DEV: ensures highlightjs is correctly tested (#9923)

DEV: ensures highlightjs is correctly tested (#9923)

diff --git a/lib/tasks/javascript.rake b/lib/tasks/javascript.rake
index 2b57ca0..280e245 100644
--- a/lib/tasks/javascript.rake
+++ b/lib/tasks/javascript.rake
@@ -177,6 +177,11 @@ task 'javascript:update' do
 
       puts "Cleanup unused styles folder"
       system("rm -rf node_modules/highlight.js/build/styles")
+
+      langs_dir = 'vendor/assets/javascripts/highlightjs/languages/*.min.js'
+      langs = Dir.glob(langs_dir).map { |lang| File.basename(lang).split('.')[0] }
+      test_bundle_dest = 'vendor/assets/javascripts/highlightjs/highlight-test-bundle.min.js'
+      File.write(test_bundle_dest, HighlightJs.bundle(langs))
     end
 
     if src.include? "ace-builds"
diff --git a/test/javascripts/components/highlighted-code-test.js b/test/javascripts/components/highlighted-code-test.js
new file mode 100644
index 0000000..38b0f2d
--- /dev/null
+++ b/test/javascripts/components/highlighted-code-test.js
@@ -0,0 +1,22 @@
+import componentTest from "helpers/component-test";
+
+moduleForComponent("highlighted-code", { integration: true });
+
+componentTest("highlighting code", {
+  template: "{{highlighted-code lang='ruby' code=code}}",
+
+  beforeEach() {
+    Discourse.HighlightJSPath =
+      "assets/highlightjs/highlight-test-bundle.min.js";
+    this.set("code", "def test; end");
+  },
+
+  async test(assert) {
+    assert.equal(
+      find("code.ruby.hljs .hljs-function .hljs-keyword")
+        .text()
+        .trim(),
+      "def"
+    );
+  }
+});
diff --git a/vendor/assets/javascripts/highlightjs/highlight-test-bundle.min.js b/vendor/assets/javascripts/highlightjs/highlight-test-bundle.min.js
new file mode 100644
index 0000000..4371efe
--- /dev/null
+++ b/vendor/assets/javascripts/highlightjs/highlight-test-bundle.min.js
@@ -0,0 +1,194 @@
+/*! highlight.js v9.18.1 | BSD3 License | git.io/hljslicense */

[... diff too long, it was truncated ...]

GitHub sha: 7635c18a

1 Like

This commit appears in #9923 which was merged by jjaffeux.