-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.js
More file actions
70 lines (59 loc) · 2.25 KB
/
example.js
File metadata and controls
70 lines (59 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* Example usage of Shopify Functions WASM Testing Helpers
*/
const {
loadFixture,
validateTestAssets,
buildFunction,
runFunction
} = require('./index.js');
async function runExample() {
console.log('=== Shopify Functions WASM Testing Helpers Example ===\n');
// 1. Load a fixture from test data
console.log('1. Loading a fixture from test data...');
try {
const fixture = loadFixture('20250915_184036_156Z_extensions_cart-checkout-validation_ba711d.json');
console.log('Fixture loaded successfully');
console.log('Export :', fixture.export);
console.log('Input:', fixture.input);
console.log('Expected Output:', fixture.expectedOutput);
console.log('Target:', fixture.target);
console.log('');
} catch (error) {
console.log('Error loading fixture:', error.message);
console.log('');
}
// 2. Validate test assets
console.log('2. Validating test assets...');
try {
const fixture = loadFixture('20250915_184036_156Z_extensions_cart-checkout-validation_ba711d.json');
const validation = validateTestAssets(fixture);
console.log('Validation result:', validation.isValid ? 'VALID' : 'INVALID');
if (!validation.isValid) {
console.log('Validation errors:', validation.errors);
}
console.log('');
} catch (error) {
console.log('Error validating fixture:', error.message);
console.log('');
}
// 3. Build a function payload
console.log('3. Building a function payload...');
// You can provide a specific function path, or let it auto-detect
// const buildResult = await buildFunction('/path/to/your/function');
const buildResult = await buildFunction();
console.log('Function payload built successfully');
console.log('Build result:', buildResult);
// 4. Run a function
console.log('4. Running a function...');
// You can provide a specific function path, or let it auto-detect
// const result = await runFunction(fixture.export, fixture.input, '/path/to/your/function');
const result = await runFunction(fixture.export, fixture.input);
console.log('Function executed successfully');
console.log('Result status:', result.result.output.operations.length);
console.log('Output operations:', result.result.output.operations.length);
console.log('');
console.log('=== Example completed ===');
}
// Run the example
runExample().catch(console.error);