@vizhub/runtime 0.3.0 → 0.3.2
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/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/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/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/package.json +14 -7
@@ -0,0 +1,34 @@
|
|
1
|
+
export const reactJsx = {
|
2
|
+
"index.html": `<!DOCTYPE html>
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<title>React JSX Test</title>
|
6
|
+
</head>
|
7
|
+
<body>
|
8
|
+
<div id="root"></div>
|
9
|
+
<script type="module" src="index.jsx"></script>
|
10
|
+
</body>
|
11
|
+
</html>`,
|
12
|
+
"index.jsx": `import React from 'react';
|
13
|
+
import ReactDOM from 'react-dom/client';
|
14
|
+
import App from './App.jsx';
|
15
|
+
|
16
|
+
ReactDOM.createRoot(document.getElementById('root')).render(
|
17
|
+
<React.StrictMode>
|
18
|
+
<App />
|
19
|
+
</React.StrictMode>
|
20
|
+
);`,
|
21
|
+
"App.jsx": `import React from 'react';
|
22
|
+
|
23
|
+
function App() {
|
24
|
+
return <div>Hello React JSX!</div>;
|
25
|
+
}
|
26
|
+
|
27
|
+
export default App;`,
|
28
|
+
"package.json": `{
|
29
|
+
"dependencies": {
|
30
|
+
"react": "^18.2.0",
|
31
|
+
"react-dom": "^18.2.0"
|
32
|
+
}
|
33
|
+
}`,
|
34
|
+
};
|
@@ -0,0 +1,24 @@
|
|
1
|
+
export const threeJsUsage = {
|
2
|
+
"index.html": `<!DOCTYPE html>
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<title>Three.js Test</title>
|
6
|
+
<script type="importmap">
|
7
|
+
{
|
8
|
+
"imports": {
|
9
|
+
"three": "https://cdn.jsdelivr.net/npm/three@0.175.0/build/three.module.js",
|
10
|
+
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.175.0/examples/jsm/"
|
11
|
+
}
|
12
|
+
}
|
13
|
+
</script>
|
14
|
+
</head>
|
15
|
+
<body>
|
16
|
+
<script type="module" src="index.js"></script>
|
17
|
+
</body>
|
18
|
+
</html>`,
|
19
|
+
"index.js": `
|
20
|
+
import * as THREE from 'three';
|
21
|
+
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
|
22
|
+
console.log('Three.js imports:', typeof THREE, typeof OrbitControls);
|
23
|
+
`,
|
24
|
+
};
|
@@ -0,0 +1,29 @@
|
|
1
|
+
export const typeScriptSupport = {
|
2
|
+
"index.html": `<!DOCTYPE html>
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<title>TypeScript Test</title>
|
6
|
+
</head>
|
7
|
+
<body>
|
8
|
+
<div id="app"></div>
|
9
|
+
<script type="module" src="index.ts"></script>
|
10
|
+
</body>
|
11
|
+
</html>`,
|
12
|
+
"index.ts": `import { Person } from './person';
|
13
|
+
|
14
|
+
const person: Person = {
|
15
|
+
name: 'John Doe',
|
16
|
+
age: 30
|
17
|
+
};
|
18
|
+
|
19
|
+
document.getElementById('app')!.innerHTML = \`
|
20
|
+
<h1>Hello, \${person.name}!</h1>
|
21
|
+
<p>You are \${person.age} years old.</p>
|
22
|
+
\`;
|
23
|
+
|
24
|
+
console.log('TypeScript is working');`,
|
25
|
+
"person.ts": `export interface Person {
|
26
|
+
name: string;
|
27
|
+
age: number;
|
28
|
+
}`,
|
29
|
+
};
|
@@ -0,0 +1,47 @@
|
|
1
|
+
import { rollup } from "rollup";
|
2
|
+
import { expect } from "vitest";
|
3
|
+
import { buildHTML } from "../index";
|
4
|
+
const DEBUG = false;
|
5
|
+
export async function testInBrowser({ browser, files, vizCache, slugCache, vizId, expectedLog, evaluateInBrowser, getSvelteCompiler, }) {
|
6
|
+
const page = await browser.newPage();
|
7
|
+
try {
|
8
|
+
// Capture console.log output
|
9
|
+
const logs = [];
|
10
|
+
page.on("console", (message) => logs.push(message.text()));
|
11
|
+
// Capture page errors
|
12
|
+
page.on("pageerror", (error) => {
|
13
|
+
console.error("[testInBrowser] pageerror:", error);
|
14
|
+
});
|
15
|
+
// Load the HTML
|
16
|
+
const html = await buildHTML({
|
17
|
+
files,
|
18
|
+
vizCache,
|
19
|
+
slugCache,
|
20
|
+
vizId,
|
21
|
+
rollup,
|
22
|
+
getSvelteCompiler,
|
23
|
+
});
|
24
|
+
await page.setContent(html);
|
25
|
+
// Wait a bit for scripts to execute
|
26
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
27
|
+
DEBUG && console.log("[testInBrowser] html:", html);
|
28
|
+
DEBUG && console.log("[testInBrowser] logs:", logs);
|
29
|
+
// Check console output
|
30
|
+
if (typeof expectedLog === "string") {
|
31
|
+
expect(logs).toContain(expectedLog);
|
32
|
+
}
|
33
|
+
else {
|
34
|
+
// If it's a RegExp, find a log that matches
|
35
|
+
const matchingLog = logs.find((log) => expectedLog.test(log));
|
36
|
+
expect(matchingLog).toBeDefined();
|
37
|
+
}
|
38
|
+
// If evaluateInBrowser is provided, run it and expect the result to be truthy
|
39
|
+
if (evaluateInBrowser) {
|
40
|
+
const result = await evaluateInBrowser(page);
|
41
|
+
expect(result).toBeTruthy();
|
42
|
+
}
|
43
|
+
}
|
44
|
+
finally {
|
45
|
+
await page.close();
|
46
|
+
}
|
47
|
+
}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
import { rollup } from "rollup";
|
2
|
+
import { expect } from "vitest";
|
3
|
+
import { buildHTML } from "../index";
|
4
|
+
const DEBUG = false;
|
5
|
+
// Invokes Puppeteer to test the HTML in a browser,
|
6
|
+
// and isolates the console.log output to check against expectedLog.
|
7
|
+
// Captures stack trace from an error in the page and validates that sourcemaps are working
|
8
|
+
export async function testStackTrace({ browser, files, expectedLineNumber, }) {
|
9
|
+
const page = await browser.newPage();
|
10
|
+
let errorCaptured = false;
|
11
|
+
try {
|
12
|
+
// Enable sourcemaps for proper stack traces
|
13
|
+
const html = await buildHTML({
|
14
|
+
files,
|
15
|
+
rollup,
|
16
|
+
enableSourcemap: true,
|
17
|
+
});
|
18
|
+
// Capture page errors with their stack traces
|
19
|
+
page.on("pageerror", (error) => {
|
20
|
+
errorCaptured = true;
|
21
|
+
const stack = error.stack || "";
|
22
|
+
DEBUG &&
|
23
|
+
console.log("[testStackTrace] Error stack:", stack);
|
24
|
+
// Verify the error message contains the expected text
|
25
|
+
expect(error.message).toContain("Hello main!");
|
26
|
+
// Find any stack frame with a line number close to what we expect
|
27
|
+
// Different browsers format stack traces differently
|
28
|
+
const stackLines = stack.split("\n");
|
29
|
+
let foundExpectedLineNumber = false;
|
30
|
+
for (const line of stackLines) {
|
31
|
+
// Look for patterns like: at generateError (error.js:3:3) or at file:///path/bundle.js:20:3
|
32
|
+
const lineMatches = line.match(/:(\d+):/);
|
33
|
+
if (lineMatches && lineMatches[1]) {
|
34
|
+
const lineNumber = parseInt(lineMatches[1], 10);
|
35
|
+
DEBUG &&
|
36
|
+
console.log(`[testStackTrace] Found line number in stack: ${lineNumber}`);
|
37
|
+
// Check if this line number matches any of our expected line numbers
|
38
|
+
if (expectedLineNumber === lineNumber) {
|
39
|
+
foundExpectedLineNumber = true;
|
40
|
+
break;
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
44
|
+
expect(foundExpectedLineNumber, `Stack trace should contain expected line number(s): ${expectedLineNumber}`).toBe(true);
|
45
|
+
});
|
46
|
+
await page.setContent(html);
|
47
|
+
// Wait a bit for scripts to execute and error to be thrown
|
48
|
+
await new Promise((resolve) => setTimeout(resolve, 200));
|
49
|
+
// Verify that we actually captured an error
|
50
|
+
expect(errorCaptured, "An error should have been thrown").toBe(true);
|
51
|
+
}
|
52
|
+
finally {
|
53
|
+
await page.close();
|
54
|
+
}
|
55
|
+
}
|
@@ -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
|
+
};
|