From 8027a2d1dce94c620c16a2ab3c8296b02dcb2dc2 Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Fri, 2 Jul 2021 20:38:58 -0400 Subject: [PATCH] test that the CDN ESM build is importable (to node) --- .github/workflows/node.js.yml | 5 +++++ test/builds/cdn_build_as_esm.mjs | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 test/builds/cdn_build_as_esm.mjs diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 1c265e0808..d3c86f96e5 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -33,6 +33,11 @@ jobs: run: | npm run test-browser node test/builds/browser_build_as_commonjs.js + # CDN build should be easily importable + - if: contains(matrix.build-how, 'cdn') + name: Test: Can import CDN esm build + run: | + node test/builds/cdn_build_as_esm.mjs - if: contains(matrix.build-how, 'node') name: Test Node.js build diff --git a/test/builds/cdn_build_as_esm.mjs b/test/builds/cdn_build_as_esm.mjs new file mode 100644 index 0000000000..b217e7d5ce --- /dev/null +++ b/test/builds/cdn_build_as_esm.mjs @@ -0,0 +1,24 @@ +import hljs from "../../build/es/highlight.js"; + +const API = [ + "getLanguage", + "registerLanguage", + "highlight", + "highlightAuto", + "highlightAll", + "highlightElement" +]; + +const assert = (f,msg) => { + if (!f()) { + console.error(msg); + process.exit(1); + } +}; +const keys = Object.keys(hljs); + +API.forEach(n => { + assert(_ => keys.includes(n), `API should include ${n}`); +}); + +console.log("Pass: browser build works with Node.js just fine.")