@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,148 +0,0 @@
|
|
|
1
|
-
import { vi, describe, beforeEach, afterEach, it, expect } from 'vitest';
|
|
2
|
-
import { mockAndCaptureOutput } from '@shopify/cli-kit/node/testing/output';
|
|
3
|
-
import { inTemporaryDirectory } from '@shopify/cli-kit/node/fs';
|
|
4
|
-
import { renderConfirmationPrompt } from '@shopify/cli-kit/node/ui';
|
|
5
|
-
import { getStorefrontEnvironments } from '../../../lib/graphql/admin/list-environments.js';
|
|
6
|
-
import { login } from '../../../lib/auth.js';
|
|
7
|
-
import { renderMissingLink, renderMissingStorefront } from '../../../lib/render-errors.js';
|
|
8
|
-
import { linkStorefront } from '../link.js';
|
|
9
|
-
import { runEnvList } from './list.js';
|
|
10
|
-
|
|
11
|
-
const SHOP = "my-shop";
|
|
12
|
-
vi.mock("@shopify/cli-kit/node/ui", async () => {
|
|
13
|
-
const original = await vi.importActual("@shopify/cli-kit/node/ui");
|
|
14
|
-
return {
|
|
15
|
-
...original,
|
|
16
|
-
renderConfirmationPrompt: vi.fn()
|
|
17
|
-
};
|
|
18
|
-
});
|
|
19
|
-
vi.mock("../link.js");
|
|
20
|
-
vi.mock("../../../lib/auth.js");
|
|
21
|
-
vi.mock("../../../lib/shopify-config.js");
|
|
22
|
-
vi.mock("../../../lib/render-errors.js");
|
|
23
|
-
vi.mock("../../../lib/graphql/admin/list-environments.js");
|
|
24
|
-
vi.mock("../../../lib/shell.js", () => ({ getCliCommand: () => "h2" }));
|
|
25
|
-
describe("listEnvironments", () => {
|
|
26
|
-
const ADMIN_SESSION = {
|
|
27
|
-
token: "abc123",
|
|
28
|
-
storeFqdn: SHOP
|
|
29
|
-
};
|
|
30
|
-
const SHOPIFY_CONFIG = {
|
|
31
|
-
shop: SHOP,
|
|
32
|
-
shopName: "My Shop",
|
|
33
|
-
email: "email",
|
|
34
|
-
storefront: {
|
|
35
|
-
id: "gid://shopify/HydrogenStorefront/1",
|
|
36
|
-
title: "Existing Link"
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
const PRODUCTION_ENVIRONMENT = {
|
|
40
|
-
id: "gid://shopify/HydrogenStorefrontEnvironment/1",
|
|
41
|
-
branch: "main",
|
|
42
|
-
type: "PRODUCTION",
|
|
43
|
-
name: "Production",
|
|
44
|
-
createdAt: "2023-02-16T22:35:42Z",
|
|
45
|
-
url: "https://oxygen-123.example.com"
|
|
46
|
-
};
|
|
47
|
-
const CUSTOM_ENVIRONMENT = {
|
|
48
|
-
id: "gid://shopify/HydrogenStorefrontEnvironment/3",
|
|
49
|
-
branch: "staging",
|
|
50
|
-
type: "CUSTOM",
|
|
51
|
-
name: "Staging",
|
|
52
|
-
createdAt: "2023-05-08T20:52:29Z",
|
|
53
|
-
url: "https://oxygen-456.example.com"
|
|
54
|
-
};
|
|
55
|
-
const PREVIEW_ENVIRONMENT = {
|
|
56
|
-
id: "gid://shopify/HydrogenStorefrontEnvironment/2",
|
|
57
|
-
branch: null,
|
|
58
|
-
type: "PREVIEW",
|
|
59
|
-
name: "Preview",
|
|
60
|
-
createdAt: "2023-02-16T22:35:42Z",
|
|
61
|
-
url: null
|
|
62
|
-
};
|
|
63
|
-
beforeEach(async () => {
|
|
64
|
-
vi.mocked(login).mockResolvedValue({
|
|
65
|
-
session: ADMIN_SESSION,
|
|
66
|
-
config: SHOPIFY_CONFIG
|
|
67
|
-
});
|
|
68
|
-
vi.mocked(getStorefrontEnvironments).mockResolvedValue({
|
|
69
|
-
id: "gid://shopify/HydrogenStorefront/1",
|
|
70
|
-
productionUrl: "https://example.com",
|
|
71
|
-
environments: [
|
|
72
|
-
PRODUCTION_ENVIRONMENT,
|
|
73
|
-
CUSTOM_ENVIRONMENT,
|
|
74
|
-
PREVIEW_ENVIRONMENT
|
|
75
|
-
]
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
afterEach(() => {
|
|
79
|
-
vi.resetAllMocks();
|
|
80
|
-
mockAndCaptureOutput().clear();
|
|
81
|
-
});
|
|
82
|
-
it("fetchs environment variables", async () => {
|
|
83
|
-
await inTemporaryDirectory(async (tmpDir) => {
|
|
84
|
-
await runEnvList({ path: tmpDir });
|
|
85
|
-
expect(getStorefrontEnvironments).toHaveBeenCalledWith(
|
|
86
|
-
ADMIN_SESSION,
|
|
87
|
-
SHOPIFY_CONFIG.storefront.id
|
|
88
|
-
);
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
it("lists the environments", async () => {
|
|
92
|
-
await inTemporaryDirectory(async (tmpDir) => {
|
|
93
|
-
const output = mockAndCaptureOutput();
|
|
94
|
-
await runEnvList({ path: tmpDir });
|
|
95
|
-
expect(output.info()).toMatch(
|
|
96
|
-
/Showing 3 environments for the Hydrogen storefront Existing Link/i
|
|
97
|
-
);
|
|
98
|
-
expect(output.info()).toMatch(/Production \(Branch: main\)/);
|
|
99
|
-
expect(output.info()).toMatch(/https:\/\/example\.com/);
|
|
100
|
-
expect(output.info()).toMatch(/Staging \(Branch: staging\)/);
|
|
101
|
-
expect(output.info()).toMatch(/https:\/\/oxygen-456\.example\.com/);
|
|
102
|
-
expect(output.info()).toMatch(/Preview/);
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
describe("when there is no linked storefront", () => {
|
|
106
|
-
beforeEach(() => {
|
|
107
|
-
vi.mocked(login).mockResolvedValue({
|
|
108
|
-
session: ADMIN_SESSION,
|
|
109
|
-
config: {
|
|
110
|
-
...SHOPIFY_CONFIG,
|
|
111
|
-
storefront: void 0
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
it("calls renderMissingLink", async () => {
|
|
116
|
-
await inTemporaryDirectory(async (tmpDir) => {
|
|
117
|
-
await runEnvList({ path: tmpDir });
|
|
118
|
-
expect(renderMissingLink).toHaveBeenCalledOnce();
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
it("prompts the user to create a link", async () => {
|
|
122
|
-
vi.mocked(renderConfirmationPrompt).mockResolvedValue(true);
|
|
123
|
-
await inTemporaryDirectory(async (tmpDir) => {
|
|
124
|
-
await runEnvList({ path: tmpDir });
|
|
125
|
-
expect(renderConfirmationPrompt).toHaveBeenCalledWith({
|
|
126
|
-
message: expect.arrayContaining([{ command: "h2 link" }])
|
|
127
|
-
});
|
|
128
|
-
expect(linkStorefront).toHaveBeenCalledWith(
|
|
129
|
-
tmpDir,
|
|
130
|
-
ADMIN_SESSION,
|
|
131
|
-
{ ...SHOPIFY_CONFIG, storefront: void 0 },
|
|
132
|
-
expect.anything()
|
|
133
|
-
);
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
describe("when there is no matching storefront in the shop", () => {
|
|
138
|
-
beforeEach(() => {
|
|
139
|
-
vi.mocked(getStorefrontEnvironments).mockResolvedValue(null);
|
|
140
|
-
});
|
|
141
|
-
it("calls renderMissingStorefront", async () => {
|
|
142
|
-
await inTemporaryDirectory(async (tmpDir) => {
|
|
143
|
-
await runEnvList({ path: tmpDir });
|
|
144
|
-
expect(renderMissingStorefront).toHaveBeenCalledOnce();
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
});
|
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import { vi, describe, beforeEach, afterEach, it, expect } from 'vitest';
|
|
2
|
-
import { mockAndCaptureOutput } from '@shopify/cli-kit/node/testing/output';
|
|
3
|
-
import { inTemporaryDirectory, fileExists, readFile, writeFile } from '@shopify/cli-kit/node/fs';
|
|
4
|
-
import { joinPath } from '@shopify/cli-kit/node/path';
|
|
5
|
-
import { renderConfirmationPrompt } from '@shopify/cli-kit/node/ui';
|
|
6
|
-
import { login } from '../../../lib/auth.js';
|
|
7
|
-
import { getStorefrontEnvVariables } from '../../../lib/graphql/admin/pull-variables.js';
|
|
8
|
-
import { runEnvPull } from './pull.js';
|
|
9
|
-
import { renderMissingLink, renderMissingStorefront } from '../../../lib/render-errors.js';
|
|
10
|
-
import { linkStorefront } from '../link.js';
|
|
11
|
-
|
|
12
|
-
vi.mock("@shopify/cli-kit/node/ui", async () => {
|
|
13
|
-
const original = await vi.importActual("@shopify/cli-kit/node/ui");
|
|
14
|
-
return {
|
|
15
|
-
...original,
|
|
16
|
-
renderConfirmationPrompt: vi.fn()
|
|
17
|
-
};
|
|
18
|
-
});
|
|
19
|
-
vi.mock("../link.js");
|
|
20
|
-
vi.mock("../../../lib/auth.js");
|
|
21
|
-
vi.mock("../../../lib/render-errors.js");
|
|
22
|
-
vi.mock("../../../lib/graphql/admin/pull-variables.js");
|
|
23
|
-
describe("pullVariables", () => {
|
|
24
|
-
const ADMIN_SESSION = {
|
|
25
|
-
token: "abc123",
|
|
26
|
-
storeFqdn: "my-shop"
|
|
27
|
-
};
|
|
28
|
-
const SHOPIFY_CONFIG = {
|
|
29
|
-
shop: "my-shop",
|
|
30
|
-
shopName: "My Shop",
|
|
31
|
-
email: "email",
|
|
32
|
-
storefront: {
|
|
33
|
-
id: "gid://shopify/HydrogenStorefront/2",
|
|
34
|
-
title: "Existing Link"
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
beforeEach(async () => {
|
|
38
|
-
vi.mocked(login).mockResolvedValue({
|
|
39
|
-
session: ADMIN_SESSION,
|
|
40
|
-
config: SHOPIFY_CONFIG
|
|
41
|
-
});
|
|
42
|
-
vi.mocked(getStorefrontEnvVariables).mockResolvedValue({
|
|
43
|
-
id: SHOPIFY_CONFIG.storefront.id,
|
|
44
|
-
environmentVariables: [
|
|
45
|
-
{
|
|
46
|
-
id: "gid://shopify/HydrogenStorefrontEnvironmentVariable/1",
|
|
47
|
-
key: "PUBLIC_API_TOKEN",
|
|
48
|
-
value: "abc123",
|
|
49
|
-
readOnly: true,
|
|
50
|
-
isSecret: false
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
id: "gid://shopify/HydrogenStorefrontEnvironmentVariable/2",
|
|
54
|
-
key: "PRIVATE_API_TOKEN",
|
|
55
|
-
value: "",
|
|
56
|
-
readOnly: true,
|
|
57
|
-
isSecret: true
|
|
58
|
-
}
|
|
59
|
-
]
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
afterEach(() => {
|
|
63
|
-
vi.resetAllMocks();
|
|
64
|
-
mockAndCaptureOutput().clear();
|
|
65
|
-
});
|
|
66
|
-
it("calls getStorefrontEnvVariables", async () => {
|
|
67
|
-
await inTemporaryDirectory(async (tmpDir) => {
|
|
68
|
-
await runEnvPull({ path: tmpDir, envBranch: "staging" });
|
|
69
|
-
expect(getStorefrontEnvVariables).toHaveBeenCalledWith(
|
|
70
|
-
ADMIN_SESSION,
|
|
71
|
-
SHOPIFY_CONFIG.storefront.id,
|
|
72
|
-
"staging"
|
|
73
|
-
);
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
it("writes environment variables to a .env file", async () => {
|
|
77
|
-
await inTemporaryDirectory(async (tmpDir) => {
|
|
78
|
-
const filePath = joinPath(tmpDir, ".env");
|
|
79
|
-
expect(await fileExists(filePath)).toBeFalsy();
|
|
80
|
-
await runEnvPull({ path: tmpDir });
|
|
81
|
-
expect(await readFile(filePath)).toStrictEqual(
|
|
82
|
-
'PUBLIC_API_TOKEN=abc123\nPRIVATE_API_TOKEN=""'
|
|
83
|
-
);
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
it("warns about secret environment variables", async () => {
|
|
87
|
-
await inTemporaryDirectory(async (tmpDir) => {
|
|
88
|
-
const outputMock = mockAndCaptureOutput();
|
|
89
|
-
await runEnvPull({ path: tmpDir });
|
|
90
|
-
expect(outputMock.warn()).toMatch(
|
|
91
|
-
/Existing Link contains environment variables marked as secret, so their/
|
|
92
|
-
);
|
|
93
|
-
expect(outputMock.warn()).toMatch(/values weren’t pulled./);
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
it("renders a success message", async () => {
|
|
97
|
-
await inTemporaryDirectory(async (tmpDir) => {
|
|
98
|
-
const outputMock = mockAndCaptureOutput();
|
|
99
|
-
await runEnvPull({ path: tmpDir });
|
|
100
|
-
expect(outputMock.info()).toMatch(
|
|
101
|
-
/Changes have been made to your \.env file/
|
|
102
|
-
);
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
describe("when environment variables are empty", () => {
|
|
106
|
-
beforeEach(() => {
|
|
107
|
-
vi.mocked(getStorefrontEnvVariables).mockResolvedValue({
|
|
108
|
-
id: "gid://shopify/HydrogenStorefront/1",
|
|
109
|
-
environmentVariables: []
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
it("renders a message", async () => {
|
|
113
|
-
await inTemporaryDirectory(async (tmpDir) => {
|
|
114
|
-
const outputMock = mockAndCaptureOutput();
|
|
115
|
-
await runEnvPull({ path: tmpDir });
|
|
116
|
-
expect(outputMock.info()).toMatch(/No environment variables found\./);
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
describe("when there is no linked storefront", () => {
|
|
121
|
-
beforeEach(async () => {
|
|
122
|
-
vi.mocked(login).mockResolvedValue({
|
|
123
|
-
session: ADMIN_SESSION,
|
|
124
|
-
config: {
|
|
125
|
-
...SHOPIFY_CONFIG,
|
|
126
|
-
storefront: void 0
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
it("calls renderMissingLink", async () => {
|
|
131
|
-
await inTemporaryDirectory(async (tmpDir) => {
|
|
132
|
-
await runEnvPull({ path: tmpDir });
|
|
133
|
-
expect(renderMissingLink).toHaveBeenCalledOnce();
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
it("prompts the user to create a link", async () => {
|
|
137
|
-
vi.mocked(renderConfirmationPrompt).mockResolvedValue(true);
|
|
138
|
-
await inTemporaryDirectory(async (tmpDir) => {
|
|
139
|
-
await runEnvPull({ path: tmpDir });
|
|
140
|
-
expect(renderConfirmationPrompt).toHaveBeenCalledWith({
|
|
141
|
-
message: expect.stringMatching(/Run .* link.*\?/i)
|
|
142
|
-
});
|
|
143
|
-
expect(linkStorefront).toHaveBeenCalledWith(
|
|
144
|
-
tmpDir,
|
|
145
|
-
ADMIN_SESSION,
|
|
146
|
-
{ ...SHOPIFY_CONFIG, storefront: void 0 },
|
|
147
|
-
expect.anything()
|
|
148
|
-
);
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
it("ends without requesting variables", async () => {
|
|
152
|
-
await inTemporaryDirectory(async (tmpDir) => {
|
|
153
|
-
await runEnvPull({ path: tmpDir });
|
|
154
|
-
expect(getStorefrontEnvVariables).not.toHaveBeenCalled();
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
describe("and the user does not create a new link", () => {
|
|
158
|
-
it("ends without requesting variables", async () => {
|
|
159
|
-
vi.mocked(renderConfirmationPrompt).mockResolvedValue(false);
|
|
160
|
-
await inTemporaryDirectory(async (tmpDir) => {
|
|
161
|
-
await runEnvPull({ path: tmpDir });
|
|
162
|
-
expect(getStorefrontEnvVariables).not.toHaveBeenCalled();
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
describe("when there is no matching storefront in the shop", () => {
|
|
168
|
-
beforeEach(() => {
|
|
169
|
-
vi.mocked(getStorefrontEnvVariables).mockResolvedValue(null);
|
|
170
|
-
});
|
|
171
|
-
it("renders missing storefronts message and ends", async () => {
|
|
172
|
-
await inTemporaryDirectory(async (tmpDir) => {
|
|
173
|
-
await runEnvPull({ path: tmpDir });
|
|
174
|
-
expect(renderMissingStorefront).toHaveBeenCalledOnce();
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
describe("when a .env file already exists", () => {
|
|
179
|
-
beforeEach(() => {
|
|
180
|
-
vi.mocked(renderConfirmationPrompt).mockResolvedValue(true);
|
|
181
|
-
});
|
|
182
|
-
it("prompts the user to confirm", async () => {
|
|
183
|
-
await inTemporaryDirectory(async (tmpDir) => {
|
|
184
|
-
const filePath = joinPath(tmpDir, ".env");
|
|
185
|
-
await writeFile(filePath, "EXISTING_TOKEN=1");
|
|
186
|
-
await runEnvPull({ path: tmpDir });
|
|
187
|
-
expect(renderConfirmationPrompt).toHaveBeenCalledWith({
|
|
188
|
-
confirmationMessage: `Yes, confirm changes`,
|
|
189
|
-
cancellationMessage: `No, make changes later`,
|
|
190
|
-
message: expect.stringMatching(
|
|
191
|
-
/We'll make the following changes to your \.env file:/
|
|
192
|
-
)
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
describe("and --force is enabled", () => {
|
|
197
|
-
it("does not prompt the user to confirm", async () => {
|
|
198
|
-
await inTemporaryDirectory(async (tmpDir) => {
|
|
199
|
-
const filePath = joinPath(tmpDir, ".env");
|
|
200
|
-
await writeFile(filePath, "EXISTING_TOKEN=1");
|
|
201
|
-
await runEnvPull({ path: tmpDir, force: true });
|
|
202
|
-
expect(renderConfirmationPrompt).not.toHaveBeenCalled();
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
});
|