{"size": 2650, "ext": "js", "max_stars_repo_path": "test-modules/project-generation.js", "max_stars_repo_name": "Haribalajiravi/creamie-cli", "max_stars_repo_stars_event_min_datetime": "2019-12-08T09:40:51.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-15T17:52:18.000Z", "max_issues_repo_path": "test-modules/project-generation.js", "max_issues_repo_name": "Haribalajiravi/creamie-cli", "max_issues_repo_issues_event_min_datetime": "2020-07-20T17:30:27.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-01T17:55:23.000Z", "max_forks_repo_path": "test-modules/project-generation.js", "max_forks_repo_name": "Haribalajiravi/creamie-cli", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": 3, "max_forks_count": null, "avg_line_length": 25.7281553398, "max_line_length": 76, "alphanum_fraction": 0.5690566038}
/* eslint-disable no-undef */
const fs = require('fs');
const Utilities = require('./Utilities');
/**
 * Project generation imports
 */
const {
  package,
  dependencies,
  devDependencies,
  getLatestVersion,
} = require('../project-generator/project/package');
const copy = require('../utils/copy');

/**
 * Project creation test cases to check all files created properly
 */
describe('Project generation', () => {
  before(() => {
    /* Create test_junks folder before all testcases */
    if (!fs.existsSync(`./${Utilities.baseTestFolder}`)) {
      fs.mkdirSync(`./${Utilities.baseTestFolder}`);
    }
  });

  /**
   * Checking wheather any errors occurs while generating project
   */
  it('Project creation with no exceptions.', async () => {
    copy(
      './project-generator/creamie-project',
      `./${Utilities.baseTestFolder}`
    );
    fs.renameSync(
      `./${Utilities.baseTestFolder}/creamie-project/`,
      `./${Utilities.baseTestFolder}/${Utilities.projectName}/`,
      (err) => {
        if (err) {
          isValid = false;
          throw err;
        }
      }
    );
    package.name = Utilities.projectName;
    package.dependencies = await getLatestVersion(dependencies);
    package.devDependencies = await getLatestVersion(devDependencies);
    fs.writeFile(
      `./${Utilities.baseTestFolder}/${Utilities.projectName}/package.json`,
      JSON.stringify(package, null, 4),
      (err) => {
        if (err) {
          throw err;
        }
      }
    );
  }).timeout(3000);

  /**
   * Checking all the files of project are properly created
   */
  it('All files and folders are created.', () => {
    [
      '.gitignore',
      'ecosystem.config.js',
      'server.js',
      'webpack.config.js',
      'package.json',
      'src',
      'src/index.html',
      'src/index.js',
      'src/app',
      'src/app/app-component.css',
      'src/app/app-component.html',
      'src/app/app-component.js',
      'src/app/app-config.js',
      'src/assets',
      'src/assets/cream.png',
      'src/styles',
      'src/styles/main.css',
    ].forEach((path) => {
      Utilities.isFileOrFolderExist(path, (isExist) => {
        if (!isExist) {
          throw `${path} is not available!`;
        }
      });
    });
  });

  /**
   * Checking if any extra files created in project generation
   */
  it('No extra file(s) or folder(s) are created.', () => {
    ['src/boot.js', 'dist', '*.logs'].forEach((path) => {
      Utilities.isFileOrFolderExist(path, (isExist) => {
        if (isExist) {
          isValid = false;
          throw `${path} should not be available!`;
        }
      });
    });
  });
});
