Added tests for CLI .json config reading

This commit is contained in:
sanex3339
2018-02-16 00:55:08 +03:00
parent ccc2325d56
commit 67af6c8016
4 changed files with 43 additions and 15 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -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
View File
@@ -0,0 +1,5 @@
{
"compact": true,
"selfDefending": false,
"sourceMap": true
}
+36 -13
View File
@@ -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
};
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;
let result: Object;
before(() => {
result = CLIUtils.getUserConfig(configFilePath);
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);
});
});
});