@canva/cli 1.6.0 → 1.8.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/CHANGELOG.md +22 -0
- package/README.md +1 -1
- package/cli.js +436 -436
- package/package.json +1 -1
- package/templates/base/package.json +1 -1
- package/templates/base/scripts/copy_env.ts +4 -1
- package/templates/dam/package.json +1 -1
- package/templates/dam/scripts/copy_env.ts +4 -1
- package/templates/data_connector/package.json +1 -1
- package/templates/data_connector/scripts/copy_env.ts +4 -1
- package/templates/gen_ai/package.json +1 -1
- package/templates/gen_ai/scripts/copy_env.ts +4 -1
- package/templates/hello_world/package.json +1 -1
- package/templates/hello_world/scripts/copy_env.ts +4 -1
- package/templates/base/utils/backend/jwt_middleware/tests/jwt_middleware.tests.ts +0 -630
- package/templates/common/utils/backend/jwt_middleware/tests/jwt_middleware.tests.ts +0 -630
- package/templates/common/utils/tests/table_wrapper.tests.ts +0 -252
- package/templates/dam/scripts/start/tests/start.tests.ts +0 -61
- package/templates/dam/utils/backend/jwt_middleware/tests/jwt_middleware.tests.ts +0 -630
- package/templates/data_connector/scripts/start/tests/start.tests.ts +0 -61
- package/templates/gen_ai/scripts/start/tests/start.tests.ts +0 -61
- package/templates/gen_ai/utils/backend/bearer_middleware/tests/bearer_middleware.tests.ts +0 -192
- package/templates/hello_world/scripts/start/tests/start.tests.ts +0 -61
- /package/templates/base/scripts/{start/tests/start.tests.ts → start.tests.ts} +0 -0
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
import type { Cell, TableElement } from "@canva/design";
|
|
2
|
-
import { TableWrapper } from "../table_wrapper";
|
|
3
|
-
|
|
4
|
-
describe("TableWrapper", () => {
|
|
5
|
-
describe("create", () => {
|
|
6
|
-
it("should create a new table", () => {
|
|
7
|
-
const wrapper = TableWrapper.create(2, 3);
|
|
8
|
-
const element = wrapper.toElement();
|
|
9
|
-
expect(element.rows.length).toBe(2);
|
|
10
|
-
expect(element.rows[0].cells.length).toBe(3);
|
|
11
|
-
expect(element.rows[1].cells.length).toBe(3);
|
|
12
|
-
});
|
|
13
|
-
it("should throw an error if the row count is less than 1", () => {
|
|
14
|
-
expect(() => TableWrapper.create(0, 1)).toThrow();
|
|
15
|
-
});
|
|
16
|
-
it("should throw an error if the column count is less than 1", () => {
|
|
17
|
-
expect(() => TableWrapper.create(1, 0)).toThrow();
|
|
18
|
-
});
|
|
19
|
-
it("should throw an error if the number of cells exceeds 225", () => {
|
|
20
|
-
expect(() => TableWrapper.create(16, 15)).toThrow();
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
describe("fromElement", () => {
|
|
25
|
-
it("should create a table wrapper from an existing table element", () => {
|
|
26
|
-
const element: TableElement = {
|
|
27
|
-
type: "table",
|
|
28
|
-
rows: [
|
|
29
|
-
{
|
|
30
|
-
cells: [
|
|
31
|
-
{ colSpan: 2, type: "empty" },
|
|
32
|
-
{ type: "empty" },
|
|
33
|
-
{ rowSpan: 2, type: "empty" },
|
|
34
|
-
],
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
cells: [
|
|
38
|
-
{
|
|
39
|
-
type: "string",
|
|
40
|
-
value: "hello",
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
type: "empty",
|
|
44
|
-
attributes: { backgroundColor: "#ff00ff" },
|
|
45
|
-
},
|
|
46
|
-
{ type: "empty" },
|
|
47
|
-
],
|
|
48
|
-
},
|
|
49
|
-
],
|
|
50
|
-
};
|
|
51
|
-
const wrapper = TableWrapper.fromElement(element);
|
|
52
|
-
expect(wrapper.toElement()).toEqual(element);
|
|
53
|
-
|
|
54
|
-
// Make sure the new element is not a reference
|
|
55
|
-
if (element.rows[1].cells[1]?.attributes) {
|
|
56
|
-
element.rows[1].cells[1].attributes.backgroundColor = "#ff0000";
|
|
57
|
-
}
|
|
58
|
-
expect(wrapper.toElement()).not.toEqual(element);
|
|
59
|
-
});
|
|
60
|
-
it("should throw an error if the element is not a table", () => {
|
|
61
|
-
const element = {
|
|
62
|
-
type: "TEXT",
|
|
63
|
-
children: ["hello"],
|
|
64
|
-
};
|
|
65
|
-
expect(() => {
|
|
66
|
-
TableWrapper.fromElement(element as unknown as TableElement);
|
|
67
|
-
}).toThrow();
|
|
68
|
-
});
|
|
69
|
-
it("should throw an error if the element has no rows", () => {
|
|
70
|
-
expect(() => {
|
|
71
|
-
TableWrapper.fromElement({
|
|
72
|
-
type: "TABLE",
|
|
73
|
-
} as unknown as TableElement);
|
|
74
|
-
}).toThrow();
|
|
75
|
-
expect(() => {
|
|
76
|
-
TableWrapper.fromElement({
|
|
77
|
-
type: "table",
|
|
78
|
-
rows: [],
|
|
79
|
-
});
|
|
80
|
-
}).toThrow();
|
|
81
|
-
});
|
|
82
|
-
it("should throw an error if any row of the element has no cells", () => {
|
|
83
|
-
const element: TableElement = {
|
|
84
|
-
type: "table",
|
|
85
|
-
rows: [{ cells: [] }],
|
|
86
|
-
};
|
|
87
|
-
expect(() => {
|
|
88
|
-
TableWrapper.fromElement(element);
|
|
89
|
-
}).toThrow();
|
|
90
|
-
});
|
|
91
|
-
it("should throw an error if number of cells is inconsistent", () => {
|
|
92
|
-
const element: TableElement = {
|
|
93
|
-
type: "table",
|
|
94
|
-
rows: [
|
|
95
|
-
{ cells: [{ type: "empty" }, { type: "empty" }] },
|
|
96
|
-
{ cells: [{ type: "empty" }] },
|
|
97
|
-
],
|
|
98
|
-
};
|
|
99
|
-
expect(() => {
|
|
100
|
-
TableWrapper.fromElement(element);
|
|
101
|
-
}).toThrow();
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
describe("addRow", () => {
|
|
106
|
-
it("should add a row to the table", () => {
|
|
107
|
-
const wrapper = TableWrapper.create(2, 3);
|
|
108
|
-
wrapper.addRow(0);
|
|
109
|
-
const element = wrapper.toElement();
|
|
110
|
-
expect(element.rows.length).toBe(3);
|
|
111
|
-
expect(element.rows[0].cells.length).toBe(3);
|
|
112
|
-
});
|
|
113
|
-
it("should copy the fill value if top and bottom cells are the same", () => {
|
|
114
|
-
const wrapper = TableWrapper.create(2, 3);
|
|
115
|
-
wrapper.setCellDetails(1, 1, {
|
|
116
|
-
type: "empty",
|
|
117
|
-
attributes: { backgroundColor: "#ff0000" },
|
|
118
|
-
});
|
|
119
|
-
wrapper.setCellDetails(2, 1, {
|
|
120
|
-
type: "empty",
|
|
121
|
-
attributes: { backgroundColor: "#ff0000" },
|
|
122
|
-
});
|
|
123
|
-
wrapper.addRow(1);
|
|
124
|
-
const newCell = wrapper.getCellDetails(2, 1);
|
|
125
|
-
expect(newCell?.attributes).toBeDefined();
|
|
126
|
-
expect(newCell?.attributes?.backgroundColor).toBe("#ff0000");
|
|
127
|
-
});
|
|
128
|
-
it("should expand the row span if top and bottom cells belong to the same merged cell", () => {
|
|
129
|
-
const wrapper = TableWrapper.create(2, 3);
|
|
130
|
-
wrapper.setCellDetails(1, 1, { rowSpan: 2, type: "empty" });
|
|
131
|
-
wrapper.addRow(1);
|
|
132
|
-
const mergedCell = wrapper.getCellDetails(1, 1);
|
|
133
|
-
expect(mergedCell?.rowSpan).toBe(3);
|
|
134
|
-
});
|
|
135
|
-
it("should throw an error if the row position is out of bounds", () => {
|
|
136
|
-
const wrapper = TableWrapper.create(2, 3);
|
|
137
|
-
expect(() => wrapper.addRow(-1)).toThrow();
|
|
138
|
-
expect(() => wrapper.addRow(3)).toThrow();
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
describe("addColumn", () => {
|
|
143
|
-
it("should add a column to the table", () => {
|
|
144
|
-
const wrapper = TableWrapper.create(2, 3);
|
|
145
|
-
wrapper.addColumn(0);
|
|
146
|
-
const element = wrapper.toElement();
|
|
147
|
-
expect(element.rows.length).toBe(2);
|
|
148
|
-
expect(element.rows[0].cells.length).toBe(4);
|
|
149
|
-
});
|
|
150
|
-
it("should copy the fill value if left and right cells are the same", () => {
|
|
151
|
-
const wrapper = TableWrapper.create(2, 3);
|
|
152
|
-
wrapper.setCellDetails(1, 1, {
|
|
153
|
-
type: "empty",
|
|
154
|
-
attributes: { backgroundColor: "#ff0000" },
|
|
155
|
-
});
|
|
156
|
-
wrapper.setCellDetails(1, 2, {
|
|
157
|
-
type: "empty",
|
|
158
|
-
attributes: { backgroundColor: "#ff0000" },
|
|
159
|
-
});
|
|
160
|
-
wrapper.addColumn(1);
|
|
161
|
-
const newCell = wrapper.getCellDetails(1, 2);
|
|
162
|
-
expect(newCell?.attributes).toBeDefined();
|
|
163
|
-
expect(newCell?.attributes?.backgroundColor).toBe("#ff0000");
|
|
164
|
-
});
|
|
165
|
-
it("should expand the column span if left and right cells belong to the same merged cell", () => {
|
|
166
|
-
const wrapper = TableWrapper.create(2, 3);
|
|
167
|
-
wrapper.setCellDetails(1, 1, { type: "empty", colSpan: 2 });
|
|
168
|
-
wrapper.addColumn(1);
|
|
169
|
-
const mergedCell = wrapper.getCellDetails(1, 1);
|
|
170
|
-
expect(mergedCell?.colSpan).toBe(3);
|
|
171
|
-
});
|
|
172
|
-
it("should throw an error if the column position is out of bounds", () => {
|
|
173
|
-
const wrapper = TableWrapper.create(2, 3);
|
|
174
|
-
expect(() => wrapper.addColumn(-1)).toThrow();
|
|
175
|
-
expect(() => wrapper.addColumn(4)).toThrow();
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
describe("isGhostCell", () => {
|
|
180
|
-
it("should return true if the cell is a ghost cell", () => {
|
|
181
|
-
const wrapper = TableWrapper.create(2, 3);
|
|
182
|
-
wrapper.setCellDetails(1, 1, { type: "empty", colSpan: 2 });
|
|
183
|
-
expect(wrapper.isGhostCell(1, 1)).toBe(false);
|
|
184
|
-
expect(wrapper.isGhostCell(1, 2)).toBe(true);
|
|
185
|
-
expect(wrapper.isGhostCell(1, 3)).toBe(false);
|
|
186
|
-
});
|
|
187
|
-
it("should throw an error if the position is out of bounds", () => {
|
|
188
|
-
const wrapper = TableWrapper.create(2, 3);
|
|
189
|
-
expect(() => wrapper.isGhostCell(0, 1)).toThrow();
|
|
190
|
-
expect(() => wrapper.isGhostCell(3, 1)).toThrow();
|
|
191
|
-
expect(() => wrapper.isGhostCell(1, 0)).toThrow();
|
|
192
|
-
expect(() => wrapper.isGhostCell(1, 4)).toThrow();
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
describe("setCellDetails", () => {
|
|
197
|
-
it("should set the cell details", () => {
|
|
198
|
-
const wrapper = TableWrapper.create(2, 3);
|
|
199
|
-
wrapper.setCellDetails(1, 1, {
|
|
200
|
-
colSpan: 2,
|
|
201
|
-
rowSpan: 2,
|
|
202
|
-
type: "string",
|
|
203
|
-
value: "hello",
|
|
204
|
-
attributes: { backgroundColor: "#ff0000" },
|
|
205
|
-
});
|
|
206
|
-
expect(wrapper.isGhostCell(1, 1)).toBe(false);
|
|
207
|
-
expect(wrapper.isGhostCell(1, 2)).toBe(true);
|
|
208
|
-
expect(wrapper.isGhostCell(2, 1)).toBe(true);
|
|
209
|
-
expect(wrapper.isGhostCell(2, 2)).toBe(true);
|
|
210
|
-
const element = wrapper.toElement();
|
|
211
|
-
const firstCell = element.rows[0].cells[0] as Cell & {
|
|
212
|
-
type: "string";
|
|
213
|
-
value: string;
|
|
214
|
-
};
|
|
215
|
-
expect(firstCell?.type).toBe("string");
|
|
216
|
-
expect(firstCell.value).toBe("hello");
|
|
217
|
-
expect(firstCell.attributes).toBeDefined();
|
|
218
|
-
expect(firstCell.attributes?.backgroundColor).toBe("#ff0000");
|
|
219
|
-
});
|
|
220
|
-
it("should throw an error if the position is out of bounds", () => {
|
|
221
|
-
const wrapper = TableWrapper.create(2, 3);
|
|
222
|
-
expect(() => wrapper.setCellDetails(0, 1, { type: "empty" })).toThrow();
|
|
223
|
-
expect(() => wrapper.setCellDetails(3, 1, { type: "empty" })).toThrow();
|
|
224
|
-
expect(() => wrapper.setCellDetails(1, 0, { type: "empty" })).toThrow();
|
|
225
|
-
expect(() => wrapper.setCellDetails(1, 4, { type: "empty" })).toThrow();
|
|
226
|
-
});
|
|
227
|
-
it("should throw an error if the rowSpan is invalid", () => {
|
|
228
|
-
const wrapper = TableWrapper.create(2, 3);
|
|
229
|
-
expect(() =>
|
|
230
|
-
wrapper.setCellDetails(1, 1, { type: "empty", rowSpan: -1 }),
|
|
231
|
-
).toThrow();
|
|
232
|
-
expect(() =>
|
|
233
|
-
wrapper.setCellDetails(1, 1, { type: "empty", rowSpan: 0 }),
|
|
234
|
-
).toThrow();
|
|
235
|
-
expect(() =>
|
|
236
|
-
wrapper.setCellDetails(1, 1, { type: "empty", rowSpan: 3 }),
|
|
237
|
-
).toThrow();
|
|
238
|
-
});
|
|
239
|
-
it("should throw an error if the colSpan is invalid", () => {
|
|
240
|
-
const wrapper = TableWrapper.create(2, 3);
|
|
241
|
-
expect(() =>
|
|
242
|
-
wrapper.setCellDetails(1, 1, { type: "empty", colSpan: -1 }),
|
|
243
|
-
).toThrow();
|
|
244
|
-
expect(() =>
|
|
245
|
-
wrapper.setCellDetails(1, 1, { type: "empty", colSpan: 0 }),
|
|
246
|
-
).toThrow();
|
|
247
|
-
expect(() =>
|
|
248
|
-
wrapper.setCellDetails(1, 1, { type: "empty", colSpan: 4 }),
|
|
249
|
-
).toThrow();
|
|
250
|
-
});
|
|
251
|
-
});
|
|
252
|
-
});
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
|
|
3
|
-
import type { ChildProcess } from "child_process";
|
|
4
|
-
import { spawn } from "child_process";
|
|
5
|
-
import * as treeKill from "tree-kill";
|
|
6
|
-
|
|
7
|
-
describe("start script", () => {
|
|
8
|
-
let serverProcess: ChildProcess;
|
|
9
|
-
|
|
10
|
-
afterEach(() => {
|
|
11
|
-
if (serverProcess?.pid && !serverProcess.exitCode) {
|
|
12
|
-
treeKill(serverProcess.pid);
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it("should execute 'npm run start' and start a dev server", async () => {
|
|
17
|
-
const testServerPort = 8089;
|
|
18
|
-
serverProcess = await spawn(
|
|
19
|
-
`npm run start -- -p ${testServerPort} --no-preview`,
|
|
20
|
-
{
|
|
21
|
-
shell: true,
|
|
22
|
-
},
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
if (!serverProcess.pid) {
|
|
26
|
-
throw new Error("Unable to start server");
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// wait for the server to start and collect output until it reports the running URL
|
|
30
|
-
let output = "";
|
|
31
|
-
await new Promise<void>((resolve, reject) => {
|
|
32
|
-
serverProcess.stdout?.on("data", (data) => {
|
|
33
|
-
output += data.toString();
|
|
34
|
-
if (output.includes("Development URL")) {
|
|
35
|
-
resolve();
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
serverProcess.stderr?.on("data", (data) => {
|
|
40
|
-
console.error("Server process error: ", data.toString());
|
|
41
|
-
reject();
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
// timeout and fail test if the server hasn't correctly started in 10 seconds
|
|
45
|
-
setTimeout(() => {
|
|
46
|
-
if (serverProcess?.pid && !serverProcess.exitCode) {
|
|
47
|
-
treeKill(serverProcess.pid);
|
|
48
|
-
}
|
|
49
|
-
reject(new Error("Test timed out"));
|
|
50
|
-
}, 10000);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
// check that the server is running and accessible
|
|
54
|
-
const expectedServerURL = `http://localhost:${testServerPort}`;
|
|
55
|
-
expect(output).toContain(expectedServerURL);
|
|
56
|
-
expect(serverProcess.exitCode).toBeNull();
|
|
57
|
-
|
|
58
|
-
// clean up
|
|
59
|
-
treeKill(serverProcess.pid);
|
|
60
|
-
}, 15000); // 15 seconds timeout to allow for the server to start
|
|
61
|
-
});
|