From d9254c4a60df0714c9c6533cf461c959a4ab12ad Mon Sep 17 00:00:00 2001 From: Michael Schmidt Date: Sat, 7 Mar 2020 18:06:01 +0100 Subject: [PATCH] Tests: Fixed optional dependencies in pattern tests (#2242) The pattern tests still used peer dependencies, so I updated them to use optional and modify dependencies instead. --- tests/pattern-tests.js | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/tests/pattern-tests.js b/tests/pattern-tests.js index dad15acbc1..a4d1ac2712 100644 --- a/tests/pattern-tests.js +++ b/tests/pattern-tests.js @@ -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); }); }