Skip to content

Commit

Permalink
Fix: Normalize hints when extending
Browse files Browse the repository at this point in the history
  • Loading branch information
sarvaje authored and molant committed Dec 3, 2019
1 parent e61c8a6 commit 5e922dd
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/hint/src/lib/config.ts
Expand Up @@ -99,6 +99,8 @@ const composeConfig = (userConfig: UserConfig, parentConfig = '') => {
throw new Error(`Configuration package "${config}" is not valid`); throw new Error(`Configuration package "${config}" is not valid`);
} }


loadedConfiguration.hints = normalizeHints(loadedConfiguration.hints);

return composeConfig(loadedConfiguration, config); return composeConfig(loadedConfiguration, config);
}); });


Expand Down
38 changes: 38 additions & 0 deletions packages/hint/tests/lib/config.ts
Expand Up @@ -273,6 +273,44 @@ test(`if the configuration file contains an extends property, it should combine
t.is(configuration.parsers && configuration.parsers.length, 2); 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) => { test(`if the configuration file contains an invalid extends property, returns an exception`, async (t) => {
const { resourceLoader, sandbox } = t.context; const { resourceLoader, sandbox } = t.context;
const exts = JSON.parse(await readFileAsync(path.join(__dirname, './fixtures/notvalid/package.json'))).hintConfig; const exts = JSON.parse(await readFileAsync(path.join(__dirname, './fixtures/notvalid/package.json'))).hintConfig;
Expand Down
19 changes: 19 additions & 0 deletions packages/hint/tests/lib/fixtures/valid/array-hints.json
@@ -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.