Skip to content

Commit dec22fc

Browse files
authored
update test example (#43)
1 parent 098a1e8 commit dec22fc

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

README.md

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,34 @@ For a full test suite that runs multiple fixtures using `getFunctionInfo`:
2525
```javascript
2626
import path from "path";
2727
import fs from "fs";
28+
import { describe, beforeAll, test, expect } from "vitest";
2829
import {
2930
buildFunction,
3031
getFunctionInfo,
31-
loadFixture,
32-
runFunction,
33-
validateTestAssets,
3432
loadSchema,
3533
loadInputQuery,
34+
loadFixture,
35+
validateTestAssets,
36+
runFunction
3637
} from "@shopify/shopify-function-test-helpers";
3738

38-
describe("Function Tests", () => {
39+
describe("Default Integration Test", () => {
3940
let schema;
4041
let functionDir;
41-
let functionInfo;
42+
let schemaPath;
43+
let targeting;
44+
let functionRunnerPath;
45+
let wasmPath;
4246

4347
beforeAll(async () => {
4448
functionDir = path.dirname(__dirname);
4549
await buildFunction(functionDir);
4650

47-
// Get function information from Shopify CLI
48-
functionInfo = await getFunctionInfo(functionDir);
51+
const functionInfo = await getFunctionInfo(functionDir);
52+
({ schemaPath, functionRunnerPath, wasmPath, targeting } = functionInfo);
4953

50-
// Load schema
51-
schema = await loadSchema(functionInfo.schemaPath);
52-
}, 20000);
54+
schema = await loadSchema(schemaPath);
55+
}, 45000);
5356

5457
const fixturesDir = path.join(__dirname, "fixtures");
5558
const fixtureFiles = fs
@@ -58,31 +61,27 @@ describe("Function Tests", () => {
5861
.map((file) => path.join(fixturesDir, file));
5962

6063
fixtureFiles.forEach((fixtureFile) => {
61-
test(\`runs \${path.basename(fixtureFile)}\`, async () => {
64+
test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => {
6265
const fixture = await loadFixture(fixtureFile);
63-
64-
// Get the correct input query for this fixture's target
65-
const targetInputQueryPath = functionInfo.targeting[fixture.target].inputQueryPath;
66+
const targetInputQueryPath = targeting[fixture.target].inputQueryPath;
6667
const inputQueryAST = await loadInputQuery(targetInputQueryPath);
6768

68-
// Validate test assets
6969
const validationResult = await validateTestAssets({
7070
schema,
7171
fixture,
72-
inputQueryAST,
72+
inputQueryAST
7373
});
7474

75-
expect(validationResult.inputQuery.errors).toHaveLength(0);
76-
expect(validationResult.inputFixture.errors).toHaveLength(0);
77-
expect(validationResult.outputFixture.errors).toHaveLength(0);
75+
expect(validationResult.inputQuery.errors).toEqual([]);
76+
expect(validationResult.inputFixture.errors).toEqual([]);
77+
expect(validationResult.outputFixture.errors).toEqual([]);
7878

79-
// Run the function
8079
const runResult = await runFunction(
8180
fixture,
82-
functionInfo.functionRunnerPath,
83-
functionInfo.wasmPath,
81+
functionRunnerPath,
82+
wasmPath,
8483
targetInputQueryPath,
85-
functionInfo.schemaPath
84+
schemaPath
8685
);
8786

8887
expect(runResult.error).toBeNull();

0 commit comments

Comments
 (0)