@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,383 +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, writeFile } from '@shopify/cli-kit/node/fs';
|
|
4
|
-
import { joinPath } from '@shopify/cli-kit/node/path';
|
|
5
|
-
import { renderConfirmationPrompt, renderSelectPrompt } 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 { getStorefrontEnvironments } from '../../../lib/graphql/admin/list-environments.js';
|
|
9
|
-
import { pushStorefrontEnvVariables } from '../../../lib/graphql/admin/push-variables.js';
|
|
10
|
-
import { runEnvPush } from './push__unstable.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
|
-
renderSelectPrompt: vi.fn()
|
|
18
|
-
};
|
|
19
|
-
});
|
|
20
|
-
vi.mock("../link.js");
|
|
21
|
-
vi.mock("../../../lib/auth.js");
|
|
22
|
-
vi.mock("../../../lib/render-errors.js");
|
|
23
|
-
vi.mock("../../../lib/graphql/admin/pull-variables.js");
|
|
24
|
-
vi.mock("../../../lib/graphql/admin/list-environments.js");
|
|
25
|
-
vi.mock("../../../lib/graphql/admin/push-variables.js");
|
|
26
|
-
const ADMIN_SESSION = {
|
|
27
|
-
token: "abc123",
|
|
28
|
-
storeFqdn: "my-shop"
|
|
29
|
-
};
|
|
30
|
-
const SHOPIFY_CONFIG = {
|
|
31
|
-
shop: "my-shop",
|
|
32
|
-
shopName: "My Shop",
|
|
33
|
-
email: "email",
|
|
34
|
-
storefront: {
|
|
35
|
-
id: "gid://shopify/HydrogenStorefront/2",
|
|
36
|
-
title: "Existing Link"
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
const PRODUCTION_ENV = {
|
|
40
|
-
id: "gid://shopify/HydrogenStorefrontEnvironment/1",
|
|
41
|
-
createdAt: "2024-01-01",
|
|
42
|
-
branch: "main",
|
|
43
|
-
name: "Production",
|
|
44
|
-
type: "PRODUCTION",
|
|
45
|
-
url: "production.com"
|
|
46
|
-
};
|
|
47
|
-
const PREVIEW_ENV = {
|
|
48
|
-
id: "gid://shopify/HydrogenStorefrontEnvironment/2",
|
|
49
|
-
createdAt: "2024-01-01",
|
|
50
|
-
branch: null,
|
|
51
|
-
name: "Preview",
|
|
52
|
-
type: "PREVIEW",
|
|
53
|
-
url: null
|
|
54
|
-
};
|
|
55
|
-
const CUSTOM_ENV = {
|
|
56
|
-
id: "gid://shopify/HydrogenStorefrontEnvironment/3",
|
|
57
|
-
createdAt: "2024-01-01",
|
|
58
|
-
branch: "staging",
|
|
59
|
-
name: "Staging",
|
|
60
|
-
type: "CUSTOM",
|
|
61
|
-
url: "custom.com"
|
|
62
|
-
};
|
|
63
|
-
const outputMock = mockAndCaptureOutput();
|
|
64
|
-
const processExit = vi.spyOn(process, "exit");
|
|
65
|
-
describe("pushVariables", () => {
|
|
66
|
-
beforeEach(async () => {
|
|
67
|
-
processExit.mockImplementation(() => {
|
|
68
|
-
throw "mockExit";
|
|
69
|
-
});
|
|
70
|
-
vi.mocked(login).mockResolvedValue({
|
|
71
|
-
session: ADMIN_SESSION,
|
|
72
|
-
config: SHOPIFY_CONFIG
|
|
73
|
-
});
|
|
74
|
-
vi.mocked(getStorefrontEnvVariables).mockResolvedValue({
|
|
75
|
-
id: SHOPIFY_CONFIG.storefront.id,
|
|
76
|
-
environmentVariables: [
|
|
77
|
-
{
|
|
78
|
-
id: "gid://shopify/HydrogenStorefrontEnvironmentVariable/1",
|
|
79
|
-
key: "PUBLIC_API_TOKEN",
|
|
80
|
-
value: "abc123",
|
|
81
|
-
readOnly: true,
|
|
82
|
-
isSecret: false
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
id: "gid://shopify/HydrogenStorefrontEnvironmentVariable/2",
|
|
86
|
-
key: "PRIVATE_API_TOKEN",
|
|
87
|
-
value: "",
|
|
88
|
-
readOnly: true,
|
|
89
|
-
isSecret: true
|
|
90
|
-
}
|
|
91
|
-
]
|
|
92
|
-
});
|
|
93
|
-
vi.mocked(getStorefrontEnvironments).mockResolvedValue({
|
|
94
|
-
id: SHOPIFY_CONFIG.storefront.id,
|
|
95
|
-
productionUrl: "prod.com",
|
|
96
|
-
environments: [PRODUCTION_ENV, PREVIEW_ENV, CUSTOM_ENV]
|
|
97
|
-
});
|
|
98
|
-
vi.mocked(pushStorefrontEnvVariables).mockResolvedValue({
|
|
99
|
-
userErrors: []
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
afterEach(() => {
|
|
103
|
-
outputMock.clear();
|
|
104
|
-
vi.clearAllMocks();
|
|
105
|
-
vi.resetAllMocks();
|
|
106
|
-
});
|
|
107
|
-
it("calls getStorefrontEnvironments", async () => {
|
|
108
|
-
vi.mocked(renderConfirmationPrompt).mockResolvedValue(true);
|
|
109
|
-
await inTemporaryDirectory(async (tmpDir) => {
|
|
110
|
-
const filePath = joinPath(tmpDir, ".env");
|
|
111
|
-
await writeFile(filePath, "EXISTING_TOKEN=1\nSECOND_TOKEN=2");
|
|
112
|
-
await expect(
|
|
113
|
-
runEnvPush({ path: tmpDir, env: "Preview" })
|
|
114
|
-
).resolves.not.toThrow();
|
|
115
|
-
expect(getStorefrontEnvironments).toHaveBeenCalledWith(
|
|
116
|
-
ADMIN_SESSION,
|
|
117
|
-
SHOPIFY_CONFIG.storefront.id
|
|
118
|
-
);
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
it("errors if no environments data", async () => {
|
|
122
|
-
vi.mocked(getStorefrontEnvironments).mockResolvedValue({
|
|
123
|
-
id: SHOPIFY_CONFIG.storefront.id,
|
|
124
|
-
productionUrl: "prod.com",
|
|
125
|
-
environments: []
|
|
126
|
-
});
|
|
127
|
-
await inTemporaryDirectory(async (tmpDir) => {
|
|
128
|
-
const filePath = joinPath(tmpDir, ".env");
|
|
129
|
-
await writeFile(filePath, "EXISTING_TOKEN=1\nSECOND_TOKEN=2");
|
|
130
|
-
await expect(
|
|
131
|
-
runEnvPush({ path: tmpDir, env: "Preview" })
|
|
132
|
-
).rejects.toThrowError("No environments found");
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
it("prompts the user to select an environment", async () => {
|
|
136
|
-
vi.mocked(renderSelectPrompt).mockResolvedValue(PREVIEW_ENV.id);
|
|
137
|
-
await inTemporaryDirectory(async (tmpDir) => {
|
|
138
|
-
const filePath = joinPath(tmpDir, ".env");
|
|
139
|
-
await writeFile(filePath, "EXISTING_TOKEN=1\nSECOND_TOKEN=2");
|
|
140
|
-
await expect(runEnvPush({ path: tmpDir })).resolves.not.toThrow();
|
|
141
|
-
expect(renderSelectPrompt).toHaveBeenCalledWith({
|
|
142
|
-
message: "Select a set of environment variables to overwrite:",
|
|
143
|
-
choices: [
|
|
144
|
-
expect.objectContaining({ label: expect.stringContaining("Preview") }),
|
|
145
|
-
expect.objectContaining({ label: expect.stringContaining("Staging") }),
|
|
146
|
-
expect.objectContaining({
|
|
147
|
-
label: expect.stringContaining("Production")
|
|
148
|
-
})
|
|
149
|
-
]
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
describe("when an environment is passed", () => {
|
|
154
|
-
it("errors when the environment does not match graphql", async () => {
|
|
155
|
-
await inTemporaryDirectory(async (tmpDir) => {
|
|
156
|
-
const filePath = joinPath(tmpDir, ".env");
|
|
157
|
-
await writeFile(filePath, "EXISTING_TOKEN=1\nSECOND_TOKEN=2");
|
|
158
|
-
await expect(
|
|
159
|
-
runEnvPush({ path: tmpDir, env: "Something random" })
|
|
160
|
-
).rejects.toThrowError("Environment not found");
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
it("prompts the user if there are multiple matches", async () => {
|
|
164
|
-
vi.mocked(renderSelectPrompt).mockResolvedValue(PREVIEW_ENV.id);
|
|
165
|
-
vi.mocked(getStorefrontEnvironments).mockResolvedValue({
|
|
166
|
-
id: SHOPIFY_CONFIG.storefront.id,
|
|
167
|
-
productionUrl: "prod.com",
|
|
168
|
-
environments: [
|
|
169
|
-
PRODUCTION_ENV,
|
|
170
|
-
PREVIEW_ENV,
|
|
171
|
-
{ ...CUSTOM_ENV, name: "Preview" }
|
|
172
|
-
]
|
|
173
|
-
});
|
|
174
|
-
await inTemporaryDirectory(async (tmpDir) => {
|
|
175
|
-
const filePath = joinPath(tmpDir, ".env");
|
|
176
|
-
await writeFile(filePath, "EXISTING_TOKEN=1\nSECOND_TOKEN=2");
|
|
177
|
-
await expect(
|
|
178
|
-
runEnvPush({ path: tmpDir, env: "Preview" })
|
|
179
|
-
).resolves.not.toThrow();
|
|
180
|
-
expect(renderSelectPrompt).toHaveBeenCalledWith({
|
|
181
|
-
message: "There were multiple environments found with the name Preview:",
|
|
182
|
-
choices: expect.any(Array)
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
it("exits if variables are identical", async () => {
|
|
188
|
-
vi.mocked(getStorefrontEnvVariables).mockResolvedValue({
|
|
189
|
-
id: SHOPIFY_CONFIG.storefront.id,
|
|
190
|
-
environmentVariables: [
|
|
191
|
-
{
|
|
192
|
-
id: "1",
|
|
193
|
-
key: "EXISTING_TOKEN",
|
|
194
|
-
value: "1",
|
|
195
|
-
isSecret: false,
|
|
196
|
-
readOnly: false
|
|
197
|
-
},
|
|
198
|
-
{
|
|
199
|
-
id: "2",
|
|
200
|
-
key: "SECOND_TOKEN",
|
|
201
|
-
value: "2",
|
|
202
|
-
isSecret: false,
|
|
203
|
-
readOnly: false
|
|
204
|
-
}
|
|
205
|
-
]
|
|
206
|
-
});
|
|
207
|
-
await inTemporaryDirectory(async (tmpDir) => {
|
|
208
|
-
const filePath = joinPath(tmpDir, ".env");
|
|
209
|
-
await writeFile(filePath, "EXISTING_TOKEN=1\nSECOND_TOKEN=2");
|
|
210
|
-
await expect(
|
|
211
|
-
runEnvPush({ path: tmpDir, env: "Preview" })
|
|
212
|
-
).resolves.not.toThrow();
|
|
213
|
-
expect(outputMock.info()).toMatch(
|
|
214
|
-
/No changes to your environment variables/
|
|
215
|
-
);
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
it("renders a diff when a variable is updated", async () => {
|
|
219
|
-
vi.mocked(renderConfirmationPrompt).mockResolvedValue(true);
|
|
220
|
-
vi.mocked(getStorefrontEnvVariables).mockResolvedValue({
|
|
221
|
-
id: SHOPIFY_CONFIG.storefront.id,
|
|
222
|
-
environmentVariables: [
|
|
223
|
-
{
|
|
224
|
-
id: "1",
|
|
225
|
-
key: "EXISTING_TOKEN",
|
|
226
|
-
value: "1",
|
|
227
|
-
isSecret: false,
|
|
228
|
-
readOnly: false
|
|
229
|
-
},
|
|
230
|
-
{
|
|
231
|
-
id: "2",
|
|
232
|
-
key: "SECOND_TOKEN",
|
|
233
|
-
value: "updated value",
|
|
234
|
-
isSecret: false,
|
|
235
|
-
readOnly: false
|
|
236
|
-
}
|
|
237
|
-
]
|
|
238
|
-
});
|
|
239
|
-
await inTemporaryDirectory(async (tmpDir) => {
|
|
240
|
-
const filePath = joinPath(tmpDir, ".env");
|
|
241
|
-
await writeFile(filePath, "EXISTING_TOKEN=1\nSECOND_TOKEN=2");
|
|
242
|
-
await expect(
|
|
243
|
-
runEnvPush({ path: tmpDir, env: "Preview" })
|
|
244
|
-
).resolves.not.toThrow();
|
|
245
|
-
expect(renderConfirmationPrompt).toHaveBeenCalled();
|
|
246
|
-
});
|
|
247
|
-
});
|
|
248
|
-
it("ignores comparison against secrets", async () => {
|
|
249
|
-
vi.mocked(renderConfirmationPrompt).mockResolvedValue(true);
|
|
250
|
-
vi.mocked(getStorefrontEnvVariables).mockResolvedValue({
|
|
251
|
-
id: SHOPIFY_CONFIG.storefront.id,
|
|
252
|
-
environmentVariables: [
|
|
253
|
-
{
|
|
254
|
-
id: "1",
|
|
255
|
-
key: "EXISTING_TOKEN",
|
|
256
|
-
value: "1",
|
|
257
|
-
isSecret: false,
|
|
258
|
-
readOnly: false
|
|
259
|
-
},
|
|
260
|
-
{
|
|
261
|
-
id: "2",
|
|
262
|
-
key: "SECOND_TOKEN",
|
|
263
|
-
value: "updated value",
|
|
264
|
-
isSecret: true,
|
|
265
|
-
readOnly: false
|
|
266
|
-
}
|
|
267
|
-
]
|
|
268
|
-
});
|
|
269
|
-
await inTemporaryDirectory(async (tmpDir) => {
|
|
270
|
-
const filePath = joinPath(tmpDir, ".env");
|
|
271
|
-
await writeFile(filePath, "EXISTING_TOKEN=1\nSECOND_TOKEN=2");
|
|
272
|
-
await expect(
|
|
273
|
-
runEnvPush({ path: tmpDir, env: "Preview" })
|
|
274
|
-
).resolves.not.toThrow();
|
|
275
|
-
});
|
|
276
|
-
expect(outputMock.info()).toMatch(
|
|
277
|
-
/No changes to your environment variables/
|
|
278
|
-
);
|
|
279
|
-
});
|
|
280
|
-
it("ignores comparison against read only variables", async () => {
|
|
281
|
-
vi.mocked(renderConfirmationPrompt).mockResolvedValue(true);
|
|
282
|
-
vi.mocked(getStorefrontEnvVariables).mockResolvedValue({
|
|
283
|
-
id: SHOPIFY_CONFIG.storefront.id,
|
|
284
|
-
environmentVariables: [
|
|
285
|
-
{
|
|
286
|
-
id: "1",
|
|
287
|
-
key: "EXISTING_TOKEN",
|
|
288
|
-
value: "1",
|
|
289
|
-
isSecret: false,
|
|
290
|
-
readOnly: false
|
|
291
|
-
},
|
|
292
|
-
{
|
|
293
|
-
id: "2",
|
|
294
|
-
key: "SECOND_TOKEN",
|
|
295
|
-
value: "updated value",
|
|
296
|
-
isSecret: false,
|
|
297
|
-
readOnly: true
|
|
298
|
-
}
|
|
299
|
-
]
|
|
300
|
-
});
|
|
301
|
-
await inTemporaryDirectory(async (tmpDir) => {
|
|
302
|
-
const filePath = joinPath(tmpDir, ".env");
|
|
303
|
-
await writeFile(filePath, "EXISTING_TOKEN=1\nSECOND_TOKEN=2");
|
|
304
|
-
await expect(
|
|
305
|
-
runEnvPush({ path: tmpDir, env: "Preview" })
|
|
306
|
-
).resolves.not.toThrow();
|
|
307
|
-
expect(outputMock.info()).toMatch(
|
|
308
|
-
/No changes to your environment variables/
|
|
309
|
-
);
|
|
310
|
-
});
|
|
311
|
-
});
|
|
312
|
-
it("exits when diff is not confirmed", async () => {
|
|
313
|
-
vi.mocked(renderConfirmationPrompt).mockResolvedValue(false);
|
|
314
|
-
vi.mocked(getStorefrontEnvVariables).mockResolvedValue({
|
|
315
|
-
id: SHOPIFY_CONFIG.storefront.id,
|
|
316
|
-
environmentVariables: [
|
|
317
|
-
{
|
|
318
|
-
id: "1",
|
|
319
|
-
key: "EXISTING_TOKEN",
|
|
320
|
-
value: "1",
|
|
321
|
-
isSecret: false,
|
|
322
|
-
readOnly: false
|
|
323
|
-
},
|
|
324
|
-
{
|
|
325
|
-
id: "2",
|
|
326
|
-
key: "SECOND_TOKEN",
|
|
327
|
-
value: "updated value",
|
|
328
|
-
isSecret: false,
|
|
329
|
-
readOnly: true
|
|
330
|
-
}
|
|
331
|
-
]
|
|
332
|
-
});
|
|
333
|
-
await inTemporaryDirectory(async (tmpDir) => {
|
|
334
|
-
const filePath = joinPath(tmpDir, ".env");
|
|
335
|
-
await writeFile(filePath, "EXISTING_TOKEN=1\nSECOND_TOKEN=2");
|
|
336
|
-
await expect(
|
|
337
|
-
runEnvPush({ path: tmpDir, env: "Preview" })
|
|
338
|
-
).resolves.not.toThrow();
|
|
339
|
-
expect(pushStorefrontEnvVariables).not.toHaveBeenCalled();
|
|
340
|
-
});
|
|
341
|
-
});
|
|
342
|
-
it("calls pushStorefrontEnvVariables when diff is confirmed", async () => {
|
|
343
|
-
vi.mocked(renderConfirmationPrompt).mockResolvedValue(true);
|
|
344
|
-
vi.mocked(getStorefrontEnvVariables).mockResolvedValue({
|
|
345
|
-
id: SHOPIFY_CONFIG.storefront.id,
|
|
346
|
-
environmentVariables: [
|
|
347
|
-
{
|
|
348
|
-
id: "1",
|
|
349
|
-
key: "EXISTING_TOKEN",
|
|
350
|
-
value: "1",
|
|
351
|
-
isSecret: false,
|
|
352
|
-
readOnly: false
|
|
353
|
-
},
|
|
354
|
-
{
|
|
355
|
-
id: "2",
|
|
356
|
-
key: "SECOND_TOKEN",
|
|
357
|
-
value: "2",
|
|
358
|
-
isSecret: false,
|
|
359
|
-
readOnly: false
|
|
360
|
-
}
|
|
361
|
-
]
|
|
362
|
-
});
|
|
363
|
-
await inTemporaryDirectory(async (tmpDir) => {
|
|
364
|
-
const filePath = joinPath(tmpDir, ".env");
|
|
365
|
-
await writeFile(filePath, "EXISTING_TOKEN=1\nSECOND_TOKEN=NEW_VALUE");
|
|
366
|
-
await expect(
|
|
367
|
-
runEnvPush({ path: tmpDir, env: "Preview" })
|
|
368
|
-
).resolves.not.toThrow();
|
|
369
|
-
expect(pushStorefrontEnvVariables).toHaveBeenCalledWith(
|
|
370
|
-
{ storeFqdn: "my-shop", token: "abc123" },
|
|
371
|
-
"gid://shopify/HydrogenStorefront/2",
|
|
372
|
-
"gid://shopify/HydrogenStorefrontEnvironment/2",
|
|
373
|
-
[
|
|
374
|
-
{ key: "EXISTING_TOKEN", value: "1" },
|
|
375
|
-
{ key: "SECOND_TOKEN", value: "NEW_VALUE" }
|
|
376
|
-
]
|
|
377
|
-
);
|
|
378
|
-
expect(outputMock.info()).toMatch(
|
|
379
|
-
/Environment variables push to Preview was successful/
|
|
380
|
-
);
|
|
381
|
-
});
|
|
382
|
-
});
|
|
383
|
-
});
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { describe, beforeEach, vi, afterEach, it, expect } from 'vitest';
|
|
2
|
-
import { mockAndCaptureOutput } from '@shopify/cli-kit/node/testing/output';
|
|
3
|
-
import { runGenerate } from './route.js';
|
|
4
|
-
import { generateRoutes } from '../../../lib/setups/routes/generate.js';
|
|
5
|
-
|
|
6
|
-
describe("runGenerate", () => {
|
|
7
|
-
const outputMock = mockAndCaptureOutput();
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
vi.resetAllMocks();
|
|
10
|
-
vi.mock("../../../lib/setups/routes/generate.js");
|
|
11
|
-
});
|
|
12
|
-
afterEach(() => {
|
|
13
|
-
vi.resetAllMocks();
|
|
14
|
-
outputMock.clear();
|
|
15
|
-
});
|
|
16
|
-
it("calls route generation and renders the result", async () => {
|
|
17
|
-
vi.mocked(generateRoutes).mockResolvedValue({
|
|
18
|
-
isTypescript: true,
|
|
19
|
-
formatOptions: {},
|
|
20
|
-
routeGroups: {},
|
|
21
|
-
routes: [
|
|
22
|
-
{ sourceRoute: "", destinationRoute: "/cart", operation: "created" },
|
|
23
|
-
{ sourceRoute: "", destinationRoute: "/about", operation: "skipped" },
|
|
24
|
-
{
|
|
25
|
-
sourceRoute: "",
|
|
26
|
-
destinationRoute: "/collections",
|
|
27
|
-
operation: "created"
|
|
28
|
-
}
|
|
29
|
-
]
|
|
30
|
-
});
|
|
31
|
-
const options = {
|
|
32
|
-
routeName: "all",
|
|
33
|
-
directory: "there",
|
|
34
|
-
typescript: true
|
|
35
|
-
};
|
|
36
|
-
await runGenerate(options);
|
|
37
|
-
expect(generateRoutes).toHaveBeenCalledWith({
|
|
38
|
-
...options,
|
|
39
|
-
v1RouteConvention: false
|
|
40
|
-
});
|
|
41
|
-
expect(outputMock.info()).toMatch(/2 of 3 routes/i);
|
|
42
|
-
});
|
|
43
|
-
});
|