Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/validate-js-functions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
- name: Generate types
run: yarn js-typegen
- name: Test
run: yarn js-test
run: yarn js-test:unit
2 changes: 1 addition & 1 deletion .github/workflows/validate-ts-functions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
- name: Generate types
run: yarn js-typegen
- name: Test
run: yarn js-test
run: yarn js-test:unit
7 changes: 5 additions & 2 deletions functions-cart-checkout-validation-js/package.json.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
"name": "{{handle}}",
"version": "0.0.1",
"license": "UNLICENSED",
"type": "module",
"scripts": {
"shopify": "npm exec -- shopify",
"typegen": "npm exec -- shopify app function typegen",
"build": "npm exec -- shopify app function build",
"preview": "npm exec -- shopify app function run",
"test": "vitest"
"test": "vitest",
"test:unit": "vitest run src/"
},
"codegen": {
"schema": "schema.graphql",
Expand All @@ -28,6 +30,7 @@
"@shopify/shopify_function": "2.0.0"
},
"devDependencies": {
"vitest": "2.1.9"
"@shopify/shopify-function-test-helpers": "^1.0.0",
"vitest": "^3.2.4"
}
}
45 changes: 45 additions & 0 deletions functions-cart-checkout-validation-js/tests/default.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import path from "path";
import fs from "fs";
import { describe, beforeAll, test, expect } from "vitest";
import { buildFunction, getFunctionInfo, loadSchema, loadInputQuery, loadFixture, validateTestAssets, runFunction } from "@shopify/shopify-function-test-helpers";

describe("Default Integration Test", () => {
let schema;
let functionDir;
let functionInfo;
let schemaPath;
let targeting;
let functionRunnerPath;
let wasmPath;

beforeAll(async () => {
functionDir = path.dirname(__dirname);
await buildFunction(functionDir);
functionInfo = await getFunctionInfo(functionDir);
({ schemaPath, functionRunnerPath, wasmPath, targeting } = functionInfo);
schema = await loadSchema(schemaPath);
}, 45000);

const fixturesDir = path.join(__dirname, "fixtures");
const fixtureFiles = fs
.readdirSync(fixturesDir)
.filter((file) => file.endsWith(".json"))
.map((file) => path.join(fixturesDir, file));

fixtureFiles.forEach((fixtureFile) => {
test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => {
const fixture = await loadFixture(fixtureFile);
const targetInputQueryPath = targeting[fixture.target].inputQueryPath;
const inputQueryAST = await loadInputQuery(targetInputQueryPath);

const validationResult = await validateTestAssets({ schema, fixture, inputQueryAST });
expect(validationResult.inputQuery.errors).toEqual([]);
expect(validationResult.inputFixture.errors).toEqual([]);
expect(validationResult.outputFixture.errors).toEqual([]);

const runResult = await runFunction(fixture, functionRunnerPath, wasmPath, targetInputQueryPath, schemaPath);
expect(runResult.error).toBeNull();
expect(runResult.result.output).toEqual(fixture.expectedOutput);
}, 10000);
});
});
30 changes: 30 additions & 0 deletions functions-cart-checkout-validation-js/tests/fixtures/log.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"payload": {
"export": "cart-validations-generate-run",
"target": "cart.validations.generate.run",
"input": {
"cart": {
"lines": [
{
"quantity": 1
},
{
"quantity": 1
},
{
"quantity": 1
}
]
}
},
"output": {
"operations": [
{
"validationAdd": {
"errors": []
}
}
]
}
}
}
1 change: 1 addition & 0 deletions functions-cart-checkout-validation-js/vitest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
13 changes: 13 additions & 0 deletions functions-cart-checkout-validation-rs/package.json.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "{{handle}}",
"version": "0.0.1",
"private": true,
"type": "module",
"scripts": {
"test": "vitest run"
},
"devDependencies": {
"@shopify/shopify-function-test-helpers": "^1.0.0",
"vitest": "^3.2.4"
}
}
45 changes: 45 additions & 0 deletions functions-cart-checkout-validation-rs/tests/default.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import path from "path";
import fs from "fs";
import { describe, beforeAll, test, expect } from "vitest";
import { buildFunction, getFunctionInfo, loadSchema, loadInputQuery, loadFixture, validateTestAssets, runFunction } from "@shopify/shopify-function-test-helpers";

describe("Default Integration Test", () => {
let schema;
let functionDir;
let functionInfo;
let schemaPath;
let targeting;
let functionRunnerPath;
let wasmPath;

beforeAll(async () => {
functionDir = path.dirname(__dirname);
await buildFunction(functionDir);
functionInfo = await getFunctionInfo(functionDir);
({ schemaPath, functionRunnerPath, wasmPath, targeting } = functionInfo);
schema = await loadSchema(schemaPath);
}, 45000);

const fixturesDir = path.join(__dirname, "fixtures");
const fixtureFiles = fs
.readdirSync(fixturesDir)
.filter((file) => file.endsWith(".json"))
.map((file) => path.join(fixturesDir, file));

fixtureFiles.forEach((fixtureFile) => {
test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => {
const fixture = await loadFixture(fixtureFile);
const targetInputQueryPath = targeting[fixture.target].inputQueryPath;
const inputQueryAST = await loadInputQuery(targetInputQueryPath);

const validationResult = await validateTestAssets({ schema, fixture, inputQueryAST });
expect(validationResult.inputQuery.errors).toEqual([]);
expect(validationResult.inputFixture.errors).toEqual([]);
expect(validationResult.outputFixture.errors).toEqual([]);

const runResult = await runFunction(fixture, functionRunnerPath, wasmPath, targetInputQueryPath, schemaPath);
expect(runResult.error).toBeNull();
expect(runResult.result.output).toEqual(fixture.expectedOutput);
}, 10000);
});
});
30 changes: 30 additions & 0 deletions functions-cart-checkout-validation-rs/tests/fixtures/log.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"payload": {
"export": "cart_validations_generate_run",
"target": "cart.validations.generate.run",
"input": {
"cart": {
"lines": [
{
"quantity": 1
},
{
"quantity": 1
},
{
"quantity": 1
}
]
}
},
"output": {
"operations": [
{
"validationAdd": {
"errors": []
}
}
]
}
}
}
7 changes: 5 additions & 2 deletions functions-cart-transform-js/package.json.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
"name": "{{handle}}",
"version": "0.0.1",
"license": "UNLICENSED",
"type": "module",
"scripts": {
"shopify": "npm exec -- shopify",
"typegen": "npm exec -- shopify app function typegen",
"build": "npm exec -- shopify app function build",
"preview": "npm exec -- shopify app function run",
"test": "vitest"
"test": "vitest",
"test:unit": "vitest run src/"
},
"codegen": {
"schema": "schema.graphql",
Expand All @@ -28,6 +30,7 @@
"@shopify/shopify_function": "2.0.0"
},
"devDependencies": {
"vitest": "2.1.9"
"@shopify/shopify-function-test-helpers": "^1.0.0",
"vitest": "^3.2.4"
}
}
45 changes: 45 additions & 0 deletions functions-cart-transform-js/tests/default.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import path from "path";
import fs from "fs";
import { describe, beforeAll, test, expect } from "vitest";
import { buildFunction, getFunctionInfo, loadSchema, loadInputQuery, loadFixture, validateTestAssets, runFunction } from "@shopify/shopify-function-test-helpers";

describe("Default Integration Test", () => {
let schema;
let functionDir;
let functionInfo;
let schemaPath;
let targeting;
let functionRunnerPath;
let wasmPath;

beforeAll(async () => {
functionDir = path.dirname(__dirname);
await buildFunction(functionDir);
functionInfo = await getFunctionInfo(functionDir);
({ schemaPath, functionRunnerPath, wasmPath, targeting } = functionInfo);
schema = await loadSchema(schemaPath);
}, 45000);

const fixturesDir = path.join(__dirname, "fixtures");
const fixtureFiles = fs
.readdirSync(fixturesDir)
.filter((file) => file.endsWith(".json"))
.map((file) => path.join(fixturesDir, file));

fixtureFiles.forEach((fixtureFile) => {
test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => {
const fixture = await loadFixture(fixtureFile);
const targetInputQueryPath = targeting[fixture.target].inputQueryPath;
const inputQueryAST = await loadInputQuery(targetInputQueryPath);

const validationResult = await validateTestAssets({ schema, fixture, inputQueryAST });
expect(validationResult.inputQuery.errors).toEqual([]);
expect(validationResult.inputFixture.errors).toEqual([]);
expect(validationResult.outputFixture.errors).toEqual([]);

const runResult = await runFunction(fixture, functionRunnerPath, wasmPath, targetInputQueryPath, schemaPath);
expect(runResult.error).toBeNull();
expect(runResult.result.output).toEqual(fixture.expectedOutput);
}, 10000);
});
});
19 changes: 19 additions & 0 deletions functions-cart-transform-js/tests/fixtures/log.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"payload": {
"export": "cart-transform-run",
"target": "cart.transform.run",
"input": {
"cart": {
"lines": [
{
"id": "gid://shopify/CartLine/1",
"quantity": 1
}
]
}
},
"output": {
"operations": []
}
}
}
1 change: 1 addition & 0 deletions functions-cart-transform-js/vitest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
13 changes: 13 additions & 0 deletions functions-cart-transform-rs/package.json.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "{{handle}}",
"version": "0.0.1",
"private": true,
"type": "module",
"scripts": {
"test": "vitest run"
},
"devDependencies": {
"@shopify/shopify-function-test-helpers": "^1.0.0",
"vitest": "^3.2.4"
}
}
45 changes: 45 additions & 0 deletions functions-cart-transform-rs/tests/default.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import path from "path";
import fs from "fs";
import { describe, beforeAll, test, expect } from "vitest";
import { buildFunction, getFunctionInfo, loadSchema, loadInputQuery, loadFixture, validateTestAssets, runFunction } from "@shopify/shopify-function-test-helpers";

describe("Default Integration Test", () => {
let schema;
let functionDir;
let functionInfo;
let schemaPath;
let targeting;
let functionRunnerPath;
let wasmPath;

beforeAll(async () => {
functionDir = path.dirname(__dirname);
await buildFunction(functionDir);
functionInfo = await getFunctionInfo(functionDir);
({ schemaPath, functionRunnerPath, wasmPath, targeting } = functionInfo);
schema = await loadSchema(schemaPath);
}, 45000);

const fixturesDir = path.join(__dirname, "fixtures");
const fixtureFiles = fs
.readdirSync(fixturesDir)
.filter((file) => file.endsWith(".json"))
.map((file) => path.join(fixturesDir, file));

fixtureFiles.forEach((fixtureFile) => {
test(`runs ${path.relative(fixturesDir, fixtureFile)}`, async () => {
const fixture = await loadFixture(fixtureFile);
const targetInputQueryPath = targeting[fixture.target].inputQueryPath;
const inputQueryAST = await loadInputQuery(targetInputQueryPath);

const validationResult = await validateTestAssets({ schema, fixture, inputQueryAST });
expect(validationResult.inputQuery.errors).toEqual([]);
expect(validationResult.inputFixture.errors).toEqual([]);
expect(validationResult.outputFixture.errors).toEqual([]);

const runResult = await runFunction(fixture, functionRunnerPath, wasmPath, targetInputQueryPath, schemaPath);
expect(runResult.error).toBeNull();
expect(runResult.result.output).toEqual(fixture.expectedOutput);
}, 10000);
});
});
19 changes: 19 additions & 0 deletions functions-cart-transform-rs/tests/fixtures/log.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"payload": {
"export": "cart_transform_run",
"target": "cart.transform.run",
"input": {
"cart": {
"lines": [
{
"id": "gid://shopify/CartLine/1",
"quantity": 1
}
]
}
},
"output": {
"operations": []
}
}
}
Loading