Skip to content

Commit dcbcb92

Browse files
committed
test: auto index for manual testing
1 parent 4476c81 commit dcbcb92

File tree

6 files changed

+23
-61
lines changed

6 files changed

+23
-61
lines changed

packages/nuejs/test/compile.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
11
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs'
2-
import { join } from 'node:path'
2+
import { join, dirname } from 'node:path'
3+
import { fileURLToPath } from 'node:url'
34

45
import { parse } from '../src/compile.js'
5-
import { getDirname } from './test-utils.js'
66

7-
const srcdir = getDirname(import.meta.url)
7+
const genIndex = (name) => `
8+
<meta charset="utf-8">
9+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
10+
<link rel="stylesheet" href="../../client/test.css">
11+
12+
<h1>${name}</h1>
13+
14+
<div id="container"></div>
15+
16+
<script type="module">
17+
import createApp from '../../../src/browser/nue.js';
18+
import { lib } from './index.js';
19+
const [App, ...deps] = lib
20+
createApp(App, {}, deps).mount(container)
21+
</script>
22+
`
23+
24+
const srcdir = dirname(fileURLToPath(import.meta.url))
825

926
// Ensure the dist directory exists
1027
const distDir = join(srcdir, 'dist')
@@ -35,5 +52,7 @@ for (const { testPath, name } of testComponentDirs) {
3552
const output = `export const lib = [${components.join(',')}]`
3653
writeFileSync(outputPath, output)
3754

55+
writeFileSync(join(outputDir, 'index.html'), genIndex(name))
56+
3857
console.log(`Compiled ${name}: ${outputPath}`)
3958
}

packages/nuejs/test/test-clicks/index.html

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/nuejs/test/test-fors/index.html

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/nuejs/test/test-ifs/index.html

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/nuejs/test/test-refs/index.html

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/nuejs/test/test-utils.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@ import { createWindow } from 'domino'
77
import { parse } from '../src/compile.js'
88

99

10-
/**
11-
* Get directory from url
12-
* @param {Url} url - Pass `import.meta.url`
13-
* @returns {string} Directory path containing the current file
14-
*/
15-
export function getDirname(url) {
16-
return dirname(fileURLToPath(url))
17-
}
18-
1910
/**
2011
* Get directory path from url and return function for usage with {@linkcode mountTestComponent}
2112
* @param {Url} url - `import.meta.url` to get the test directory
@@ -25,7 +16,7 @@ export function mkConfigBase(url) {
2516
* @param {string} componentName
2617
* @param {Object?} data
2718
*/
28-
return (componentName, data) => ({ testPath: getDirname(url), componentName, data })
19+
return (componentName, data) => ({ testPath: dirname(fileURLToPath(url)), componentName, data })
2920
}
3021

3122

0 commit comments

Comments
 (0)