CLIUtils.spec.ts 2.5 KB

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