@shopify/cli-hydrogen 7.1.2 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/hydrogen/build-vite.js +19 -10
- package/dist/commands/hydrogen/build.js +10 -2
- package/dist/commands/hydrogen/check.js +1 -0
- package/dist/commands/hydrogen/codegen.js +1 -0
- package/dist/commands/hydrogen/customer-account/push.js +170 -0
- package/dist/commands/hydrogen/debug/cpu.js +3 -0
- package/dist/commands/hydrogen/deploy.js +121 -36
- package/dist/commands/hydrogen/dev-vite.js +128 -59
- package/dist/commands/hydrogen/dev.js +108 -51
- package/dist/commands/hydrogen/env/list.js +7 -8
- package/dist/commands/hydrogen/env/pull.js +17 -1
- package/dist/commands/hydrogen/env/{push__unstable.js → push.js} +23 -50
- package/dist/commands/hydrogen/generate/route.js +1 -0
- package/dist/commands/hydrogen/init.js +45 -17
- package/dist/commands/hydrogen/link.js +20 -4
- package/dist/commands/hydrogen/list.js +1 -0
- package/dist/commands/hydrogen/login.js +1 -0
- package/dist/commands/hydrogen/logout.js +1 -0
- package/dist/commands/hydrogen/preview.js +31 -16
- package/dist/commands/hydrogen/setup/css.js +8 -1
- package/dist/commands/hydrogen/setup/markets.js +1 -0
- package/dist/commands/hydrogen/setup/vite.js +244 -138
- package/dist/commands/hydrogen/setup.js +21 -22
- package/dist/commands/hydrogen/shortcut.js +10 -0
- package/dist/commands/hydrogen/unlink.js +1 -0
- package/dist/commands/hydrogen/upgrade.js +2 -1
- package/dist/generator-templates/assets/vite/package.json +3 -4
- package/dist/generator-templates/assets/vite/vite.config.js +10 -2
- package/dist/generator-templates/starter/CHANGELOG.md +89 -0
- package/dist/generator-templates/starter/README.md +3 -44
- package/dist/generator-templates/starter/app/graphql/customer-account/CustomerDetailsQuery.ts +1 -0
- package/dist/generator-templates/starter/app/lib/fragments.ts +2 -0
- package/dist/generator-templates/starter/app/root.tsx +2 -5
- package/dist/generator-templates/starter/app/routes/account.orders._index.tsx +1 -1
- package/dist/generator-templates/starter/app/routes/account.tsx +1 -1
- package/dist/generator-templates/starter/app/routes/collections.all.tsx +160 -0
- package/dist/generator-templates/starter/app/routes/products.$handle.tsx +1 -2
- package/dist/generator-templates/starter/customer-accountapi.generated.d.ts +6 -3
- package/dist/generator-templates/starter/{remix.env.d.ts → env.d.ts} +8 -2
- package/dist/generator-templates/starter/package.json +14 -9
- package/dist/generator-templates/starter/server.ts +2 -1
- package/dist/generator-templates/starter/storefrontapi.generated.d.ts +59 -3
- package/dist/generator-templates/starter/vite.config.ts +21 -0
- package/dist/{commands/hydrogen/init.d.ts → init.d.ts} +11 -3
- package/dist/lib/check-lockfile.js +12 -18
- package/dist/lib/codegen.js +37 -13
- package/dist/lib/common.js +50 -0
- package/dist/lib/cpu-profiler.js +4 -1
- package/dist/lib/dev-shared.js +97 -0
- package/dist/lib/environment-variables.js +51 -30
- package/dist/lib/file.js +8 -1
- package/dist/lib/flags.js +37 -16
- package/dist/lib/graphql/admin/customer-application-update.js +29 -0
- package/dist/lib/graphql/admin/get-oxygen-data.js +1 -0
- package/dist/lib/graphql/admin/list-environments.js +1 -0
- package/dist/lib/graphql/admin/pull-variables.js +4 -4
- package/dist/lib/graphql/admin/test-helper.js +37 -0
- package/dist/lib/log.js +86 -13
- package/dist/lib/mini-oxygen/common.js +19 -33
- package/dist/lib/mini-oxygen/index.js +6 -2
- package/dist/lib/mini-oxygen/node.js +43 -31
- package/dist/lib/mini-oxygen/workerd.js +72 -165
- package/dist/lib/missing-routes.js +1 -1
- package/dist/lib/onboarding/common.js +82 -70
- package/dist/lib/onboarding/local.js +19 -9
- package/dist/lib/onboarding/remote.js +35 -30
- package/dist/lib/package-managers.js +24 -0
- package/dist/lib/remix-config.js +17 -1
- package/dist/lib/request-events.js +6 -1
- package/dist/lib/setups/i18n/replacers.js +9 -6
- package/dist/lib/setups/routes/generate.js +1 -0
- package/dist/lib/shell.js +2 -1
- package/dist/lib/shopify-config.js +19 -1
- package/dist/lib/template-diff.js +36 -15
- package/dist/lib/template-downloader.js +35 -5
- package/dist/lib/transpile/morph/typedefs.js +5 -2
- package/dist/lib/transpile/project.js +8 -4
- package/dist/lib/tunneling.js +44 -0
- package/dist/lib/virtual-routes.js +1 -1
- package/dist/lib/vite-config.js +39 -9
- package/oclif.manifest.json +711 -498
- package/package.json +32 -24
- package/dist/commands/hydrogen/deploy.test.js +0 -553
- package/dist/commands/hydrogen/env/list.test.js +0 -148
- package/dist/commands/hydrogen/env/pull.test.js +0 -207
- package/dist/commands/hydrogen/env/push__unstable.test.js +0 -383
- package/dist/commands/hydrogen/generate/route.test.js +0 -43
- package/dist/commands/hydrogen/init.test.js +0 -641
- package/dist/commands/hydrogen/link.test.js +0 -187
- package/dist/commands/hydrogen/list.test.js +0 -111
- package/dist/commands/hydrogen/setup.test.js +0 -61
- package/dist/commands/hydrogen/shortcut.test.js +0 -30
- package/dist/commands/hydrogen/unlink.test.js +0 -36
- package/dist/commands/hydrogen/upgrade.test.js +0 -786
- package/dist/generator-templates/starter/remix.config.js +0 -24
- package/dist/lib/auth.test.js +0 -157
- package/dist/lib/check-lockfile.test.js +0 -81
- package/dist/lib/check-version.test.js +0 -86
- package/dist/lib/environment-variables.test.js +0 -149
- package/dist/lib/file.test.js +0 -68
- package/dist/lib/flags.test.js +0 -43
- package/dist/lib/get-oxygen-deployment-data.test.js +0 -120
- package/dist/lib/gid.test.js +0 -15
- package/dist/lib/graphql/admin/client.test.js +0 -76
- package/dist/lib/graphql/admin/create-storefront.test.js +0 -64
- package/dist/lib/graphql/admin/link-storefront.test.js +0 -38
- package/dist/lib/graphql/admin/list-environments.test.js +0 -44
- package/dist/lib/graphql/admin/list-storefronts.test.js +0 -44
- package/dist/lib/graphql/admin/pull-variables.test.js +0 -43
- package/dist/lib/graphql/business-platform/user-account.test.js +0 -80
- package/dist/lib/log.test.js +0 -92
- package/dist/lib/mini-oxygen/assets.js +0 -134
- package/dist/lib/mini-oxygen/mini-oxygen.test.js +0 -214
- package/dist/lib/mini-oxygen/workerd-inspector-logs.js +0 -227
- package/dist/lib/mini-oxygen/workerd-inspector-proxy.js +0 -200
- package/dist/lib/mini-oxygen/workerd-inspector.js +0 -219
- package/dist/lib/missing-routes.test.js +0 -45
- package/dist/lib/remix-version-check.test.js +0 -39
- package/dist/lib/remix-version-interop.test.js +0 -13
- package/dist/lib/setups/i18n/domains.test.js +0 -39
- package/dist/lib/setups/i18n/replacers.test.js +0 -261
- package/dist/lib/setups/i18n/subdomains.test.js +0 -39
- package/dist/lib/setups/i18n/subfolders.test.js +0 -39
- package/dist/lib/setups/routes/generate.test.js +0 -296
- package/dist/lib/shell.test.js +0 -111
- package/dist/lib/shopify-config.test.js +0 -199
- package/dist/lib/string.test.js +0 -16
- package/dist/lib/virtual-routes.test.js +0 -49
- package/dist/lib/vite/hydrogen-middleware.js +0 -82
- package/dist/lib/vite/mini-oxygen.js +0 -152
- package/dist/lib/vite/plugins.d.ts +0 -27
- package/dist/lib/vite/plugins.js +0 -139
- package/dist/lib/vite/shared.js +0 -10
- package/dist/lib/vite/utils.js +0 -55
- package/dist/lib/vite/worker-entry.js +0 -1518
- /package/dist/generator-templates/starter/{.eslintrc.js → .eslintrc.cjs} +0 -0
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { vi, describe, beforeEach, afterEach, it, expect } from 'vitest';
|
|
2
|
-
import { renderConfirmationPrompt } from '@shopify/cli-kit/node/ui';
|
|
3
|
-
import { getOxygenDeploymentData } from './get-oxygen-deployment-data.js';
|
|
4
|
-
import { login } from './auth.js';
|
|
5
|
-
import { getConfig } from './shopify-config.js';
|
|
6
|
-
import { renderMissingLink, renderMissingStorefront } from './render-errors.js';
|
|
7
|
-
import { linkStorefront } from '../commands/hydrogen/link.js';
|
|
8
|
-
import { getOxygenData } from './graphql/admin/get-oxygen-data.js';
|
|
9
|
-
|
|
10
|
-
vi.mock("@shopify/cli-kit/node/ui", async () => {
|
|
11
|
-
const original = await vi.importActual("@shopify/cli-kit/node/ui");
|
|
12
|
-
return {
|
|
13
|
-
...original,
|
|
14
|
-
renderConfirmationPrompt: vi.fn()
|
|
15
|
-
};
|
|
16
|
-
});
|
|
17
|
-
vi.mock("./auth.js");
|
|
18
|
-
vi.mock("./admin-session.js");
|
|
19
|
-
vi.mock("./shopify-config.js");
|
|
20
|
-
vi.mock("./render-errors.js");
|
|
21
|
-
vi.mock("../commands/hydrogen/link.js");
|
|
22
|
-
vi.mock("./graphql/admin/get-oxygen-data.js");
|
|
23
|
-
describe("getOxygenDeploymentData", () => {
|
|
24
|
-
const OXYGEN_DEPLOYMENT_TOKEN = "a-lovely-token";
|
|
25
|
-
const environments = [
|
|
26
|
-
{
|
|
27
|
-
name: "production",
|
|
28
|
-
branch: "main",
|
|
29
|
-
type: "PRODUCTION"
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
name: "preview",
|
|
33
|
-
branch: null,
|
|
34
|
-
type: "PREVIEW"
|
|
35
|
-
}
|
|
36
|
-
];
|
|
37
|
-
beforeEach(() => {
|
|
38
|
-
vi.mocked(login).mockResolvedValue({
|
|
39
|
-
session: {
|
|
40
|
-
token: "123",
|
|
41
|
-
storeFqdn: "www.snowdevil.com"
|
|
42
|
-
},
|
|
43
|
-
config: {
|
|
44
|
-
shop: "snowdevil.myshopify.com",
|
|
45
|
-
shopName: "Snowdevil",
|
|
46
|
-
email: "merchant@shop.com",
|
|
47
|
-
storefront: {
|
|
48
|
-
id: "1",
|
|
49
|
-
title: "Snowboards"
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
vi.mocked(getConfig).mockResolvedValue({
|
|
54
|
-
storefront: { id: "storefront-id", title: "Existing Link" }
|
|
55
|
-
});
|
|
56
|
-
vi.mocked(getOxygenData).mockResolvedValue({
|
|
57
|
-
storefront: {
|
|
58
|
-
oxygenDeploymentToken: OXYGEN_DEPLOYMENT_TOKEN,
|
|
59
|
-
environments
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
afterEach(() => {
|
|
64
|
-
vi.resetAllMocks();
|
|
65
|
-
});
|
|
66
|
-
it("returns the oxygen deployment token and environments", async () => {
|
|
67
|
-
const data = await getOxygenDeploymentData({ root: "test-root" });
|
|
68
|
-
expect(data?.oxygenDeploymentToken).toBe(OXYGEN_DEPLOYMENT_TOKEN);
|
|
69
|
-
expect(data?.environments).toEqual(environments);
|
|
70
|
-
});
|
|
71
|
-
describe("when there is no linked storefront", () => {
|
|
72
|
-
beforeEach(() => {
|
|
73
|
-
vi.mocked(login).mockResolvedValue({
|
|
74
|
-
session: {
|
|
75
|
-
token: "123",
|
|
76
|
-
storeFqdn: "www.snowdevil.com"
|
|
77
|
-
},
|
|
78
|
-
config: {
|
|
79
|
-
shop: "snowdevil.myshopify.com",
|
|
80
|
-
shopName: "Snowdevil",
|
|
81
|
-
email: "merchant@shop.com",
|
|
82
|
-
storefront: void 0
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
it("calls renderMissingLink and prompts the user to create a link", async () => {
|
|
87
|
-
vi.mocked(renderConfirmationPrompt).mockResolvedValue(true);
|
|
88
|
-
await getOxygenDeploymentData({ root: "test-root" });
|
|
89
|
-
expect(renderMissingLink).toHaveBeenCalled();
|
|
90
|
-
expect(renderConfirmationPrompt).toHaveBeenCalled();
|
|
91
|
-
expect(linkStorefront).toHaveBeenCalled();
|
|
92
|
-
});
|
|
93
|
-
it("returns nothing if the user does not create a new link", async () => {
|
|
94
|
-
vi.mocked(renderConfirmationPrompt).mockResolvedValue(false);
|
|
95
|
-
const token = await getOxygenDeploymentData({ root: "test-root" });
|
|
96
|
-
expect(token).toEqual(void 0);
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
describe("when there is no matching storefront in the shop", () => {
|
|
100
|
-
beforeEach(() => {
|
|
101
|
-
vi.mocked(getOxygenData).mockResolvedValue({ storefront: null });
|
|
102
|
-
});
|
|
103
|
-
it("calls renderMissingStorefront and returns nothing", async () => {
|
|
104
|
-
const token = await getOxygenDeploymentData({ root: "test-root" });
|
|
105
|
-
expect(renderMissingStorefront).toHaveBeenCalled();
|
|
106
|
-
expect(token).toEqual(void 0);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
describe("when the storefront does not have an oxygen deployment token", () => {
|
|
110
|
-
beforeEach(() => {
|
|
111
|
-
vi.mocked(getOxygenData).mockResolvedValue({
|
|
112
|
-
storefront: { oxygenDeploymentToken: "", environments: [] }
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
it("returns nothing", async () => {
|
|
116
|
-
const data = await getOxygenDeploymentData({ root: "test-root" });
|
|
117
|
-
expect(data).toEqual(void 0);
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
});
|
package/dist/lib/gid.test.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { AbortError } from '@shopify/cli-kit/node/error';
|
|
3
|
-
import { parseGid } from './gid.js';
|
|
4
|
-
|
|
5
|
-
describe("parseGid", () => {
|
|
6
|
-
it("returns an ID", () => {
|
|
7
|
-
const id = parseGid("gid://shopify/HydrogenStorefront/324");
|
|
8
|
-
expect(id).toStrictEqual("324");
|
|
9
|
-
});
|
|
10
|
-
describe("when the global ID is invalid", () => {
|
|
11
|
-
it("throws an error", () => {
|
|
12
|
-
expect(() => parseGid("321asd")).toThrow(AbortError);
|
|
13
|
-
});
|
|
14
|
-
});
|
|
15
|
-
});
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { AbortError } from '@shopify/cli-kit/node/error';
|
|
2
|
-
import { vi, describe, it, expect } from 'vitest';
|
|
3
|
-
import { adminRequest } from './client.js';
|
|
4
|
-
import { graphqlRequest } from '@shopify/cli-kit/node/api/graphql';
|
|
5
|
-
|
|
6
|
-
vi.mock("@shopify/cli-kit/node/api/graphql");
|
|
7
|
-
describe("adminRequest", () => {
|
|
8
|
-
it("sends a query to the Admin API and returns the successful response", async () => {
|
|
9
|
-
const fakeResponse = {
|
|
10
|
-
test: "test"
|
|
11
|
-
};
|
|
12
|
-
vi.mocked(graphqlRequest).mockResolvedValue(fakeResponse);
|
|
13
|
-
const response = await adminRequest("", {
|
|
14
|
-
token: "",
|
|
15
|
-
storeFqdn: ""
|
|
16
|
-
});
|
|
17
|
-
expect(response).toMatchObject(fakeResponse);
|
|
18
|
-
});
|
|
19
|
-
describe("when there is an unknown error response", () => {
|
|
20
|
-
it("passes along the error message", async () => {
|
|
21
|
-
const fakeGraphqlError = {
|
|
22
|
-
errors: [
|
|
23
|
-
{
|
|
24
|
-
message: "test error"
|
|
25
|
-
}
|
|
26
|
-
]
|
|
27
|
-
};
|
|
28
|
-
vi.mocked(graphqlRequest).mockRejectedValue(fakeGraphqlError);
|
|
29
|
-
const response = adminRequest("", {
|
|
30
|
-
token: "",
|
|
31
|
-
storeFqdn: ""
|
|
32
|
-
});
|
|
33
|
-
await expect(response).rejects.toMatchObject(fakeGraphqlError);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
describe("when the app isn't installed", () => {
|
|
37
|
-
it("throws an AbortError", async () => {
|
|
38
|
-
const fakeGraphqlError = {
|
|
39
|
-
errors: [
|
|
40
|
-
{
|
|
41
|
-
message: "app is not installed"
|
|
42
|
-
}
|
|
43
|
-
]
|
|
44
|
-
};
|
|
45
|
-
vi.mocked(graphqlRequest).mockRejectedValue(fakeGraphqlError);
|
|
46
|
-
const response = adminRequest("", {
|
|
47
|
-
token: "",
|
|
48
|
-
storeFqdn: ""
|
|
49
|
-
});
|
|
50
|
-
await expect(response).rejects.toThrowError(AbortError);
|
|
51
|
-
await expect(response).rejects.toMatch(
|
|
52
|
-
/Hydrogen sales channel isn\'t installed/
|
|
53
|
-
);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
describe("when the user doesn't have access to hydrogenStorefrontCreate", () => {
|
|
57
|
-
it("throws an AbortError", async () => {
|
|
58
|
-
const fakeGraphqlError = {
|
|
59
|
-
errors: [
|
|
60
|
-
{
|
|
61
|
-
message: "Access denied for hydrogenStorefrontCreate field"
|
|
62
|
-
}
|
|
63
|
-
]
|
|
64
|
-
};
|
|
65
|
-
vi.mocked(graphqlRequest).mockRejectedValue(fakeGraphqlError);
|
|
66
|
-
const response = adminRequest("", {
|
|
67
|
-
token: "",
|
|
68
|
-
storeFqdn: ""
|
|
69
|
-
});
|
|
70
|
-
await expect(response).rejects.toThrowError(AbortError);
|
|
71
|
-
await expect(response).rejects.toMatch(
|
|
72
|
-
/Couldn\'t connect storefront to Shopify/
|
|
73
|
-
);
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
});
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { vi, describe, afterEach, it, expect } from 'vitest';
|
|
2
|
-
import { adminRequest } from './client.js';
|
|
3
|
-
import { createStorefront } from './create-storefront.js';
|
|
4
|
-
|
|
5
|
-
vi.mock("./client.js");
|
|
6
|
-
describe("createStorefront", () => {
|
|
7
|
-
const ADMIN_SESSION = {
|
|
8
|
-
token: "abc123",
|
|
9
|
-
storeFqdn: "my-shop.myshopify.com"
|
|
10
|
-
};
|
|
11
|
-
afterEach(() => {
|
|
12
|
-
vi.resetAllMocks();
|
|
13
|
-
});
|
|
14
|
-
it("sends a mutation to create a new storefront and returns it", async () => {
|
|
15
|
-
vi.mocked(adminRequest).mockImplementation(
|
|
16
|
-
(_, __, variables) => Promise.resolve({
|
|
17
|
-
hydrogenStorefrontCreate: {
|
|
18
|
-
hydrogenStorefront: {
|
|
19
|
-
id: "gid://shopify/HydrogenStorefront/123",
|
|
20
|
-
title: variables?.title,
|
|
21
|
-
productionUrl: "https://..."
|
|
22
|
-
},
|
|
23
|
-
userErrors: [],
|
|
24
|
-
jobId: "123"
|
|
25
|
-
}
|
|
26
|
-
})
|
|
27
|
-
);
|
|
28
|
-
const TITLE = "title";
|
|
29
|
-
await expect(createStorefront(ADMIN_SESSION, TITLE)).resolves.toStrictEqual(
|
|
30
|
-
{
|
|
31
|
-
jobId: "123",
|
|
32
|
-
storefront: {
|
|
33
|
-
id: "gid://shopify/HydrogenStorefront/123",
|
|
34
|
-
title: TITLE,
|
|
35
|
-
productionUrl: "https://..."
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
);
|
|
39
|
-
expect(adminRequest).toHaveBeenCalledWith(
|
|
40
|
-
expect.stringMatching(/^#graphql.+mutation.+hydrogenStorefrontCreate\(/s),
|
|
41
|
-
ADMIN_SESSION,
|
|
42
|
-
{ title: TITLE }
|
|
43
|
-
);
|
|
44
|
-
});
|
|
45
|
-
it("throws formatted GraphQL errors", async () => {
|
|
46
|
-
const error = "Title is invalid";
|
|
47
|
-
vi.mocked(adminRequest).mockResolvedValue({
|
|
48
|
-
hydrogenStorefrontCreate: {
|
|
49
|
-
jobId: void 0,
|
|
50
|
-
hydrogenStorefront: void 0,
|
|
51
|
-
userErrors: [
|
|
52
|
-
{
|
|
53
|
-
code: "INVALID",
|
|
54
|
-
field: ["title"],
|
|
55
|
-
message: error
|
|
56
|
-
}
|
|
57
|
-
]
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
await expect(createStorefront(ADMIN_SESSION, "title")).rejects.toThrow(
|
|
61
|
-
error
|
|
62
|
-
);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { vi, describe, afterEach, it, expect } from 'vitest';
|
|
2
|
-
import { adminRequest } from './client.js';
|
|
3
|
-
import { getStorefronts } from './link-storefront.js';
|
|
4
|
-
|
|
5
|
-
vi.mock("./client.js");
|
|
6
|
-
describe("getStorefrontsWithDeployment", () => {
|
|
7
|
-
const ADMIN_SESSION = {
|
|
8
|
-
token: "abc123",
|
|
9
|
-
storeFqdn: "my-shop.myshopify.com"
|
|
10
|
-
};
|
|
11
|
-
afterEach(() => {
|
|
12
|
-
vi.resetAllMocks();
|
|
13
|
-
});
|
|
14
|
-
it("calls the graphql client and returns Hydrogen storefronts", async () => {
|
|
15
|
-
const mockedResponse = {
|
|
16
|
-
hydrogenStorefronts: [
|
|
17
|
-
{
|
|
18
|
-
id: "gid://shopify/HydrogenStorefront/123",
|
|
19
|
-
title: "title",
|
|
20
|
-
productionUrl: "https://..."
|
|
21
|
-
}
|
|
22
|
-
]
|
|
23
|
-
};
|
|
24
|
-
vi.mocked(adminRequest).mockResolvedValue(
|
|
25
|
-
mockedResponse
|
|
26
|
-
);
|
|
27
|
-
await expect(getStorefronts(ADMIN_SESSION)).resolves.toStrictEqual([
|
|
28
|
-
{
|
|
29
|
-
...mockedResponse.hydrogenStorefronts[0],
|
|
30
|
-
parsedId: "123"
|
|
31
|
-
}
|
|
32
|
-
]);
|
|
33
|
-
expect(adminRequest).toHaveBeenCalledWith(
|
|
34
|
-
expect.stringMatching(/^#graphql.+query.+hydrogenStorefronts\s*{/s),
|
|
35
|
-
ADMIN_SESSION
|
|
36
|
-
);
|
|
37
|
-
});
|
|
38
|
-
});
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { vi, describe, afterEach, it, expect } from 'vitest';
|
|
2
|
-
import { adminRequest } from './client.js';
|
|
3
|
-
import { getStorefrontEnvironments } from './list-environments.js';
|
|
4
|
-
|
|
5
|
-
vi.mock("./client.js");
|
|
6
|
-
describe("getStorefrontEnvironments", () => {
|
|
7
|
-
const ADMIN_SESSION = {
|
|
8
|
-
token: "abc123",
|
|
9
|
-
storeFqdn: "my-shop.myshopify.com"
|
|
10
|
-
};
|
|
11
|
-
afterEach(() => {
|
|
12
|
-
vi.resetAllMocks();
|
|
13
|
-
});
|
|
14
|
-
it("calls the graphql client and returns Hydrogen storefronts", async () => {
|
|
15
|
-
const mockedResponse = {
|
|
16
|
-
hydrogenStorefront: {
|
|
17
|
-
id: "gid://shopify/HydrogenStorefront/123",
|
|
18
|
-
productionUrl: "https://...",
|
|
19
|
-
environments: [
|
|
20
|
-
{
|
|
21
|
-
createdAt: "2021-01-01T00:00:00Z",
|
|
22
|
-
id: "e123",
|
|
23
|
-
name: "Staging",
|
|
24
|
-
type: "CUSTOM",
|
|
25
|
-
branch: "staging",
|
|
26
|
-
url: "https://..."
|
|
27
|
-
}
|
|
28
|
-
]
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
vi.mocked(adminRequest).mockResolvedValue(
|
|
32
|
-
mockedResponse
|
|
33
|
-
);
|
|
34
|
-
const id = "123";
|
|
35
|
-
await expect(
|
|
36
|
-
getStorefrontEnvironments(ADMIN_SESSION, id)
|
|
37
|
-
).resolves.toStrictEqual(mockedResponse.hydrogenStorefront);
|
|
38
|
-
expect(adminRequest).toHaveBeenCalledWith(
|
|
39
|
-
expect.stringMatching(/^#graphql.+query.+hydrogenStorefront\(/s),
|
|
40
|
-
ADMIN_SESSION,
|
|
41
|
-
{ id }
|
|
42
|
-
);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { vi, describe, afterEach, it, expect } from 'vitest';
|
|
2
|
-
import { adminRequest } from './client.js';
|
|
3
|
-
import { getStorefrontsWithDeployment } from './list-storefronts.js';
|
|
4
|
-
|
|
5
|
-
vi.mock("./client.js");
|
|
6
|
-
describe("getStorefrontsWithDeployment", () => {
|
|
7
|
-
const ADMIN_SESSION = {
|
|
8
|
-
token: "abc123",
|
|
9
|
-
storeFqdn: "my-shop.myshopify.com"
|
|
10
|
-
};
|
|
11
|
-
afterEach(() => {
|
|
12
|
-
vi.resetAllMocks();
|
|
13
|
-
});
|
|
14
|
-
it("calls the graphql client and returns Hydrogen storefronts", async () => {
|
|
15
|
-
const mockedResponse = {
|
|
16
|
-
hydrogenStorefronts: [
|
|
17
|
-
{
|
|
18
|
-
id: "gid://shopify/HydrogenStorefront/123",
|
|
19
|
-
title: "title",
|
|
20
|
-
currentProductionDeployment: {
|
|
21
|
-
id: "d123",
|
|
22
|
-
createdAt: "2021-01-01T00:00:00Z",
|
|
23
|
-
commitMessage: null
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
]
|
|
27
|
-
};
|
|
28
|
-
vi.mocked(adminRequest).mockResolvedValue(
|
|
29
|
-
mockedResponse
|
|
30
|
-
);
|
|
31
|
-
await expect(
|
|
32
|
-
getStorefrontsWithDeployment(ADMIN_SESSION)
|
|
33
|
-
).resolves.toStrictEqual([
|
|
34
|
-
{
|
|
35
|
-
...mockedResponse.hydrogenStorefronts[0],
|
|
36
|
-
parsedId: "123"
|
|
37
|
-
}
|
|
38
|
-
]);
|
|
39
|
-
expect(adminRequest).toHaveBeenCalledWith(
|
|
40
|
-
expect.stringMatching(/^#graphql.+query.+hydrogenStorefronts\s*{/s),
|
|
41
|
-
ADMIN_SESSION
|
|
42
|
-
);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { vi, describe, afterEach, it, expect } from 'vitest';
|
|
2
|
-
import { adminRequest } from './client.js';
|
|
3
|
-
import { getStorefrontEnvVariables } from './pull-variables.js';
|
|
4
|
-
|
|
5
|
-
vi.mock("./client.js");
|
|
6
|
-
describe("getStorefrontEnvVariables", () => {
|
|
7
|
-
const ADMIN_SESSION = {
|
|
8
|
-
token: "abc123",
|
|
9
|
-
storeFqdn: "my-shop.myshopify.com"
|
|
10
|
-
};
|
|
11
|
-
afterEach(() => {
|
|
12
|
-
vi.resetAllMocks();
|
|
13
|
-
});
|
|
14
|
-
it("calls the graphql client and returns Hydrogen storefronts", async () => {
|
|
15
|
-
const mockedResponse = {
|
|
16
|
-
hydrogenStorefront: {
|
|
17
|
-
id: "123",
|
|
18
|
-
environmentVariables: [
|
|
19
|
-
{
|
|
20
|
-
id: "123",
|
|
21
|
-
isSecret: false,
|
|
22
|
-
readOnly: false,
|
|
23
|
-
key: "key",
|
|
24
|
-
value: "value"
|
|
25
|
-
}
|
|
26
|
-
]
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
vi.mocked(adminRequest).mockResolvedValue(
|
|
30
|
-
mockedResponse
|
|
31
|
-
);
|
|
32
|
-
const id = "123";
|
|
33
|
-
const branch = "staging";
|
|
34
|
-
await expect(
|
|
35
|
-
getStorefrontEnvVariables(ADMIN_SESSION, id, branch)
|
|
36
|
-
).resolves.toStrictEqual(mockedResponse.hydrogenStorefront);
|
|
37
|
-
expect(adminRequest).toHaveBeenCalledWith(
|
|
38
|
-
expect.stringMatching(/^#graphql.+query.+hydrogenStorefront\(/s),
|
|
39
|
-
ADMIN_SESSION,
|
|
40
|
-
{ id, branch }
|
|
41
|
-
);
|
|
42
|
-
});
|
|
43
|
-
});
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { vi, describe, afterEach, it, expect } from 'vitest';
|
|
2
|
-
import { businessPlatformRequest } from '@shopify/cli-kit/node/api/business-platform';
|
|
3
|
-
import { getUserAccount } from './user-account.js';
|
|
4
|
-
|
|
5
|
-
vi.mock("@shopify/cli-kit/node/api/business-platform");
|
|
6
|
-
describe("getUserAccount", () => {
|
|
7
|
-
afterEach(() => {
|
|
8
|
-
vi.resetAllMocks();
|
|
9
|
-
});
|
|
10
|
-
it("fetches the current user account and merges destinations", async () => {
|
|
11
|
-
vi.mocked(businessPlatformRequest).mockResolvedValue({
|
|
12
|
-
currentUserAccount: {
|
|
13
|
-
email: "email",
|
|
14
|
-
organizations: {
|
|
15
|
-
edges: [
|
|
16
|
-
{
|
|
17
|
-
node: {
|
|
18
|
-
id: "gid://shopify/Organization/123",
|
|
19
|
-
name: "name",
|
|
20
|
-
categories: [
|
|
21
|
-
{
|
|
22
|
-
destinations: {
|
|
23
|
-
edges: [
|
|
24
|
-
{
|
|
25
|
-
node: {
|
|
26
|
-
name: "n1",
|
|
27
|
-
webUrl: "w1",
|
|
28
|
-
status: "ACTIVE"
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
],
|
|
32
|
-
pageInfo: {}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
]
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
],
|
|
39
|
-
pageInfo: {}
|
|
40
|
-
},
|
|
41
|
-
orphanDestinations: {
|
|
42
|
-
categories: [
|
|
43
|
-
{
|
|
44
|
-
destinations: {
|
|
45
|
-
edges: [
|
|
46
|
-
{
|
|
47
|
-
node: {
|
|
48
|
-
name: "n2",
|
|
49
|
-
webUrl: "w2",
|
|
50
|
-
status: "NOPE"
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
node: {
|
|
55
|
-
name: "n3",
|
|
56
|
-
webUrl: "w3",
|
|
57
|
-
status: "ACTIVE"
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
],
|
|
61
|
-
pageInfo: {}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
]
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
await expect(getUserAccount("123")).resolves.toStrictEqual({
|
|
69
|
-
email: "email",
|
|
70
|
-
activeShops: [
|
|
71
|
-
{ name: "n1", fqdn: "w1" },
|
|
72
|
-
{ name: "n3", fqdn: "w3" }
|
|
73
|
-
]
|
|
74
|
-
});
|
|
75
|
-
expect(businessPlatformRequest).toHaveBeenCalledWith(
|
|
76
|
-
expect.stringMatching(/^#graphql.+query.+currentUserAccount\s*{/s),
|
|
77
|
-
"123"
|
|
78
|
-
);
|
|
79
|
-
});
|
|
80
|
-
});
|
package/dist/lib/log.test.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { fileURLToPath } from 'node:url';
|
|
2
|
-
import { describe, beforeEach, afterAll, it, expect } from 'vitest';
|
|
3
|
-
import { mockAndCaptureOutput } from '@shopify/cli-kit/node/testing/output';
|
|
4
|
-
import { resetAllLogs, enhanceH2Logs } from './log.js';
|
|
5
|
-
|
|
6
|
-
describe("log replacer", () => {
|
|
7
|
-
describe("enhanceH2Logs", () => {
|
|
8
|
-
const host = "http://localhost:3000";
|
|
9
|
-
const rootDirectory = fileURLToPath(import.meta.url);
|
|
10
|
-
const outputMock = mockAndCaptureOutput();
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
resetAllLogs();
|
|
13
|
-
outputMock.clear();
|
|
14
|
-
});
|
|
15
|
-
afterAll(() => {
|
|
16
|
-
resetAllLogs();
|
|
17
|
-
outputMock.clear();
|
|
18
|
-
});
|
|
19
|
-
describe("enhances h2:info pattern", () => {
|
|
20
|
-
it("renders in an info banner", () => {
|
|
21
|
-
enhanceH2Logs({ host, rootDirectory });
|
|
22
|
-
console.warn("[h2:info:storefront.query] Tip");
|
|
23
|
-
const message = outputMock.info();
|
|
24
|
-
expect(message).not.toMatch("h2");
|
|
25
|
-
expect(message).toMatch("info");
|
|
26
|
-
expect(message).toMatch("In Hydrogen's `storefront.query`");
|
|
27
|
-
expect(message).toMatch("Tip");
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
describe("enhances h2:warn pattern", () => {
|
|
31
|
-
it("renders in a warning banner", () => {
|
|
32
|
-
enhanceH2Logs({ host, rootDirectory });
|
|
33
|
-
console.warn("[h2:warn:storefront.query] Wrong query 1");
|
|
34
|
-
const warning = outputMock.warn();
|
|
35
|
-
expect(warning).not.toMatch("h2");
|
|
36
|
-
expect(warning).toMatch("warning");
|
|
37
|
-
expect(warning).toMatch("In Hydrogen's `storefront.query`");
|
|
38
|
-
expect(warning).toMatch("Wrong query");
|
|
39
|
-
});
|
|
40
|
-
it("shows links from the last line as a list", () => {
|
|
41
|
-
enhanceH2Logs({ host, rootDirectory });
|
|
42
|
-
console.warn(
|
|
43
|
-
"[h2:warn:storefront.query] Wrong query.\nhttps://docs.com/something"
|
|
44
|
-
);
|
|
45
|
-
const warning = outputMock.warn();
|
|
46
|
-
expect(warning).toMatch(
|
|
47
|
-
/\s+Reference:?\s+.+?\s+https?:\/\/docs\.com\/something\s/is
|
|
48
|
-
);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
describe("enhances h2:error pattern", () => {
|
|
52
|
-
it("renders in an error banner", () => {
|
|
53
|
-
enhanceH2Logs({ host, rootDirectory });
|
|
54
|
-
console.error(new Error("[h2:error:storefront.query] Wrong query 2"));
|
|
55
|
-
const error = outputMock.error();
|
|
56
|
-
expect(error.split("stack trace:")[0]).not.toMatch("h2");
|
|
57
|
-
expect(error).toMatch("error");
|
|
58
|
-
expect(error).toMatch("In Hydrogen's `storefront.query`");
|
|
59
|
-
expect(error).toMatch("Wrong query");
|
|
60
|
-
});
|
|
61
|
-
it("shows a GraphiQL link when the error is related to a GraphQL query", () => {
|
|
62
|
-
enhanceH2Logs({ host, rootDirectory });
|
|
63
|
-
console.error(
|
|
64
|
-
new Error("[h2:error:storefront.query] Wrong query 3", {
|
|
65
|
-
cause: {
|
|
66
|
-
graphql: { query: "query test {}", variables: '{"var1": true}' }
|
|
67
|
-
}
|
|
68
|
-
})
|
|
69
|
-
);
|
|
70
|
-
const error = outputMock.error();
|
|
71
|
-
expect(error).toMatch("GraphiQL");
|
|
72
|
-
expect((error.match(/\s+GraphiQL\s+\(\s+([^\)]+)\s+\)/) ?? [])[1]).toMatchInlineSnapshot(`
|
|
73
|
-
"http://localhost:3000/grap \u2502
|
|
74
|
-
\u2502 hiql?query=query%20test%20%7B%7D&variables=%7B%22var1%22%3A%20true%7D"
|
|
75
|
-
`);
|
|
76
|
-
});
|
|
77
|
-
it("trims stack traces when the error is related to a GraphQL query", () => {
|
|
78
|
-
enhanceH2Logs({ host, rootDirectory });
|
|
79
|
-
console.error(
|
|
80
|
-
new Error("[h2:error:storefront.query] Wrong query 4", {
|
|
81
|
-
cause: { graphql: { query: "query test {}" } }
|
|
82
|
-
})
|
|
83
|
-
);
|
|
84
|
-
const error = outputMock.error();
|
|
85
|
-
const stack = error.split("stack trace:")[1] ?? "";
|
|
86
|
-
const shortenedAppDir = rootDirectory.split("/cli/").pop();
|
|
87
|
-
expect(stack).toMatch(shortenedAppDir);
|
|
88
|
-
expect(stack).not.toMatch("node_modules");
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
});
|