CLIUtils.spec.ts 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { assert } from 'chai';
  2. import { TInputOptions } from '../../../../src/types/options/TInputOptions';
  3. import { CLIUtils } from '../../../../src/cli/utils/CLIUtils';
  4. describe('CLIUtils', () => {
  5. describe('getOutputCodePath (inputPath: string): string', () => {
  6. let expectedInputPath: string = 'test/input/test-obfuscated.js',
  7. inputPath: string = 'test/input/test.js';
  8. it('should output path based on `inputPath`', () => {
  9. assert.equal(CLIUtils.getOutputCodePath(inputPath), expectedInputPath);
  10. });
  11. });
  12. describe('getOutputSourceMapPath (outputCodePath: string): string', () => {
  13. let expectedOutputSourceMapPath: string = 'test/output/test.js.map',
  14. outputCodePath: string = 'test/output/test.js';
  15. it('should return output path for source map', () => {
  16. assert.equal(CLIUtils.getOutputSourceMapPath(outputCodePath), expectedOutputSourceMapPath);
  17. });
  18. });
  19. describe('getPackageConfig (): IPackageConfig', () => {
  20. it('should return `package.json` `name` field for current CLI program as object', () => {
  21. assert.property(CLIUtils.getPackageConfig(), 'name');
  22. });
  23. it('should return `package.json` `version` field for current CLI program as object', () => {
  24. assert.property(CLIUtils.getPackageConfig(), 'version');
  25. });
  26. });
  27. describe('getUserConfig (configPath: string): Object', () => {
  28. describe('variant #1: valid config file path', () => {
  29. const configDirName: string = 'test/fixtures';
  30. const configFileName: string = 'config.js';
  31. const configFilePath: string = `../../../${configDirName}/${configFileName}`;
  32. const expectedResult: TInputOptions = {
  33. compact: true,
  34. selfDefending: false,
  35. sourceMap: true
  36. };
  37. let result: Object;
  38. before(() => {
  39. result = CLIUtils.getUserConfig(configFilePath);
  40. });
  41. it('should return object with user configuration', () => {
  42. assert.deepEqual(result, expectedResult);
  43. });
  44. });
  45. describe('variant #2: invalid config file path', () => {
  46. const configDirName: string = 'test/fixtures';
  47. const configFileName: string = 'configs.js';
  48. const configFilePath: string = `../../../${configDirName}/${configFileName}`;
  49. let testFunc: () => void;
  50. before(() => {
  51. testFunc = () => CLIUtils.getUserConfig(configFilePath);
  52. });
  53. it('should throw an error if `configFilePath` is not a valid path', () => {
  54. assert.throws(testFunc, ReferenceError);
  55. });
  56. });
  57. });
  58. });