Skip to content
Permalink
Browse files

Fix: Make formatters unique when extending configurations

Fix #2077
Close #2175
  • Loading branch information...
sarvaje authored and molant committed Apr 5, 2019
1 parent 3fc140a commit 9d3551e76ff7be5677dfc95b96b54340cb219ac3
@@ -101,6 +101,10 @@ const composeConfig = (userConfig: UserConfig, parentConfig = '') => {
// The formatters defined by the user has to overwritte the one in the extends.
finalConfig.formatters = userConfig.formatters ? userConfig.formatters : finalConfig.formatters;

if (finalConfig.formatters) {
finalConfig.formatters = Array.from(new Set(finalConfig.formatters));
}

// Otherwise the output could be double or we could trigger double events
if (finalConfig.parsers) {
finalConfig.parsers = Array.from(new Set(finalConfig.parsers));
@@ -20,7 +20,7 @@ type ConfigTestContext = {
sandbox: sinon.SinonSandbox;
};

const test = anyTest as TestInterface<ConfigTestContext>;
const test = anyTest.serial as TestInterface<ConfigTestContext>;

import { HintScope } from '../../src/lib/enums/hint-scope';
import readFileAsync from '../../src/lib/utils/fs/read-file-async';
@@ -241,6 +241,38 @@ test(`if the configuration file contains an extends property, it should combine
t.is(configuration.parsers && configuration.parsers.length, 2);
});

test(`if the configuration file contains two extends property, formatters are not duplicated.`, async (t) => {
const { resourceLoader, sandbox } = t.context;

class FakeDisallowedHint implements IHint {
public static called: boolean = false;
public constructor() {
FakeDisallowedHint.called = true;
}

public static readonly meta: HintMetadata = {
id: 'disallowed-headers',
schema: [],
scope: HintScope.any
}
}

sandbox.stub(resourceLoader, 'loadHint').returns(FakeDisallowedHint);

// Returns the same config for all the extends.
const exts = JSON.parse(await readFileAsync(path.join(__dirname, './fixtures/valid/package.json'))).hintConfig;

sandbox.stub(resourceLoader, 'loadConfiguration').returns(exts);

const config = loadScript(t.context);
const configuration: UserConfig = config.Configuration.fromFilePath(path.join(__dirname, './fixtures/valid/withtwoextends.json'), { watch: false } as CLIOptions);

t.is((configuration.connector as ConnectorConfig).name, 'chrome');
t.is((configuration.hints as HintsConfigObject)['disallowed-headers'], 'error');
t.is(configuration.formatters && configuration.formatters.length, 1);
t.is(configuration.parsers && configuration.parsers.length, 2);
});


test(`if the configuration file contains an invalid extends property, returns an exception`, async (t) => {
const { resourceLoader, sandbox } = t.context;
@@ -0,0 +1,17 @@
{
"extends": [
"basics", "basics2"
],
"connector": {
"name": "chrome",
"options": {
"waitFor": 1000
}
},
"parsers": [
"typescript"
],
"hints": {
"disallowed-headers": "error"
}
}

0 comments on commit 9d3551e

Please sign in to comment.
You can’t perform that action at this time.