Commit 1e3070a2ae608ad4631f1e5d49cdaf761d292c9e

Michael Schmidt 2020-03-07T18:06:01

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.

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);
 		});
 	}