Skip to content

Commit a1aba1f

Browse files
test(jco): improve documentation for setup helper
1 parent ad2a596 commit a1aba1f

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

packages/jco/test/helpers.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,30 @@ export async function getTmpDir() {
115115
/**
116116
* Set up an async test to be run
117117
*
118+
* Example:
119+
* ```
120+
* const { instance, cleanup } = await setupAsyncTest({
121+
* component: {
122+
* path: join(
123+
* P3_COMPONENT_FIXTURES_DIR,
124+
* 'async-simple-import.wasm',
125+
* ),
126+
* imports: {
127+
* ...new WASIShim().getImportObject(),
128+
* loadString: async () => "loaded",
129+
* loadU32: async () => 43,
130+
* },
131+
* },
132+
* jco: {
133+
* transpile: {
134+
* extraArgs: {
135+
* minify: false, // for ease of debugging
136+
* }
137+
* }
138+
* }
139+
* });
140+
* ```
141+
*
118142
* @param {object} args - Arguments for running the async test
119143
* @param {function} args.testFn - Arguments for running the async test
120144
* @param {object} args.jco - JCO-related confguration for running the async test
@@ -124,7 +148,7 @@ export async function getTmpDir() {
124148
* @param {object} args.component - configuration for an existing component that should be transpiled
125149
* @param {string} args.component.name - name of the component
126150
* @param {string} args.component.path - path to the WebAssembly binary for the existing component
127-
* @param {object[]} args.component.import - imports that should be provided to the module at instantiation time
151+
* @param {object} args.component.imports - imports that should be provided to the module at instantiation time
128152
* @param {object} args.component.build - configuration for building an ephemeral component to be tested
129153
* @param {object} args.component.js.source - Javascript source code for a component
130154
* @param {object} args.component.wit.source - WIT definitions (inlined) for a component
@@ -215,7 +239,7 @@ export async function setupAsyncTest(args) {
215239

216240
// Build a directory for the transpiled component output to be put in
217241
// (possibly inside the passed in outputDir)
218-
const moduleOutputDir = join(outputDir, component.name);
242+
const moduleOutputDir = join(outputDir, componentName);
219243
try {
220244
await stat(moduleOutputDir);
221245
} catch (err) {
@@ -260,6 +284,8 @@ export async function setupAsyncTest(args) {
260284
const esModuleSourcePathURL = pathToFileURL(esModuleOutputPath);
261285
const esModule = await import(esModuleSourcePathURL);
262286

287+
console.log('MODULE PATH?', esModuleOutputPath);
288+
263289
// Optionally instantiate the ES module
264290
//
265291
// It's useful to be able to skip instantiation of the instantiation should happen

packages/jco/test/p3/async.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ suite('Async (WASI P3)', () => {
6666
loadU32: async () => 43,
6767
},
6868
},
69+
jco: {
70+
transpile: {
71+
extraArgs: {
72+
minify: false,
73+
}
74+
}
75+
}
6976
});
7077

7178
assert.typeOf(instance.asyncGetString, 'function');

0 commit comments

Comments
 (0)