Skip to content

Commit 3cd7655

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

File tree

6 files changed

+22
-61
lines changed

6 files changed

+22
-61
lines changed

packages/nuejs/test/compile.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
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+
<link rel="stylesheet" href="../../client/test.css">
9+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
10+
11+
<h1>${name}</h1>
12+
13+
<div id="container"></div>
14+
15+
<script type="module">
16+
import createApp from '../../../src/browser/nue.js';
17+
import { lib } from './index.js';
18+
const [App, ...deps] = lib
19+
createApp(App, {}, deps).mount(container)
20+
</script>
21+
`
22+
23+
const srcdir = dirname(fileURLToPath(import.meta.url))
824

925
// Ensure the dist directory exists
1026
const distDir = join(srcdir, 'dist')
@@ -35,5 +51,7 @@ for (const { testPath, name } of testComponentDirs) {
3551
const output = `export const lib = [${components.join(',')}]`
3652
writeFileSync(outputPath, output)
3753

54+
writeFileSync(join(outputDir, 'index.html'), genIndex(name))
55+
3856
console.log(`Compiled ${name}: ${outputPath}`)
3957
}

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)