@@ -6,25 +6,39 @@ import { createWindow } from 'domino'
6
6
7
7
import { parse } from '../src/compile.js'
8
8
9
- /* Use like `getDirname(import.meta.url)` */
9
+
10
+ /**
11
+ * Get directory from url
12
+ * @param {Url } url - Pass `import.meta.url`
13
+ * @returns {string } Directory path containing the current file
14
+ */
10
15
export function getDirname ( url ) {
11
16
return dirname ( fileURLToPath ( url ) )
12
17
}
13
18
19
+ /**
20
+ * Get directory path from url and return function for usage with {@linkcode mountTestComponent}
21
+ * @param {Url } url - `import.meta.url` to get the test directory
22
+ */
14
23
export function mkConfigBase ( url ) {
15
- return componentName => ( { testName : getDirname ( url ) , componentName } )
24
+ /**
25
+ * @param {string } componentName
26
+ * @param {Object? } data
27
+ */
28
+ return ( componentName , data ) => ( { testPath : getDirname ( url ) , componentName, data } )
16
29
}
17
30
31
+
18
32
/**
19
33
* Mounts a component from a test directory
20
34
* @param {Object } options - Mount options
21
- * @param {string } options.testName - The name of the test directory
35
+ * @param {string } options.testPath - The path to the test directory
22
36
* @param {string } options.componentName - Name of the specific component to mount
23
37
* @param {Object } [options.data={}] - Data to initialize the component with
24
38
*/
25
- export async function mountTestComponent ( { testName , componentName, data = { } } ) {
39
+ export async function mountTestComponent ( { testPath , componentName, data = { } } ) {
26
40
// Validate inputs
27
- if ( ! testName || ! componentName ) throw new Error ( 'Required parameters missing: "testName " and "componentName" must be provided' )
41
+ if ( ! testPath || ! componentName ) throw new Error ( 'Required parameters missing: "testPath " and "componentName" must be provided' )
28
42
29
43
// Setup domino DOM environment
30
44
const window = createWindow ( '<!DOCTYPE html><html><body></body></html>' )
@@ -38,7 +52,7 @@ export async function mountTestComponent({ testName, componentName, data = {} })
38
52
39
53
try {
40
54
// Load and parse component
41
- const dhtmlPath = join ( testName , 'component.dhtml' )
55
+ const dhtmlPath = join ( testPath , 'component.dhtml' )
42
56
const source = readFileSync ( dhtmlPath , 'utf-8' )
43
57
const components = parseComponents ( source )
44
58
@@ -66,6 +80,7 @@ export async function mountTestComponent({ testName, componentName, data = {} })
66
80
}
67
81
}
68
82
83
+
69
84
/**
70
85
* Parses component source and returns an array of component objects
71
86
* @param {string } source - The component source code
0 commit comments