瀏覽代碼

`.cjs` file support for config files

sanex 3 年之前
父節點
當前提交
496a6109dc
共有 3 個文件被更改,包括 29 次插入2 次删除
  1. 0 1
      src/cli/utils/CLIUtils.ts
  2. 6 0
      test/fixtures/config.cjs
  3. 23 1
      test/unit-tests/cli/utils/CLIUtils.spec.ts

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

@@ -11,7 +11,6 @@ export class CLIUtils {
     public static readonly allowedConfigFileExtensions: string[] = [
         '.js',
         '.json',
-        '.mjs',
         '.cjs'
     ];
 

+ 6 - 0
test/fixtures/config.cjs

@@ -0,0 +1,6 @@
+module.exports = {
+	compact: true,
+    exclude: ['**/foo.js'],
+	selfDefending: false,
+	sourceMap: true
+};

+ 23 - 1
test/unit-tests/cli/utils/CLIUtils.spec.ts

@@ -31,7 +31,29 @@ describe('CLIUtils', () => {
                 });
             });
 
-            describe('Variant #2: json file with config', () => {
+            describe('Variant #2: cjs file with config', () => {
+                const configDirName: string = 'test/fixtures';
+                const configFileName: string = 'config.cjs';
+                const configFilePath: string = `../../../${configDirName}/${configFileName}`;
+                const expectedResult: TInputOptions = {
+                    compact: true,
+                    exclude: ['**/foo.js'],
+                    selfDefending: false,
+                    sourceMap: true
+                };
+
+                let result: Object;
+
+                before(() => {
+                    result = CLIUtils.getUserConfig(configFilePath);
+                });
+
+                it('should return object with user configuration', () => {
+                    assert.deepEqual(result, expectedResult);
+                });
+            });
+
+            describe('Variant #3: json file with config', () => {
                 const configDirName: string = 'test/fixtures';
                 const configFileName: string = 'config.json';
                 const configFilePath: string = `../../../${configDirName}/${configFileName}`;