CLIUtils.spec.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. describe('variant #1: base input path', () => {
  7. let expectedOutputPath: string = 'test/input/test-obfuscated.js',
  8. inputPath: string = 'test/input/test.js';
  9. it('should output path based on `inputPath`', () => {
  10. assert.equal(CLIUtils.getOutputCodePath(inputPath), expectedOutputPath);
  11. });
  12. });
  13. describe('variant #2: relative input path with dot', () => {
  14. let expectedOutputPath: string = 'input-obfuscated.js',
  15. inputPath: string = './input.js';
  16. it('should output path based on `inputPath`', () => {
  17. assert.equal(CLIUtils.getOutputCodePath(inputPath), expectedOutputPath);
  18. });
  19. });
  20. });
  21. describe('getOutputSourceMapPath (outputCodePath: string): string', () => {
  22. let expectedOutputSourceMapPath: string = 'test/output/test.js.map',
  23. outputCodePath: string = 'test/output/test.js';
  24. it('should return output path for source map', () => {
  25. assert.equal(CLIUtils.getOutputSourceMapPath(outputCodePath), expectedOutputSourceMapPath);
  26. });
  27. });
  28. describe('getUserConfig (configPath: string): Object', () => {
  29. describe('variant #1: valid config file path', () => {
  30. const configDirName: string = 'test/fixtures';
  31. const configFileName: string = 'config.js';
  32. const configFilePath: string = `../../../${configDirName}/${configFileName}`;
  33. const expectedResult: TInputOptions = {
  34. compact: true,
  35. selfDefending: false,
  36. sourceMap: true
  37. };
  38. let result: Object;
  39. before(() => {
  40. result = CLIUtils.getUserConfig(configFilePath);
  41. });
  42. it('should return object with user configuration', () => {
  43. assert.deepEqual(result, expectedResult);
  44. });
  45. });
  46. describe('variant #2: invalid config file path', () => {
  47. const configDirName: string = 'test/fixtures';
  48. const configFileName: string = 'configs.js';
  49. const configFilePath: string = `../../../${configDirName}/${configFileName}`;
  50. let testFunc: () => void;
  51. before(() => {
  52. testFunc = () => CLIUtils.getUserConfig(configFilePath);
  53. });
  54. it('should throw an error if `configFilePath` is not a valid path', () => {
  55. assert.throws(testFunc, ReferenceError);
  56. });
  57. });
  58. });
  59. });