Skip to content
Permalink
Browse files

Fix: Normalize hints when extending

  • Loading branch information
sarvaje authored and molant committed Dec 3, 2019
1 parent e61c8a6 commit 5e922dda5aacb4217130a0bcf64fc9bef93947c6
@@ -99,6 +99,8 @@ const composeConfig = (userConfig: UserConfig, parentConfig = '') => {
throw new Error(`Configuration package "${config}" is not valid`);
}

loadedConfiguration.hints = normalizeHints(loadedConfiguration.hints);

return composeConfig(loadedConfiguration, config);
});

@@ -273,6 +273,44 @@ 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 an extends property and the hints property is an array, it should combine the configurations`, 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 = {
getDescription() {
return '';
},
getName() {
return '';
},
id: 'disallowed-headers',
schema: [],
scope: HintScope.any
}
}

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

const exts = JSON.parse(await readFileAsync(path.join(__dirname, './fixtures/valid/array-hints.json')));

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

const config = loadScript(t.context);
const userConfig = config.Configuration.loadConfigFile(path.join(__dirname, './fixtures/valid/withextends.json'));
const configuration = config.Configuration.fromConfig(userConfig, { watch: false });

t.is(configuration.connector.name, 'chrome');
t.is(configuration.hints['disallowed-headers'], 'error');
t.is(configuration.hints.axe, 'default');
t.is(configuration.hints['https-only'], 'default');
});

test(`if the configuration file contains an invalid extends property, returns an exception`, async (t) => {
const { resourceLoader, sandbox } = t.context;
const exts = JSON.parse(await readFileAsync(path.join(__dirname, './fixtures/notvalid/package.json'))).hintConfig;
@@ -0,0 +1,19 @@
{
"connector": {
"name": "chrome",
"options": {
"waitFor": 1000
}
},
"formatters": [
"json"
],
"parsers": [
"typescript"
],
"hints": [
"axe",
"disallowed-headers",
"https-only"
]
}

0 comments on commit 5e922dd

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