CLIUtils.spec.ts 2.5 KB

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