Преглед изворни кода

Added tests for CLI .json config reading

sanex3339 пре 7 година
родитељ
комит
67af6c8016
4 измењених фајлова са 44 додато и 16 уклоњено
  1. 0 0
      dist/index.js
  2. 1 1
      src/cli/utils/CLIUtils.ts
  3. 5 0
      test/fixtures/config.json
  4. 38 15
      test/unit-tests/cli/utils/CLIUtils.spec.ts

Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
dist/index.js


+ 1 - 1
src/cli/utils/CLIUtils.ts

@@ -55,7 +55,7 @@ export class CLIUtils {
             try {
                 config = __non_webpack_require__(configPath);
             } catch (e) {
-                throw new ReferenceError('Given config path must be a valid file path');
+                throw new ReferenceError('Given config path must be a valid `.js` or `.json` file path');
             }
         }
 

+ 5 - 0
test/fixtures/config.json

@@ -0,0 +1,5 @@
+{
+  "compact": true,
+  "selfDefending": false,
+  "sourceMap": true
+}

+ 38 - 15
test/unit-tests/cli/utils/CLIUtils.spec.ts

@@ -36,23 +36,46 @@ describe('CLIUtils', () => {
 
     describe('getUserConfig (configPath: string): Object', () => {
         describe('variant #1: valid config file path', () => {
-            const configDirName: string = 'test/fixtures';
-            const configFileName: string = 'config.js';
-            const configFilePath: string = `../../../${configDirName}/${configFileName}`;
-            const expectedResult: TInputOptions = {
-                compact: true,
-                selfDefending: false,
-                sourceMap: true
-            };
-
-            let result: Object;
-
-            before(() => {
-                result = CLIUtils.getUserConfig(configFilePath);
+            describe('variant #1: js file with config', () => {
+                const configDirName: string = 'test/fixtures';
+                const configFileName: string = 'config.js';
+                const configFilePath: string = `../../../${configDirName}/${configFileName}`;
+                const expectedResult: TInputOptions = {
+                    compact: true,
+                    selfDefending: false,
+                    sourceMap: true
+                };
+
+                let result: Object;
+
+                before(() => {
+                    result = CLIUtils.getUserConfig(configFilePath);
+                });
+
+                it('should return object with user configuration', () => {
+                    assert.deepEqual(result, expectedResult);
+                });
             });
 
-            it('should return object with user configuration', () => {
-                assert.deepEqual(result, expectedResult);
+            describe('variant #2: json file with config', () => {
+                const configDirName: string = 'test/fixtures';
+                const configFileName: string = 'config.json';
+                const configFilePath: string = `../../../${configDirName}/${configFileName}`;
+                const expectedResult: TInputOptions = {
+                    compact: true,
+                    selfDefending: false,
+                    sourceMap: true
+                };
+
+                let result: Object;
+
+                before(() => {
+                    result = CLIUtils.getUserConfig(configFilePath);
+                });
+
+                it('should return object with user configuration', () => {
+                    assert.deepEqual(result, expectedResult);
+                });
             });
         });
 

Неке датотеке нису приказане због велике количине промена