CLIUtils.spec.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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('getUserConfig (configPath: string): Object', () => {
  20. describe('variant #1: valid config file path', () => {
  21. const configDirName: string = 'test/fixtures';
  22. const configFileName: string = 'config.js';
  23. const configFilePath: string = `../../../${configDirName}/${configFileName}`;
  24. const expectedResult: TInputOptions = {
  25. compact: true,
  26. selfDefending: false,
  27. sourceMap: true
  28. };
  29. let result: Object;
  30. before(() => {
  31. result = CLIUtils.getUserConfig(configFilePath);
  32. });
  33. it('should return object with user configuration', () => {
  34. assert.deepEqual(result, expectedResult);
  35. });
  36. });
  37. describe('variant #2: invalid config file path', () => {
  38. const configDirName: string = 'test/fixtures';
  39. const configFileName: string = 'configs.js';
  40. const configFilePath: string = `../../../${configDirName}/${configFileName}`;
  41. let testFunc: () => void;
  42. before(() => {
  43. testFunc = () => CLIUtils.getUserConfig(configFilePath);
  44. });
  45. it('should throw an error if `configFilePath` is not a valid path', () => {
  46. assert.throws(testFunc, ReferenceError);
  47. });
  48. });
  49. });
  50. });