Skip to content

Commit c9897ed

Browse files
committed
Create mocks for the entire checkout extension API
1 parent a54bddd commit c9897ed

21 files changed

Lines changed: 3953 additions & 20 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Environment Configuration
2+
.env
3+
.env.*
4+
5+
# Dependency directory
6+
node_modules
7+
8+
# Test coverage directory
9+
coverage
10+
11+
# Ignore Apple macOS Desktop Services Store
12+
.DS_Store
13+
14+
# Logs
15+
logs
16+
*.log
17+
18+
# extensions build output
19+
extensions/*/build
20+
extensions/*/dist
21+
22+
# lock files
23+
24+
25+
26+
27+
# Ignore shopify files created during app dev
28+
.shopify/*
29+
.shopify.lock
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const fs = require("node:fs");
2+
3+
function getConfig() {
4+
const config = {
5+
projects: {},
6+
};
7+
8+
let extensions = [];
9+
try {
10+
extensions = fs.readdirSync("./extensions");
11+
} catch {
12+
// ignore if no extensions
13+
}
14+
15+
for (const entry of extensions) {
16+
const extensionPath = `./extensions/${entry}`;
17+
const schema = `${extensionPath}/schema.graphql`;
18+
if (!fs.existsSync(schema)) {
19+
continue;
20+
}
21+
config.projects[entry] = {
22+
schema,
23+
documents: [`${extensionPath}/**/*.graphql`],
24+
};
25+
}
26+
27+
return config;
28+
}
29+
30+
module.exports = getConfig();
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
This extension was created with:
2+
3+
```
4+
shopify app init --name checkout-basic-testing-example
5+
cd checkout-basic-testing-example
6+
shopify app generate extension
7+
# I chose 'Checkout UI'
8+
```
9+
10+
See it in action:
11+
12+
```
13+
npm install
14+
npm run typecheck
15+
npm test
16+
```

examples/testing/checkout-basic-testing-example/extensions/.gitkeep

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Instructions are in [app's README](../../)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"welcome": "Welcome to the {{target}} extension!",
3+
"iWouldLikeAFreeGiftWithMyOrder": "I would like to receive a free gift with my order",
4+
"addAFreeGiftToMyOrder": "Add a free gift to my order",
5+
"attributeChangesAreNotSupported": "Attribute changes are not supported in this checkout"
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"welcome": "Bienvenue dans l'extension {{target}}!",
3+
"iWouldLikeAFreeGiftWithMyOrder": "Je souhaite recevoir un cadeau gratuit avec ma commande",
4+
"addAFreeGiftToMyOrder": "Ajouter un cadeau gratuit à ma commande",
5+
"attributeChangesAreNotSupported": "Les modifications d'attribut ne sont pas prises en charge dans cette commande"
6+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "checkout-basic-testing-example",
3+
"private": true,
4+
"version": "1.0.0",
5+
"license": "UNLICENSED",
6+
"dependencies": {
7+
"preact": "^10.10.x",
8+
"@preact/signals": "^2.3.x",
9+
"@shopify/ui-extensions": "2026.1.x"
10+
}
11+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import '@shopify/ui-extensions';
2+
/// <reference path="../../node_modules/@shopify/ui-extensions/build/ts/surfaces/checkout/targets/purchase.checkout.block.render.d.ts" />
3+
4+
//@ts-ignore
5+
declare module './src/Checkout.jsx' {
6+
const shopify: import('@shopify/ui-extensions/purchase.checkout.block.render').Api;
7+
const globalThis: { shopify: typeof shopify };
8+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Learn more about configuring your checkout UI extension:
2+
# https://shopify.dev/docs/api/checkout-ui-extensions/latest/configuration
3+
4+
# The version of APIs your extension will receive. Learn more:
5+
# https://shopify.dev/docs/api/usage/versioning
6+
api_version = "2026-01"
7+
8+
[[extensions]]
9+
name = "checkout-basic-testing-example"
10+
handle = "checkout-basic-testing-example"
11+
type = "ui_extension"
12+
uid = "4aeff854-b3f4-8d93-1398-b0fa7256818fc0502641"
13+
14+
# Controls where in Shopify your extension will be injected,
15+
# and the file that contains your extension’s source code. Learn more:
16+
# https://shopify.dev/docs/api/checkout-ui-extensions/latest/extension-targets-overview
17+
18+
[[extensions.targeting]]
19+
module = "./src/Checkout.jsx"
20+
target = "purchase.checkout.block.render"
21+
22+
[extensions.capabilities]
23+
# Gives your extension access to directly query Shopify’s storefront API.
24+
# https://shopify.dev/docs/api/checkout-ui-extensions/latest/configuration#api-access
25+
api_access = true
26+
27+
# Gives your extension access to make external network calls, using the
28+
# JavaScript `fetch()` API. Learn more:
29+
# https://shopify.dev/docs/api/checkout-ui-extensions/latest/configuration#network-access
30+
# network_access = true
31+
32+
# Loads metafields on checkout resources, including the cart,
33+
# products, customers, and more. Learn more:
34+
# https://shopify.dev/docs/api/checkout-ui-extensions/latest/configuration#metafields
35+
36+
# [[extensions.metafields]]
37+
# namespace = "my_namespace"
38+
# key = "my_key"
39+
# [[extensions.metafields]]
40+
# namespace = "my_namespace"
41+
# key = "my_other_key"
42+
43+
# Defines settings that will be collected from merchants installing
44+
# your extension. Learn more:
45+
# https://shopify.dev/docs/api/checkout-ui-extensions/latest/configuration#settings-definition
46+
47+
# [extensions.settings]
48+
# [[extensions.settings.fields]]
49+
# key = "banner_title"
50+
# type = "single_line_text_field"
51+
# name = "Banner title"
52+
# description = "Enter a title for the banner"

0 commit comments

Comments
 (0)