Skip to content

Commit fb52ce1

Browse files
committed
add wasm integration tests
1 parent 773d157 commit fb52ce1

File tree

100 files changed

+2182
-33
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+2182
-33
lines changed

.github/workflows/validate-js-functions.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ jobs:
2525
- name: Generate types
2626
run: yarn js-typegen
2727
- name: Test
28-
run: yarn js-test
28+
run: yarn js-test:unit

.github/workflows/validate-ts-functions.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ jobs:
2525
- name: Generate types
2626
run: yarn js-typegen
2727
- name: Test
28-
run: yarn js-test
28+
run: yarn js-test:unit

functions-cart-checkout-validation-js/package.json.liquid

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
"name": "{{handle}}",
33
"version": "0.0.1",
44
"license": "UNLICENSED",
5+
"type": "module",
56
"scripts": {
67
"shopify": "npm exec -- shopify",
78
"typegen": "npm exec -- shopify app function typegen",
89
"build": "npm exec -- shopify app function build",
910
"preview": "npm exec -- shopify app function run",
10-
"test": "vitest"
11+
"test": "vitest",
12+
"test:unit": "vitest run src/"
1113
},
1214
"codegen": {
1315
"schema": "schema.graphql",
@@ -28,6 +30,7 @@
2830
"@shopify/shopify_function": "2.0.0"
2931
},
3032
"devDependencies": {
31-
"vitest": "2.1.9"
33+
"@shopify/shopify-function-test-helpers": "~0.0.0",
34+
"vitest": "^3.2.4"
3235
}
3336
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import path from "path";
2+
import fs from "fs";
3+
import { describe, beforeAll, test, expect } from "vitest";
4+
import { buildFunction, getFunctionInfo, loadSchema, loadInputQuery, loadFixture, validateTestAssets, runFunction } from "@shopify/shopify-function-test-helpers";
5+
6+
describe("Default Integration Test", () => {
7+
let schema;
8+
let functionDir;
9+
let functionInfo;
10+
let schemaPath;
11+
let targeting;
12+
let functionRunnerPath;
13+
let wasmPath;
14+
15+
beforeAll(async () => {
16+
functionDir = path.dirname(__dirname);
17+
await buildFunction(functionDir);
18+
functionInfo = await getFunctionInfo(functionDir);
19+
({ schemaPath, functionRunnerPath, wasmPath, targeting } = functionInfo);
20+
schema = await loadSchema(schemaPath);
21+
}, 45000);
22+
23+
const fixturesDir = path.join(__dirname, "fixtures");
24+
const fixtureFiles = fs
25+
.readdirSync(fixturesDir)
26+
.filter((file) => file.endsWith(".json"))
27+
.map((file) => path.join(fixturesDir, file));
28+
29+
fixtureFiles.forEach((fixtureFile) => {
30+
test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => {
31+
const fixture = await loadFixture(fixtureFile);
32+
const targetInputQueryPath = targeting[fixture.target].inputQueryPath;
33+
const inputQueryAST = await loadInputQuery(targetInputQueryPath);
34+
35+
const validationResult = await validateTestAssets({ schema, fixture, inputQueryAST });
36+
expect(validationResult.inputQuery.errors).toEqual([]);
37+
expect(validationResult.inputFixture.errors).toEqual([]);
38+
expect(validationResult.outputFixture.errors).toEqual([]);
39+
40+
const runResult = await runFunction(fixture, functionRunnerPath, wasmPath, targetInputQueryPath, schemaPath);
41+
expect(runResult.error).toBeNull();
42+
expect(runResult.result.output).toEqual(fixture.expectedOutput);
43+
}, 10000);
44+
});
45+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"payload": {
3+
"export": "cart-validations-generate-run",
4+
"target": "cart.validations.generate.run",
5+
"input": {
6+
"cart": {
7+
"lines": [
8+
{
9+
"quantity": 1
10+
},
11+
{
12+
"quantity": 1
13+
},
14+
{
15+
"quantity": 1
16+
}
17+
]
18+
}
19+
},
20+
"output": {
21+
"operations": [
22+
{
23+
"validationAdd": {
24+
"errors": []
25+
}
26+
}
27+
]
28+
}
29+
}
30+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default {};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "{{handle}}",
3+
"version": "0.0.1",
4+
"private": true,
5+
"type": "module",
6+
"scripts": {
7+
"test": "vitest run"
8+
},
9+
"devDependencies": {
10+
"@shopify/shopify-function-test-helpers": "~0.0.0",
11+
"vitest": "^3.2.4"
12+
}
13+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import path from "path";
2+
import fs from "fs";
3+
import { describe, beforeAll, test, expect } from "vitest";
4+
import { buildFunction, getFunctionInfo, loadSchema, loadInputQuery, loadFixture, validateTestAssets, runFunction } from "@shopify/shopify-function-test-helpers";
5+
6+
describe("Default Integration Test", () => {
7+
let schema;
8+
let functionDir;
9+
let functionInfo;
10+
let schemaPath;
11+
let targeting;
12+
let functionRunnerPath;
13+
let wasmPath;
14+
15+
beforeAll(async () => {
16+
functionDir = path.dirname(__dirname);
17+
await buildFunction(functionDir);
18+
functionInfo = await getFunctionInfo(functionDir);
19+
({ schemaPath, functionRunnerPath, wasmPath, targeting } = functionInfo);
20+
schema = await loadSchema(schemaPath);
21+
}, 45000);
22+
23+
const fixturesDir = path.join(__dirname, "fixtures");
24+
const fixtureFiles = fs
25+
.readdirSync(fixturesDir)
26+
.filter((file) => file.endsWith(".json"))
27+
.map((file) => path.join(fixturesDir, file));
28+
29+
fixtureFiles.forEach((fixtureFile) => {
30+
test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => {
31+
const fixture = await loadFixture(fixtureFile);
32+
const targetInputQueryPath = targeting[fixture.target].inputQueryPath;
33+
const inputQueryAST = await loadInputQuery(targetInputQueryPath);
34+
35+
const validationResult = await validateTestAssets({ schema, fixture, inputQueryAST });
36+
expect(validationResult.inputQuery.errors).toEqual([]);
37+
expect(validationResult.inputFixture.errors).toEqual([]);
38+
expect(validationResult.outputFixture.errors).toEqual([]);
39+
40+
const runResult = await runFunction(fixture, functionRunnerPath, wasmPath, targetInputQueryPath, schemaPath);
41+
expect(runResult.error).toBeNull();
42+
expect(runResult.result.output).toEqual(fixture.expectedOutput);
43+
}, 10000);
44+
});
45+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"payload": {
3+
"export": "cart_validations_generate_run",
4+
"target": "cart.validations.generate.run",
5+
"input": {
6+
"cart": {
7+
"lines": [
8+
{
9+
"quantity": 1
10+
},
11+
{
12+
"quantity": 1
13+
},
14+
{
15+
"quantity": 1
16+
}
17+
]
18+
}
19+
},
20+
"output": {
21+
"operations": [
22+
{
23+
"validationAdd": {
24+
"errors": []
25+
}
26+
}
27+
]
28+
}
29+
}
30+
}

functions-cart-transform-js/package.json.liquid

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
"name": "{{handle}}",
33
"version": "0.0.1",
44
"license": "UNLICENSED",
5+
"type": "module",
56
"scripts": {
67
"shopify": "npm exec -- shopify",
78
"typegen": "npm exec -- shopify app function typegen",
89
"build": "npm exec -- shopify app function build",
910
"preview": "npm exec -- shopify app function run",
10-
"test": "vitest"
11+
"test": "vitest",
12+
"test:unit": "vitest run src/"
1113
},
1214
"codegen": {
1315
"schema": "schema.graphql",
@@ -28,6 +30,7 @@
2830
"@shopify/shopify_function": "2.0.0"
2931
},
3032
"devDependencies": {
31-
"vitest": "2.1.9"
33+
"@shopify/shopify-function-test-helpers": "~0.0.0",
34+
"vitest": "^3.2.4"
3235
}
3336
}

0 commit comments

Comments
 (0)