Skip to content

Commit

Permalink
Tests: Fixed optional dependencies in pattern tests (#2242)
Browse files Browse the repository at this point in the history
The pattern tests still used peer dependencies, so I updated them to use optional and modify dependencies instead.
  • Loading branch information
RunDevelopment authored Mar 7, 2020
1 parent 462ad57 commit 1e3070a
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions tests/pattern-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,30 @@ for (const lang in languages) {
testPatterns(Prism);
});

/** @type {undefined | string | string[]} */
let peerDeps = languages[lang].peerDependencies;
peerDeps = !peerDeps ? [] : (Array.isArray(peerDeps) ? peerDeps : [peerDeps]);
function toArray(value) {
if (Array.isArray(value)) {
return value;
} else if (value != null) {
return [value];
} else {
return [];
}
}

let optional = toArray(languages[lang].optional);
let modify = toArray(languages[lang].modify);

if (optional.length > 0 || modify.length > 0) {
let name = `Patterns of '${lang}'`;
if (optional.length > 0) {
name += ` + optional dependencies '${optional.join("', '")}'`;
}
if (modify.length > 0) {
name += ` + modify dependencies '${modify.join("', '")}'`;
}

if (peerDeps.length > 0) {
describe(`Patterns of '${lang}' + peer dependencies '${peerDeps.join("', '")}'`, function () {
const Prism = PrismLoader.createInstance([...peerDeps, lang]);
describe(name, function () {
const Prism = PrismLoader.createInstance([...optional, ...modify, lang]);
testPatterns(Prism);
});
}
Expand Down

0 comments on commit 1e3070a

Please sign in to comment.