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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
diff --git a/tests/pattern-tests.js b/tests/pattern-tests.js
index dad15ac..a4d1ac2 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);
});
}