@shopify/oxygen-cli 1.12.1-unstable.202309120942.0 → 1.12.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,158 +0,0 @@
1
- import { mkdir, rmdir, touchFile } from '@shopify/cli-kit/node/fs';
2
- import { joinPath } from '@shopify/cli-kit/node/path';
3
- import { outputInfo, outputWarn } from '@shopify/cli-kit/node/output';
4
- import { vi, beforeAll, afterAll, describe, test, expect } from 'vitest';
5
- import { createTestConfig, testToken } from './test-helper.js';
6
- import * as utils from './utils.js';
7
-
8
- const randomString = Math.random().toString(36).substring(7);
9
- const rootFolder = `/tmp/${randomString}/`;
10
- const testConfig = createTestConfig(rootFolder);
11
- vi.mock("@shopify/cli-kit/node/output");
12
- beforeAll(async () => {
13
- await mkdir(rootFolder);
14
- await mkdir(`${rootFolder}/worker`);
15
- await mkdir(`${rootFolder}/assets`);
16
- });
17
- afterAll(async () => {
18
- await rmdir(`${rootFolder}/worker`, { force: true });
19
- await rmdir(`${rootFolder}/assets`, { force: true });
20
- await rmdir(rootFolder, { force: true });
21
- });
22
- describe("getBuildCommandFromLockfile", () => {
23
- test("getBuildCommandFromLockfile returns the default build command without a lockfile", () => {
24
- const buildCommand = utils.getBuildCommandFromLockFile(testConfig);
25
- expect(buildCommand).toBe(utils.deployDefaults.buildCommandDefault);
26
- });
27
- test("getBuildCommandFromLockfile returns the corresponding build command for a lockfile", async () => {
28
- await touchFile(`${rootFolder}/pnpm-lock.yaml`);
29
- const buildCommand = utils.getBuildCommandFromLockFile(testConfig);
30
- expect(buildCommand).toBe("pnpm run build");
31
- expect(outputInfo).toHaveBeenCalledWith(
32
- 'Found: pnpm-lock.yaml. Assuming "pnpm run build" as build command. Use the buildCommand flag to override.',
33
- utils.stderrLogger
34
- );
35
- });
36
- test("getBuildCommandFromLockfile the first build command and warns when multiple lockfiles are found", async () => {
37
- await touchFile(`${rootFolder}/yarn.lock`);
38
- const buildCommand = utils.getBuildCommandFromLockFile(testConfig);
39
- expect(buildCommand).toBe("pnpm run build");
40
- expect(outputInfo).toHaveBeenCalledWith(
41
- 'Assuming "pnpm run build" as build command. Use the buildCommand flag to override.',
42
- utils.stderrLogger
43
- );
44
- expect(outputWarn).toHaveBeenCalledWith(
45
- "Warning: Multiple lock files found: (pnpm-lock.yaml, yarn.lock).",
46
- utils.stderrLogger
47
- );
48
- });
49
- });
50
- describe("parseToken", () => {
51
- test("parseToken returns a token object when given a valid token", () => {
52
- const base64EncodedToken = Buffer.from(JSON.stringify(testToken)).toString(
53
- "base64"
54
- );
55
- const parsedToken = utils.parseToken(base64EncodedToken);
56
- expect(parsedToken).toEqual(testToken);
57
- });
58
- test("parseToken throws when given an invalid token", () => {
59
- try {
60
- utils.parseToken("invalidToken");
61
- } catch (err) {
62
- expect(err).toEqual(
63
- new Error(
64
- `Error processing deployment token. Please check your token and try again.`
65
- )
66
- );
67
- }
68
- });
69
- });
70
- describe("verifyConfig", () => {
71
- test("verifyConfig resolves with a valid configuration", async () => {
72
- await expect(utils.verifyConfig({ config: testConfig })).resolves.toBe(
73
- void 0
74
- );
75
- });
76
- test("verifyConfig throws when the rootPath cannot be resolved", async () => {
77
- const invalidConfig = {
78
- ...testConfig,
79
- rootPath: "/doesNotExist"
80
- };
81
- await expect(utils.verifyConfig({ config: invalidConfig })).rejects.toThrow(
82
- new Error("Path not found: /doesNotExist")
83
- );
84
- });
85
- test("verifyConfig throws when the assetsDir cannot be resolved", async () => {
86
- const invalidConfig = {
87
- ...testConfig,
88
- assetsDir: "not_there",
89
- skipBuild: true
90
- };
91
- await expect(utils.verifyConfig({ config: invalidConfig })).rejects.toThrow(
92
- new Error(
93
- `Path not found: ${joinPath(
94
- invalidConfig.rootPath,
95
- invalidConfig.assetsDir
96
- )}`
97
- )
98
- );
99
- expect(outputWarn).toHaveBeenCalledWith(
100
- `Use the "workerOnly" flag to perform a worker-only deployment.`,
101
- utils.stderrLogger
102
- );
103
- });
104
- test("verifyConfig throws when the workerDir cannot be resolved after a build", async () => {
105
- const invalidConfig = {
106
- ...testConfig,
107
- skipBuild: false,
108
- workerDir: "not_there",
109
- workerOnly: true
110
- };
111
- await expect(
112
- utils.verifyConfig({ config: invalidConfig, performedBuild: true })
113
- ).rejects.toThrow(
114
- new Error(
115
- `Path not found: ${joinPath(
116
- invalidConfig.rootPath,
117
- invalidConfig.workerDir
118
- )}`
119
- )
120
- );
121
- });
122
- test("verifyConfig throws when given an invalid deploymentUrl", async () => {
123
- const invalidConfig = {
124
- ...testConfig,
125
- deploymentUrl: "invalidAddress"
126
- };
127
- await expect(utils.verifyConfig({ config: invalidConfig })).rejects.toThrow(
128
- new Error("Invalid deployment service URL: invalidAddress")
129
- );
130
- });
131
- test("parseToken returns a token object when given a valid token", () => {
132
- const unparsedToken = {
133
- access_token: "some_token",
134
- allowed_resource: "gid://oxygen-hub/Namespace/1",
135
- app_id: "gid://oxygen-hub/App/1",
136
- client: "gid://oxygen-hub/Client/1",
137
- expires_at: "2023-04-08T09:38:50.368Z",
138
- namespace: "fresh-namespace",
139
- namespace_id: "gid://oxygen-hub/Namespace/1"
140
- };
141
- const base64EncodedToken = Buffer.from(
142
- JSON.stringify(unparsedToken)
143
- ).toString("base64");
144
- const parsedToken = utils.parseToken(base64EncodedToken);
145
- expect(parsedToken).toEqual(testToken);
146
- });
147
- test("parseToken throws when given an invalid token", () => {
148
- try {
149
- utils.parseToken("invalidToken");
150
- } catch (err) {
151
- expect(err).toEqual(
152
- new Error(
153
- `Error processing deployment token. Please check your token and try again.`
154
- )
155
- );
156
- }
157
- });
158
- });