@vizhub/runtime 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +280 -128
- package/dist/buildHTML.d.ts +14 -0
- package/dist/buildHTML.js +67 -0
- package/dist/cjs/buildHTML.js +71 -0
- package/dist/cjs/common/packageJson.js +81 -0
- package/dist/cjs/common/packageJson.test.js +148 -0
- package/dist/cjs/common/sucrasePlugin.js +27 -0
- package/dist/cjs/common/virtualFileSystem.js +79 -0
- package/dist/cjs/determineRuntimeVersion.js +26 -0
- package/dist/cjs/determineRuntimeVersion.test.js +103 -0
- package/dist/cjs/index.js +9 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/test/fixtures/v1/basicHTML.js +18 -0
- package/dist/cjs/test/fixtures/v1/fetchProxy.js +15 -0
- package/dist/cjs/test/fixtures/v1/index.js +15 -0
- package/dist/cjs/test/fixtures/v1/jsScriptTag.js +12 -0
- package/dist/cjs/test/fixtures/v1/protocolTest.js +18 -0
- package/dist/cjs/test/fixtures/v1/styleTest.js +18 -0
- package/dist/cjs/test/fixtures/v1/xmlTest.js +22 -0
- package/dist/cjs/test/fixtures/v2/basicBundle.js +8 -0
- package/dist/cjs/test/fixtures/v2/basicBundleNoExtension.js +8 -0
- package/dist/cjs/test/fixtures/v2/d3Import.js +10 -0
- package/dist/cjs/test/fixtures/v2/d3ImportPkg.js +22 -0
- package/dist/cjs/test/fixtures/v2/d3RosettaImportPkg.js +22 -0
- package/dist/cjs/test/fixtures/v2/es6Preserve.js +9 -0
- package/dist/cjs/test/fixtures/v2/generatorSupport.js +9 -0
- package/dist/cjs/test/fixtures/v2/index.js +45 -0
- package/dist/cjs/test/fixtures/v2/jsxTranspile.js +9 -0
- package/dist/cjs/test/fixtures/v2/reactDomImport.js +11 -0
- package/dist/cjs/test/fixtures/v2/reactDomImportPkg.js +27 -0
- package/dist/cjs/test/fixtures/v2/reactImport.js +10 -0
- package/dist/cjs/test/fixtures/v2/reactImportPkg.js +20 -0
- package/dist/cjs/test/fixtures/v2/sourceMapErrorFixture.js +22 -0
- package/dist/cjs/test/fixtures/v2/unicodeSupport.js +9 -0
- package/dist/cjs/test/fixtures/v3/basicIndexJS.js +10 -0
- package/dist/cjs/test/fixtures/v3/cssImport.js +12 -0
- package/dist/cjs/test/fixtures/v3/csvImport.js +14 -0
- package/dist/cjs/test/fixtures/v3/csvStrangeChars.js +15 -0
- package/dist/cjs/test/fixtures/v3/index.js +25 -0
- package/dist/cjs/test/fixtures/v3/jsExport.js +13 -0
- package/dist/cjs/test/fixtures/v3/sourcemap.js +13 -0
- package/dist/cjs/test/fixtures/v3/svelte.js +21 -0
- package/dist/cjs/test/fixtures/v3/vizContent.js +14 -0
- package/dist/cjs/test/fixtures/v3/vizImport.js +88 -0
- package/dist/cjs/test/fixtures/v4/d3Usage.js +34 -0
- package/dist/cjs/test/fixtures/v4/esmBuild.js +21 -0
- package/dist/cjs/test/fixtures/v4/fetchInterception.js +21 -0
- package/dist/cjs/test/fixtures/v4/index.js +21 -0
- package/dist/cjs/test/fixtures/v4/jsScriptTagTypeModule.js +21 -0
- package/dist/cjs/test/fixtures/v4/jsScriptTagTypeModules.js +15 -0
- package/dist/cjs/test/fixtures/v4/reactHooks.js +50 -0
- package/dist/cjs/test/fixtures/v4/reactJsx.js +37 -0
- package/dist/cjs/test/fixtures/v4/threeJsUsage.js +27 -0
- package/dist/cjs/test/fixtures/v4/typeScriptSupport.js +32 -0
- package/dist/cjs/test/testInBrowser.js +50 -0
- package/dist/cjs/test/testStackTrace.js +58 -0
- package/dist/cjs/test/v1.test.js +70 -0
- package/dist/cjs/test/v2.test.js +124 -0
- package/dist/cjs/test/v3.test.js +119 -0
- package/dist/cjs/test/v4.test.js +105 -0
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/utils/vizContentToFileCollection.js +23 -0
- package/dist/cjs/utils/vizContentToFileCollection.test.js +77 -0
- package/dist/cjs/v2/computeBundleJSV2.js +33 -0
- package/dist/cjs/v2/getComputedIndexHtml.js +86 -0
- package/dist/cjs/v2/getComputedIndexHtml.test.js +136 -0
- package/dist/cjs/v2/index.js +5 -0
- package/dist/cjs/v2/v2Build.js +15 -0
- package/dist/cjs/v3/cleanRollupErrorMessage.js +13 -0
- package/dist/cjs/v3/computeBundleJSV3.js +52 -0
- package/dist/cjs/v3/createVizContent.js +27 -0
- package/dist/cjs/v3/extractVizImport.js +27 -0
- package/dist/cjs/v3/extractVizImport.test.js +32 -0
- package/dist/cjs/v3/htmlTemplate.js +93 -0
- package/dist/cjs/v3/index.js +5 -0
- package/dist/cjs/v3/parseId.js +9 -0
- package/dist/cjs/v3/parseId.test.js +27 -0
- package/dist/cjs/v3/setupV3Runtime.js +345 -0
- package/dist/cjs/v3/slugCache.js +39 -0
- package/dist/cjs/v3/slugCache.test.js +107 -0
- package/dist/cjs/v3/transformDSV/dsvParseSrc.js +124 -0
- package/dist/cjs/v3/transformDSV/index.js +44 -0
- package/dist/cjs/v3/transformSvelte.js +81 -0
- package/dist/cjs/v3/types.js +2 -0
- package/dist/cjs/v3/v3Build.js +34 -0
- package/dist/cjs/v3/vizCache.js +40 -0
- package/dist/cjs/v3/vizCache.test.js +100 -0
- package/dist/cjs/v3/vizLoad.js +50 -0
- package/dist/cjs/v3/vizResolve.js +73 -0
- package/dist/cjs/v4/index.js +138 -0
- package/dist/common/packageJson.d.ts +1 -1
- package/dist/common/virtualFileSystem.d.ts +1 -1
- package/dist/determineRuntimeVersion.d.ts +2 -1
- package/dist/esm/buildHTML.js +67 -0
- package/dist/esm/common/packageJson.js +71 -0
- package/dist/esm/common/packageJson.test.js +146 -0
- package/dist/esm/common/sucrasePlugin.js +24 -0
- package/dist/esm/common/virtualFileSystem.js +75 -0
- package/dist/esm/determineRuntimeVersion.js +22 -0
- package/dist/esm/determineRuntimeVersion.test.js +101 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/test/fixtures/v1/basicHTML.js +15 -0
- package/dist/esm/test/fixtures/v1/fetchProxy.js +12 -0
- package/dist/esm/test/fixtures/v1/index.js +6 -0
- package/dist/esm/test/fixtures/v1/jsScriptTag.js +9 -0
- package/dist/esm/test/fixtures/v1/protocolTest.js +15 -0
- package/dist/esm/test/fixtures/v1/styleTest.js +15 -0
- package/dist/esm/test/fixtures/v1/xmlTest.js +19 -0
- package/dist/esm/test/fixtures/v2/basicBundle.js +5 -0
- package/dist/esm/test/fixtures/v2/basicBundleNoExtension.js +5 -0
- package/dist/esm/test/fixtures/v2/d3Import.js +7 -0
- package/dist/esm/test/fixtures/v2/d3ImportPkg.js +19 -0
- package/dist/esm/test/fixtures/v2/d3RosettaImportPkg.js +19 -0
- package/dist/esm/test/fixtures/v2/es6Preserve.js +6 -0
- package/dist/esm/test/fixtures/v2/generatorSupport.js +6 -0
- package/dist/esm/test/fixtures/v2/index.js +15 -0
- package/dist/esm/test/fixtures/v2/jsxTranspile.js +6 -0
- package/dist/esm/test/fixtures/v2/reactDomImport.js +8 -0
- package/dist/esm/test/fixtures/v2/reactDomImportPkg.js +24 -0
- package/dist/esm/test/fixtures/v2/reactImport.js +7 -0
- package/dist/esm/test/fixtures/v2/reactImportPkg.js +17 -0
- package/dist/esm/test/fixtures/v2/sourceMapErrorFixture.js +19 -0
- package/dist/esm/test/fixtures/v2/unicodeSupport.js +6 -0
- package/dist/esm/test/fixtures/v3/basicIndexJS.js +7 -0
- package/dist/esm/test/fixtures/v3/cssImport.js +9 -0
- package/dist/esm/test/fixtures/v3/csvImport.js +11 -0
- package/dist/esm/test/fixtures/v3/csvStrangeChars.js +12 -0
- package/dist/esm/test/fixtures/v3/index.js +9 -0
- package/dist/esm/test/fixtures/v3/jsExport.js +10 -0
- package/dist/esm/test/fixtures/v3/sourcemap.js +10 -0
- package/dist/esm/test/fixtures/v3/svelte.js +18 -0
- package/dist/esm/test/fixtures/v3/vizContent.js +11 -0
- package/dist/esm/test/fixtures/v3/vizImport.js +85 -0
- package/dist/esm/test/fixtures/v4/d3Usage.js +31 -0
- package/dist/esm/test/fixtures/v4/esmBuild.js +18 -0
- package/dist/esm/test/fixtures/v4/fetchInterception.js +18 -0
- package/dist/esm/test/fixtures/v4/index.js +9 -0
- package/dist/esm/test/fixtures/v4/jsScriptTagTypeModule.js +18 -0
- package/dist/esm/test/fixtures/v4/jsScriptTagTypeModules.js +12 -0
- package/dist/esm/test/fixtures/v4/reactHooks.js +47 -0
- package/dist/esm/test/fixtures/v4/reactJsx.js +34 -0
- package/dist/esm/test/fixtures/v4/threeJsUsage.js +24 -0
- package/dist/esm/test/fixtures/v4/typeScriptSupport.js +29 -0
- package/dist/esm/test/testInBrowser.js +47 -0
- package/dist/esm/test/testStackTrace.js +55 -0
- package/dist/esm/test/v1.test.js +65 -0
- package/dist/esm/test/v2.test.js +121 -0
- package/dist/esm/test/v3.test.js +114 -0
- package/dist/esm/test/v4.test.js +100 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/utils/vizContentToFileCollection.js +19 -0
- package/dist/esm/utils/vizContentToFileCollection.test.js +75 -0
- package/dist/esm/v2/computeBundleJSV2.js +29 -0
- package/dist/esm/v2/getComputedIndexHtml.js +81 -0
- package/dist/esm/v2/getComputedIndexHtml.test.js +134 -0
- package/dist/esm/v2/index.js +1 -0
- package/dist/esm/v2/v2Build.js +11 -0
- package/dist/esm/v3/cleanRollupErrorMessage.js +9 -0
- package/dist/esm/v3/computeBundleJSV3.js +48 -0
- package/dist/esm/v3/createVizContent.js +23 -0
- package/dist/esm/v3/extractVizImport.js +23 -0
- package/dist/esm/v3/extractVizImport.test.js +30 -0
- package/dist/esm/v3/htmlTemplate.js +89 -0
- package/dist/esm/v3/index.js +1 -0
- package/dist/esm/v3/parseId.js +5 -0
- package/dist/esm/v3/parseId.test.js +25 -0
- package/dist/esm/v3/setupV3Runtime.js +341 -0
- package/dist/esm/v3/slugCache.js +35 -0
- package/dist/esm/v3/slugCache.test.js +105 -0
- package/dist/esm/v3/transformDSV/dsvParseSrc.js +121 -0
- package/dist/esm/v3/transformDSV/index.js +40 -0
- package/dist/esm/v3/transformSvelte.js +77 -0
- package/dist/esm/v3/types.js +1 -0
- package/dist/esm/v3/v3Build.js +30 -0
- package/dist/esm/v3/vizCache.js +36 -0
- package/dist/esm/v3/vizCache.test.js +98 -0
- package/dist/esm/v3/vizLoad.js +46 -0
- package/dist/esm/v3/vizResolve.js +69 -0
- package/dist/esm/v4/index.js +134 -0
- package/dist/index.d.ts +3 -14
- package/dist/index.js +3 -67
- package/dist/test/testInBrowser.d.ts +1 -2
- package/dist/test/testStackTrace.d.ts +1 -1
- package/dist/types/buildHTML.d.ts +14 -0
- package/dist/types/common/packageJson.d.ts +39 -0
- package/dist/types/common/packageJson.test.d.ts +1 -0
- package/dist/types/common/sucrasePlugin.d.ts +2 -0
- package/dist/types/common/virtualFileSystem.d.ts +3 -0
- package/dist/types/determineRuntimeVersion.d.ts +3 -0
- package/dist/types/determineRuntimeVersion.test.d.ts +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/test/fixtures/v1/basicHTML.d.ts +3 -0
- package/dist/types/test/fixtures/v1/fetchProxy.d.ts +5 -0
- package/dist/types/test/fixtures/v1/index.d.ts +6 -0
- package/dist/types/test/fixtures/v1/jsScriptTag.d.ts +4 -0
- package/dist/types/test/fixtures/v1/protocolTest.d.ts +3 -0
- package/dist/types/test/fixtures/v1/styleTest.d.ts +4 -0
- package/dist/types/test/fixtures/v1/xmlTest.d.ts +4 -0
- package/dist/types/test/fixtures/v2/basicBundle.d.ts +5 -0
- package/dist/types/test/fixtures/v2/basicBundleNoExtension.d.ts +5 -0
- package/dist/types/test/fixtures/v2/d3Import.d.ts +4 -0
- package/dist/types/test/fixtures/v2/d3ImportPkg.d.ts +5 -0
- package/dist/types/test/fixtures/v2/d3RosettaImportPkg.d.ts +5 -0
- package/dist/types/test/fixtures/v2/es6Preserve.d.ts +4 -0
- package/dist/types/test/fixtures/v2/generatorSupport.d.ts +4 -0
- package/dist/types/test/fixtures/v2/index.d.ts +14 -0
- package/dist/types/test/fixtures/v2/jsxTranspile.d.ts +4 -0
- package/dist/types/test/fixtures/v2/reactDomImport.d.ts +4 -0
- package/dist/types/test/fixtures/v2/reactDomImportPkg.d.ts +5 -0
- package/dist/types/test/fixtures/v2/reactImport.d.ts +4 -0
- package/dist/types/test/fixtures/v2/reactImportPkg.d.ts +5 -0
- package/dist/types/test/fixtures/v2/sourceMapErrorFixture.d.ts +5 -0
- package/dist/types/test/fixtures/v2/unicodeSupport.d.ts +4 -0
- package/dist/types/test/fixtures/v3/basicIndexJS.d.ts +3 -0
- package/dist/types/test/fixtures/v3/cssImport.d.ts +4 -0
- package/dist/types/test/fixtures/v3/csvImport.d.ts +4 -0
- package/dist/types/test/fixtures/v3/csvStrangeChars.d.ts +4 -0
- package/dist/types/test/fixtures/v3/index.d.ts +9 -0
- package/dist/types/test/fixtures/v3/jsExport.d.ts +4 -0
- package/dist/types/test/fixtures/v3/sourcemap.d.ts +3 -0
- package/dist/types/test/fixtures/v3/svelte.d.ts +4 -0
- package/dist/types/test/fixtures/v3/vizContent.d.ts +2 -0
- package/dist/types/test/fixtures/v3/vizImport.d.ts +6 -0
- package/dist/types/test/fixtures/v4/d3Usage.d.ts +5 -0
- package/dist/types/test/fixtures/v4/esmBuild.d.ts +5 -0
- package/dist/types/test/fixtures/v4/fetchInterception.d.ts +5 -0
- package/dist/types/test/fixtures/v4/index.d.ts +9 -0
- package/dist/types/test/fixtures/v4/jsScriptTagTypeModule.d.ts +4 -0
- package/dist/types/test/fixtures/v4/jsScriptTagTypeModules.d.ts +5 -0
- package/dist/types/test/fixtures/v4/reactHooks.d.ts +6 -0
- package/dist/types/test/fixtures/v4/reactJsx.d.ts +6 -0
- package/dist/types/test/fixtures/v4/threeJsUsage.d.ts +4 -0
- package/dist/types/test/fixtures/v4/typeScriptSupport.d.ts +5 -0
- package/dist/types/test/testInBrowser.d.ts +15 -0
- package/dist/types/test/testStackTrace.d.ts +9 -0
- package/dist/types/test/v1.test.d.ts +1 -0
- package/dist/types/test/v2.test.d.ts +1 -0
- package/dist/types/test/v3.test.d.ts +1 -0
- package/dist/types/test/v4.test.d.ts +1 -0
- package/dist/types/types.d.ts +1 -0
- package/dist/types/utils/vizContentToFileCollection.d.ts +7 -0
- package/dist/types/utils/vizContentToFileCollection.test.d.ts +1 -0
- package/dist/types/v2/computeBundleJSV2.d.ts +7 -0
- package/dist/types/v2/getComputedIndexHtml.d.ts +4 -0
- package/dist/types/v2/getComputedIndexHtml.test.d.ts +1 -0
- package/dist/types/v2/index.d.ts +1 -0
- package/dist/types/v2/v2Build.d.ts +7 -0
- package/dist/types/v3/cleanRollupErrorMessage.d.ts +4 -0
- package/dist/types/v3/computeBundleJSV3.d.ts +17 -0
- package/dist/types/v3/createVizContent.d.ts +8 -0
- package/dist/types/v3/extractVizImport.d.ts +6 -0
- package/dist/types/v3/extractVizImport.test.d.ts +1 -0
- package/dist/types/v3/htmlTemplate.d.ts +5 -0
- package/dist/types/v3/index.d.ts +1 -0
- package/dist/types/v3/parseId.d.ts +6 -0
- package/dist/types/v3/parseId.test.d.ts +1 -0
- package/dist/types/v3/setupV3Runtime.d.ts +15 -0
- package/dist/types/v3/slugCache.d.ts +11 -0
- package/dist/types/v3/slugCache.test.d.ts +1 -0
- package/dist/types/v3/transformDSV/dsvParseSrc.d.ts +1 -0
- package/dist/types/v3/transformDSV/index.d.ts +2 -0
- package/dist/types/v3/transformSvelte.d.ts +8 -0
- package/dist/types/v3/types.d.ts +65 -0
- package/dist/types/v3/v3Build.d.ts +14 -0
- package/dist/types/v3/vizCache.d.ts +10 -0
- package/dist/types/v3/vizCache.test.d.ts +1 -0
- package/dist/types/v3/vizLoad.d.ts +7 -0
- package/dist/types/v3/vizResolve.d.ts +7 -0
- package/dist/types/v4/index.d.ts +10 -0
- package/dist/types.d.ts +0 -1
- package/dist/utils/vizContentToFileCollection.d.ts +1 -2
- package/dist/v2/computeBundleJSV2.d.ts +1 -1
- package/dist/v2/getComputedIndexHtml.d.ts +1 -1
- package/dist/v2/v2Build.d.ts +1 -1
- package/dist/v3/cleanRollupErrorMessage.d.ts +4 -0
- package/dist/v3/cleanRollupErrorMessage.js +9 -0
- package/dist/v3/computeBundleJSV3.d.ts +1 -2
- package/dist/v3/createVizContent.d.ts +1 -2
- package/dist/v3/setupV3Runtime.d.ts +15 -0
- package/dist/v3/setupV3Runtime.js +341 -0
- package/dist/v3/v3Build.d.ts +1 -2
- package/dist/v3/v3Build.js +1 -1
- package/dist/v3/vizLoad.js +1 -1
- package/dist/v4/index.d.ts +1 -1
- package/package.json +25 -16
@@ -0,0 +1,65 @@
|
|
1
|
+
import puppeteer from "puppeteer";
|
2
|
+
import { describe, it, expect, beforeAll, afterAll, } from "vitest";
|
3
|
+
import { buildHTML } from "../index";
|
4
|
+
import { testInBrowser } from "./testInBrowser";
|
5
|
+
import { basicHTML, fetchProxy, jsScriptTag, styleTest, xmlTest, protocolTest, } from "./fixtures/v1";
|
6
|
+
import { setJSDOM } from "../v2/getComputedIndexHtml";
|
7
|
+
import { JSDOM } from "jsdom";
|
8
|
+
setJSDOM(JSDOM);
|
9
|
+
let browser;
|
10
|
+
beforeAll(async () => {
|
11
|
+
browser = await puppeteer.launch();
|
12
|
+
});
|
13
|
+
afterAll(async () => {
|
14
|
+
await browser.close();
|
15
|
+
});
|
16
|
+
describe("VizHub Runtime v1", () => {
|
17
|
+
it("should generate srcdoc HTML", async () => {
|
18
|
+
const srcdoc = await buildHTML({
|
19
|
+
files: basicHTML,
|
20
|
+
});
|
21
|
+
expect(srcdoc).toContain("<!DOCTYPE html>");
|
22
|
+
expect(srcdoc).toContain("<title>My HTML Document</title>");
|
23
|
+
expect(srcdoc).toContain("Hello, World!");
|
24
|
+
});
|
25
|
+
it("basicHTML", async () => {
|
26
|
+
await testInBrowser({
|
27
|
+
browser,
|
28
|
+
files: basicHTML,
|
29
|
+
expectedLog: "Hello, World!",
|
30
|
+
});
|
31
|
+
});
|
32
|
+
it("jsScriptTag", async () => {
|
33
|
+
await testInBrowser({
|
34
|
+
browser,
|
35
|
+
files: jsScriptTag,
|
36
|
+
expectedLog: "Hello, JS!",
|
37
|
+
});
|
38
|
+
});
|
39
|
+
it("fetchProxy", async () => {
|
40
|
+
await testInBrowser({
|
41
|
+
browser,
|
42
|
+
files: fetchProxy,
|
43
|
+
expectedLog: "Hello, Fetch!",
|
44
|
+
});
|
45
|
+
});
|
46
|
+
it("should handle CSS file loading", async () => {
|
47
|
+
await testInBrowser({
|
48
|
+
browser,
|
49
|
+
files: styleTest,
|
50
|
+
expectedLog: "rgb(255, 0, 0)",
|
51
|
+
});
|
52
|
+
});
|
53
|
+
it("should handle XML file loading", async () => {
|
54
|
+
await testInBrowser({
|
55
|
+
browser,
|
56
|
+
files: xmlTest,
|
57
|
+
expectedLog: "root",
|
58
|
+
});
|
59
|
+
});
|
60
|
+
it("should convert protocol-less URLs to https", async () => {
|
61
|
+
const srcdoc = await buildHTML({ files: protocolTest });
|
62
|
+
expect(srcdoc).toContain('href="https://fonts.googleapis.com');
|
63
|
+
expect(srcdoc).toContain('src="https://code.jquery.com');
|
64
|
+
});
|
65
|
+
});
|
@@ -0,0 +1,121 @@
|
|
1
|
+
import puppeteer from "puppeteer";
|
2
|
+
import { rollup } from "rollup";
|
3
|
+
import { describe, it, expect, beforeAll, afterAll, } from "vitest";
|
4
|
+
import { buildHTML } from "../index";
|
5
|
+
import { testInBrowser } from "./testInBrowser";
|
6
|
+
import { basicBundle, d3Import, d3ImportPkg, reactImport, reactImportPkg, reactDomImport, reactDomImportPkg, jsxTranspile, es6Preserve, generatorSupport, unicodeSupport, d3RosettaImportPkg, basicBundleNoExtension,
|
7
|
+
// sourceMapErrorFixture,
|
8
|
+
} from "./fixtures/v2";
|
9
|
+
import { setJSDOM } from "../v2/getComputedIndexHtml";
|
10
|
+
import { JSDOM } from "jsdom";
|
11
|
+
setJSDOM(JSDOM);
|
12
|
+
let browser;
|
13
|
+
beforeAll(async () => {
|
14
|
+
browser = await puppeteer.launch();
|
15
|
+
});
|
16
|
+
afterAll(async () => {
|
17
|
+
await browser.close();
|
18
|
+
});
|
19
|
+
describe("VizHub Runtime v2", () => {
|
20
|
+
it("should bundle basic imports", async () => {
|
21
|
+
await testInBrowser({
|
22
|
+
browser,
|
23
|
+
files: basicBundle,
|
24
|
+
expectedLog: "bar",
|
25
|
+
});
|
26
|
+
});
|
27
|
+
it("should bundle basic imports missing .js extension", async () => {
|
28
|
+
await testInBrowser({
|
29
|
+
browser,
|
30
|
+
files: basicBundleNoExtension,
|
31
|
+
expectedLog: "bar",
|
32
|
+
});
|
33
|
+
});
|
34
|
+
it("should support d3 imports", async () => {
|
35
|
+
await testInBrowser({
|
36
|
+
browser,
|
37
|
+
files: d3Import,
|
38
|
+
expectedLog: "function",
|
39
|
+
});
|
40
|
+
});
|
41
|
+
it("should support d3 imports from packages", async () => {
|
42
|
+
await testInBrowser({
|
43
|
+
browser,
|
44
|
+
files: d3ImportPkg,
|
45
|
+
expectedLog: "function",
|
46
|
+
});
|
47
|
+
});
|
48
|
+
it("should support React imports", async () => {
|
49
|
+
await testInBrowser({
|
50
|
+
browser,
|
51
|
+
files: reactImport,
|
52
|
+
expectedLog: "object",
|
53
|
+
});
|
54
|
+
});
|
55
|
+
it("should support React imports from packages", async () => {
|
56
|
+
await testInBrowser({
|
57
|
+
browser,
|
58
|
+
files: reactImportPkg,
|
59
|
+
expectedLog: "object",
|
60
|
+
});
|
61
|
+
});
|
62
|
+
it("should support ReactDOM imports", async () => {
|
63
|
+
await testInBrowser({
|
64
|
+
browser,
|
65
|
+
files: reactDomImport,
|
66
|
+
expectedLog: "object",
|
67
|
+
});
|
68
|
+
});
|
69
|
+
it("should support ReactDOM imports from packages", async () => {
|
70
|
+
await testInBrowser({
|
71
|
+
browser,
|
72
|
+
files: reactDomImportPkg,
|
73
|
+
expectedLog: "object",
|
74
|
+
});
|
75
|
+
});
|
76
|
+
it("should transpile JSX", async () => {
|
77
|
+
const srcdoc = await buildHTML({
|
78
|
+
files: jsxTranspile,
|
79
|
+
rollup,
|
80
|
+
});
|
81
|
+
expect(srcdoc).toContain("React.createElement");
|
82
|
+
});
|
83
|
+
it("should preserve ES6 syntax", async () => {
|
84
|
+
await testInBrowser({
|
85
|
+
browser,
|
86
|
+
files: es6Preserve,
|
87
|
+
expectedLog: "16", // 4 * 4 = 16
|
88
|
+
});
|
89
|
+
});
|
90
|
+
it("should support generator functions", async () => {
|
91
|
+
await testInBrowser({
|
92
|
+
browser,
|
93
|
+
files: generatorSupport,
|
94
|
+
expectedLog: "5",
|
95
|
+
});
|
96
|
+
});
|
97
|
+
it("should support unicode characters", async () => {
|
98
|
+
await testInBrowser({
|
99
|
+
browser,
|
100
|
+
files: unicodeSupport,
|
101
|
+
expectedLog: "Привет",
|
102
|
+
});
|
103
|
+
});
|
104
|
+
it("should handle globals config for arbitrary package d3-rosetta", async () => {
|
105
|
+
await testInBrowser({
|
106
|
+
browser,
|
107
|
+
files: d3RosettaImportPkg,
|
108
|
+
expectedLog: "function",
|
109
|
+
});
|
110
|
+
});
|
111
|
+
// it("should handle CSS imports", async () => {
|
112
|
+
// TODO: Add test for CSS imports
|
113
|
+
// });
|
114
|
+
// TODO get this working
|
115
|
+
// it("should provide sourcemaps with correct line numbers in stack traces", async () => {
|
116
|
+
// await testStackTrace(browser, sourceMapErrorFixture, {
|
117
|
+
// sourceFile: "error.js", // Note: The actual filename may not appear in stack traces
|
118
|
+
// sourceLine: 3,
|
119
|
+
// });
|
120
|
+
// });
|
121
|
+
});
|
@@ -0,0 +1,114 @@
|
|
1
|
+
import puppeteer from "puppeteer";
|
2
|
+
import { describe, it, beforeAll, afterAll } from "vitest";
|
3
|
+
import { compile } from "svelte/compiler";
|
4
|
+
import { testInBrowser } from "./testInBrowser";
|
5
|
+
import { basicIndexJS, jsExport, cssImport, csvImport, csvStrangeChars, svelte, sampleContent, sampleContentVizImport, sampleContentVizImportSlug, sampleContentWithCSS, sampleContentVizImportWithCSS, sourcemap, } from "./fixtures/v3";
|
6
|
+
import { setJSDOM } from "../v2/getComputedIndexHtml";
|
7
|
+
import { JSDOM } from "jsdom";
|
8
|
+
import { createVizCache } from "../v3/vizCache";
|
9
|
+
import { createSlugCache } from "../v3/slugCache";
|
10
|
+
import { testStackTrace } from "./testStackTrace";
|
11
|
+
setJSDOM(JSDOM);
|
12
|
+
let browser;
|
13
|
+
beforeAll(async () => {
|
14
|
+
browser = await puppeteer.launch();
|
15
|
+
});
|
16
|
+
afterAll(async () => {
|
17
|
+
await browser.close();
|
18
|
+
});
|
19
|
+
describe("VizHub Runtime v3", () => {
|
20
|
+
it("should run main without index.html", async () => {
|
21
|
+
await testInBrowser({
|
22
|
+
browser,
|
23
|
+
files: basicIndexJS,
|
24
|
+
expectedLog: "Hello main!",
|
25
|
+
});
|
26
|
+
});
|
27
|
+
it("should handle JS exports", async () => {
|
28
|
+
await testInBrowser({
|
29
|
+
browser,
|
30
|
+
files: jsExport,
|
31
|
+
expectedLog: "Outer Inner",
|
32
|
+
});
|
33
|
+
});
|
34
|
+
it("should handle CSS imports", async () => {
|
35
|
+
await testInBrowser({
|
36
|
+
browser,
|
37
|
+
files: cssImport,
|
38
|
+
expectedLog: "rgb(255, 0, 0)",
|
39
|
+
});
|
40
|
+
});
|
41
|
+
it("should handle CSV imports", async () => {
|
42
|
+
await testInBrowser({
|
43
|
+
browser,
|
44
|
+
files: csvImport,
|
45
|
+
expectedLog: "Setosa",
|
46
|
+
});
|
47
|
+
});
|
48
|
+
it("should handle CSV with strange characters", async () => {
|
49
|
+
await testInBrowser({
|
50
|
+
browser,
|
51
|
+
files: csvStrangeChars,
|
52
|
+
expectedLog: "Türkiye",
|
53
|
+
});
|
54
|
+
});
|
55
|
+
it("should handle viz imports", async () => {
|
56
|
+
await testInBrowser({
|
57
|
+
browser,
|
58
|
+
expectedLog: "Imported from viz: Outer Inner",
|
59
|
+
vizCache: createVizCache({
|
60
|
+
initialContents: [
|
61
|
+
sampleContent,
|
62
|
+
sampleContentVizImport,
|
63
|
+
],
|
64
|
+
}),
|
65
|
+
vizId: sampleContentVizImport.id,
|
66
|
+
});
|
67
|
+
});
|
68
|
+
it("should handle viz imports with slug", async () => {
|
69
|
+
await testInBrowser({
|
70
|
+
browser,
|
71
|
+
expectedLog: "Imported from viz with slug: Outer Inner",
|
72
|
+
vizCache: createVizCache({
|
73
|
+
initialContents: [
|
74
|
+
sampleContent,
|
75
|
+
sampleContentVizImportSlug,
|
76
|
+
],
|
77
|
+
}),
|
78
|
+
vizId: sampleContentVizImportSlug.id,
|
79
|
+
slugCache: createSlugCache({
|
80
|
+
initialMappings: {
|
81
|
+
"joe/sample-content-slug": sampleContent.id,
|
82
|
+
},
|
83
|
+
}),
|
84
|
+
});
|
85
|
+
});
|
86
|
+
it("should handle viz imports with CSS", async () => {
|
87
|
+
await testInBrowser({
|
88
|
+
browser,
|
89
|
+
expectedLog: "rgb(255, 0, 0)",
|
90
|
+
vizCache: createVizCache({
|
91
|
+
initialContents: [
|
92
|
+
sampleContentWithCSS,
|
93
|
+
sampleContentVizImportWithCSS,
|
94
|
+
],
|
95
|
+
}),
|
96
|
+
vizId: sampleContentVizImportWithCSS.id,
|
97
|
+
});
|
98
|
+
});
|
99
|
+
it("should handle Svelte components", async () => {
|
100
|
+
await testInBrowser({
|
101
|
+
browser,
|
102
|
+
files: svelte,
|
103
|
+
expectedLog: "Svelte",
|
104
|
+
getSvelteCompiler: async () => compile,
|
105
|
+
});
|
106
|
+
});
|
107
|
+
it("should provide sourcemaps with correct line numbers in stack traces", async () => {
|
108
|
+
await testStackTrace({
|
109
|
+
browser,
|
110
|
+
files: sourcemap,
|
111
|
+
expectedLineNumber: 6,
|
112
|
+
});
|
113
|
+
});
|
114
|
+
});
|
@@ -0,0 +1,100 @@
|
|
1
|
+
import puppeteer from "puppeteer";
|
2
|
+
import { describe, it, beforeAll, afterAll } from "vitest";
|
3
|
+
import { testInBrowser } from "./testInBrowser";
|
4
|
+
import { jsScriptTagTypeModule, jsScriptTagTypeModules, fetchInterception, esmBuild, reactJsx, d3Usage, threeJsUsage, reactHooks, typeScriptSupport, } from "./fixtures/v4";
|
5
|
+
let browser;
|
6
|
+
beforeAll(async () => {
|
7
|
+
browser = await puppeteer.launch();
|
8
|
+
});
|
9
|
+
afterAll(async () => {
|
10
|
+
await browser.close();
|
11
|
+
});
|
12
|
+
describe("VizHub Runtime v4", () => {
|
13
|
+
it("should handle script type=module with import maps", async () => {
|
14
|
+
await testInBrowser({
|
15
|
+
browser,
|
16
|
+
files: jsScriptTagTypeModule,
|
17
|
+
expectedLog: "Hello, ES Module!",
|
18
|
+
});
|
19
|
+
});
|
20
|
+
it("should handle script type=module with file imports", async () => {
|
21
|
+
await testInBrowser({
|
22
|
+
browser,
|
23
|
+
files: jsScriptTagTypeModules,
|
24
|
+
expectedLog: "Hello, ES Module File!",
|
25
|
+
});
|
26
|
+
});
|
27
|
+
it("should handle fetch interception", async () => {
|
28
|
+
await testInBrowser({
|
29
|
+
browser,
|
30
|
+
files: fetchInterception,
|
31
|
+
expectedLog: "Fetch intercepted successfully",
|
32
|
+
});
|
33
|
+
});
|
34
|
+
it.skip("should handle ESM builds from npm packages", async () => {
|
35
|
+
await testInBrowser({
|
36
|
+
browser,
|
37
|
+
files: esmBuild,
|
38
|
+
expectedLog: new RegExp(/\d{4}-\d{2}-\d{2}/), // matches date format yyyy-MM-dd
|
39
|
+
});
|
40
|
+
});
|
41
|
+
it.skip("should handle React JSX", async () => {
|
42
|
+
await testInBrowser({
|
43
|
+
browser,
|
44
|
+
files: reactJsx,
|
45
|
+
expectedLog: "Hello React JSX!",
|
46
|
+
evaluateInBrowser: async (page) => {
|
47
|
+
return await page.evaluate(() => {
|
48
|
+
return document.querySelector("#root div")
|
49
|
+
?.textContent;
|
50
|
+
});
|
51
|
+
},
|
52
|
+
});
|
53
|
+
});
|
54
|
+
it.skip("should handle D3 usage", async () => {
|
55
|
+
await testInBrowser({
|
56
|
+
browser,
|
57
|
+
files: d3Usage,
|
58
|
+
expectedLog: "D3 chart rendered successfully",
|
59
|
+
evaluateInBrowser: async (page) => {
|
60
|
+
return await page.evaluate(() => {
|
61
|
+
return (document.querySelector("#chart svg circle") !==
|
62
|
+
null);
|
63
|
+
});
|
64
|
+
},
|
65
|
+
});
|
66
|
+
});
|
67
|
+
it("should handle Three.js usage", async () => {
|
68
|
+
await testInBrowser({
|
69
|
+
browser,
|
70
|
+
files: threeJsUsage,
|
71
|
+
expectedLog: "Three.js imports: object function",
|
72
|
+
});
|
73
|
+
});
|
74
|
+
it.skip("should handle React hooks", async () => {
|
75
|
+
await testInBrowser({
|
76
|
+
browser,
|
77
|
+
files: reactHooks,
|
78
|
+
expectedLog: "React Hooks working: count is 0",
|
79
|
+
evaluateInBrowser: async (page) => {
|
80
|
+
return await page.evaluate(() => {
|
81
|
+
return (document.querySelector("#root p")
|
82
|
+
?.textContent === "You clicked 0 times");
|
83
|
+
});
|
84
|
+
},
|
85
|
+
});
|
86
|
+
});
|
87
|
+
it.skip("should handle TypeScript support", async () => {
|
88
|
+
await testInBrowser({
|
89
|
+
browser,
|
90
|
+
files: typeScriptSupport,
|
91
|
+
expectedLog: "TypeScript is working",
|
92
|
+
evaluateInBrowser: async (page) => {
|
93
|
+
return await page.evaluate(() => {
|
94
|
+
return (document.querySelector("#app h1")
|
95
|
+
?.textContent === "Hello, John Doe!");
|
96
|
+
});
|
97
|
+
},
|
98
|
+
});
|
99
|
+
});
|
100
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,19 @@
|
|
1
|
+
/**
|
2
|
+
* Converts VizContent format to FileCollection format
|
3
|
+
* VizContent has files as {id: {name, text}} structure
|
4
|
+
* FileCollection is a simple {name: text} structure
|
5
|
+
*/
|
6
|
+
export const vizContentToFileCollection = (vizContent) => {
|
7
|
+
const fileCollection = {};
|
8
|
+
// Extract files from vizContent
|
9
|
+
const { files } = vizContent;
|
10
|
+
// Return empty object if files is undefined
|
11
|
+
if (!files) {
|
12
|
+
return fileCollection;
|
13
|
+
}
|
14
|
+
// Convert each VizFile to the FileCollection format
|
15
|
+
Object.values(files).forEach((file) => {
|
16
|
+
fileCollection[file.name] = file.text;
|
17
|
+
});
|
18
|
+
return fileCollection;
|
19
|
+
};
|
@@ -0,0 +1,75 @@
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
2
|
+
import { vizContentToFileCollection } from "./vizContentToFileCollection";
|
3
|
+
describe("vizContentToFileCollection", () => {
|
4
|
+
it("should convert VizContent files to FileCollection format", () => {
|
5
|
+
const mockVizContent = {
|
6
|
+
id: "test-viz-123",
|
7
|
+
files: {
|
8
|
+
file1: {
|
9
|
+
name: "index.html",
|
10
|
+
text: "<html>Test</html>",
|
11
|
+
},
|
12
|
+
file2: {
|
13
|
+
name: "script.js",
|
14
|
+
text: 'console.log("Hello");',
|
15
|
+
},
|
16
|
+
},
|
17
|
+
};
|
18
|
+
const result = vizContentToFileCollection(mockVizContent);
|
19
|
+
expect(result).toEqual({
|
20
|
+
"index.html": "<html>Test</html>",
|
21
|
+
"script.js": 'console.log("Hello");',
|
22
|
+
});
|
23
|
+
});
|
24
|
+
it("should return an empty object when no files exist", () => {
|
25
|
+
const mockVizContent = {
|
26
|
+
id: "empty-viz",
|
27
|
+
files: {},
|
28
|
+
};
|
29
|
+
const result = vizContentToFileCollection(mockVizContent);
|
30
|
+
expect(result).toEqual({});
|
31
|
+
});
|
32
|
+
it("should return an empty object when no files property", () => {
|
33
|
+
const mockVizContent = {
|
34
|
+
id: "empty-viz",
|
35
|
+
// @ts-ignore
|
36
|
+
files: undefined,
|
37
|
+
};
|
38
|
+
const result = vizContentToFileCollection(mockVizContent);
|
39
|
+
expect(result).toEqual({});
|
40
|
+
});
|
41
|
+
it("should handle files with special characters in names", () => {
|
42
|
+
const mockVizContent = {
|
43
|
+
id: "special-chars-viz",
|
44
|
+
files: {
|
45
|
+
fileId1: {
|
46
|
+
name: "file with spaces.txt",
|
47
|
+
text: "content",
|
48
|
+
},
|
49
|
+
fileId2: { name: "data.csv", text: "a,b,c\n1,2,3" },
|
50
|
+
},
|
51
|
+
};
|
52
|
+
const result = vizContentToFileCollection(mockVizContent);
|
53
|
+
expect(result).toEqual({
|
54
|
+
"file with spaces.txt": "content",
|
55
|
+
"data.csv": "a,b,c\n1,2,3",
|
56
|
+
});
|
57
|
+
});
|
58
|
+
it("should preserve file content exactly", () => {
|
59
|
+
const longText = `function complex() {
|
60
|
+
return {
|
61
|
+
nested: {
|
62
|
+
data: [1, 2, 3]
|
63
|
+
}
|
64
|
+
};
|
65
|
+
}`;
|
66
|
+
const mockVizContent = {
|
67
|
+
id: "preserve-content-viz",
|
68
|
+
files: {
|
69
|
+
fileId: { name: "complex.js", text: longText },
|
70
|
+
},
|
71
|
+
};
|
72
|
+
const result = vizContentToFileCollection(mockVizContent);
|
73
|
+
expect(result["complex.js"]).toBe(longText);
|
74
|
+
});
|
75
|
+
});
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { virtualFileSystem } from "../common/virtualFileSystem";
|
2
|
+
import { sucrasePlugin } from "../common/sucrasePlugin";
|
3
|
+
import { getGlobals, packageJSON, } from "../common/packageJson";
|
4
|
+
export const computeBundleJSV2 = async ({ files, rollup, enableSourcemap = true, }) => {
|
5
|
+
const indexJSContent = files["index.js"];
|
6
|
+
if (!indexJSContent) {
|
7
|
+
throw new Error("Missing index.js");
|
8
|
+
}
|
9
|
+
const inputOptions = {
|
10
|
+
input: "./index.js",
|
11
|
+
plugins: [virtualFileSystem(files), sucrasePlugin()],
|
12
|
+
onwarn(warning, warn) {
|
13
|
+
// Suppress "treating module as external dependency" warnings
|
14
|
+
if (warning.code === "UNRESOLVED_IMPORT")
|
15
|
+
return;
|
16
|
+
warn(warning);
|
17
|
+
},
|
18
|
+
};
|
19
|
+
const bundle = await rollup(inputOptions);
|
20
|
+
const pkg = packageJSON(files);
|
21
|
+
const globals = getGlobals(pkg);
|
22
|
+
const outputOptions = {
|
23
|
+
format: "iife",
|
24
|
+
globals,
|
25
|
+
sourcemap: enableSourcemap,
|
26
|
+
};
|
27
|
+
const { output } = await bundle.generate(outputOptions);
|
28
|
+
return output[0].code;
|
29
|
+
};
|
@@ -0,0 +1,81 @@
|
|
1
|
+
import { dependencies, getConfiguredLibraries, dependencySource, } from "../common/packageJson";
|
2
|
+
let parser;
|
3
|
+
const DEBUG = false;
|
4
|
+
// Expose a way to inject a DOMParser implementation
|
5
|
+
// when we're in a Node environment (tests, API server).
|
6
|
+
export const setJSDOM = (JSDOMInstance) => {
|
7
|
+
const dom = new JSDOMInstance();
|
8
|
+
parser = new dom.window.DOMParser();
|
9
|
+
};
|
10
|
+
// If we're in the browser, use native DOMParser.
|
11
|
+
if (typeof window !== "undefined") {
|
12
|
+
parser = new DOMParser();
|
13
|
+
}
|
14
|
+
const injectScripts = (htmlTemplate, files) => {
|
15
|
+
if (!parser) {
|
16
|
+
throw new Error("DOM parser is not defined. Did you forget to call setJSDOM()?");
|
17
|
+
}
|
18
|
+
const doc = parser.parseFromString(htmlTemplate, "text/html");
|
19
|
+
// Ensure we have a head element
|
20
|
+
if (!doc.head) {
|
21
|
+
const head = doc.createElement("head");
|
22
|
+
doc.documentElement.insertBefore(head, doc.documentElement.firstChild);
|
23
|
+
}
|
24
|
+
// Ensure we have a body element
|
25
|
+
if (!doc.body) {
|
26
|
+
const body = doc.createElement("body");
|
27
|
+
doc.documentElement.appendChild(body);
|
28
|
+
}
|
29
|
+
// Handle dependencies first (in head)
|
30
|
+
const deps = Object.entries(dependencies(files));
|
31
|
+
if (deps.length > 0) {
|
32
|
+
const libraries = getConfiguredLibraries(files);
|
33
|
+
// Remove any existing dependency scripts
|
34
|
+
deps.forEach(([name]) => {
|
35
|
+
const selector = `script[src*="${name}@"]`;
|
36
|
+
const existingScripts = doc.querySelectorAll(selector);
|
37
|
+
existingScripts.forEach((script) => script.remove());
|
38
|
+
});
|
39
|
+
// Add dependency scripts in order
|
40
|
+
deps
|
41
|
+
.map(([name, version]) => dependencySource({ name, version }, libraries))
|
42
|
+
.forEach((url) => {
|
43
|
+
const scriptTag = doc.createElement("script");
|
44
|
+
scriptTag.src = url;
|
45
|
+
doc.head.appendChild(scriptTag);
|
46
|
+
});
|
47
|
+
}
|
48
|
+
// Handle bundle.js (in body)
|
49
|
+
if (files["bundle.js"] || files["index.js"]) {
|
50
|
+
// Remove any existing bundle.js script tags
|
51
|
+
const existingScripts = doc.querySelectorAll('script[src="bundle.js"]');
|
52
|
+
existingScripts.forEach((script) => script.remove());
|
53
|
+
const bundleScriptTag = doc.createElement("script");
|
54
|
+
bundleScriptTag.src = "bundle.js";
|
55
|
+
doc.body.appendChild(bundleScriptTag);
|
56
|
+
}
|
57
|
+
return `<!DOCTYPE html>${doc.documentElement.outerHTML}`;
|
58
|
+
};
|
59
|
+
// Compute the index.html file from the files.
|
60
|
+
// Includes:
|
61
|
+
// - bundle.js script tag
|
62
|
+
// - dependencies script tag(s)
|
63
|
+
export const getComputedIndexHtml = (files) => {
|
64
|
+
// Isolate the index.html file.
|
65
|
+
const htmlTemplate = files["index.html"];
|
66
|
+
// If there is no index.html file, return an empty string.
|
67
|
+
if (!htmlTemplate &&
|
68
|
+
!files["index.js"] &&
|
69
|
+
!files["bundle.js"]) {
|
70
|
+
DEBUG &&
|
71
|
+
console.log("[getComputedIndexHtml] No index.html file found");
|
72
|
+
return "";
|
73
|
+
}
|
74
|
+
// If index.html is empty but we have JS files, create a minimal HTML template
|
75
|
+
const template = htmlTemplate ||
|
76
|
+
"<!DOCTYPE html><html><head></head><body></body></html>";
|
77
|
+
const indexHtml = injectScripts(template, files);
|
78
|
+
DEBUG &&
|
79
|
+
console.log("[getComputedIndexHtml] indexHtml", indexHtml);
|
80
|
+
return indexHtml;
|
81
|
+
};
|