Skip to content

Commit 91fb70d

Browse files
Merge pull request #7029 from Shopify/faster-unit-tests
Faster unit tests
2 parents 6967663 + efa0833 commit 91fb70d

31 files changed

Lines changed: 605 additions & 617 deletions

configurations/vite.config.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ interface ConfigOptions {
1313
poolStrategy: 'threads' | 'forks'
1414
}
1515

16-
export default function config(packagePath: string, {poolStrategy}: ConfigOptions = {poolStrategy: 'forks'}) {
16+
export default function config(packagePath: string, {poolStrategy}: ConfigOptions = {poolStrategy: 'threads'}) {
1717
// always treat environment as one that doesn't support hyperlinks -- otherwise assertions are hard to keep consistent
1818
process.env.FORCE_HYPERLINK = '0'
1919
process.env.FORCE_COLOR = '1'
@@ -28,6 +28,11 @@ export default function config(packagePath: string, {poolStrategy}: ConfigOption
2828
}
2929

3030
return defineConfig({
31+
define: {
32+
'process.env.SHOPIFY_UNIT_TEST': '"1"',
33+
'process.env.FORCE_HYPERLINK': '"0"',
34+
'process.env.FORCE_COLOR': '"1"',
35+
},
3136
resolve: {
3237
alias: aliases(packagePath) as AliasOptions,
3338
},
@@ -45,10 +50,6 @@ export default function config(packagePath: string, {poolStrategy}: ConfigOption
4550
reporter: ['text', 'json', 'lcov'],
4651
exclude: ['**/src/**/vendor/**'],
4752
},
48-
snapshotFormat: {
49-
escapeString: true,
50-
},
51-
includeSource: ['**/src/**/*.{ts,tsx}'],
5253
sequence: {
5354
hooks: 'list',
5455
},
@@ -58,8 +59,6 @@ export default function config(packagePath: string, {poolStrategy}: ConfigOption
5859
'clearTimeout',
5960
'setInterval',
6061
'clearInterval',
61-
'setImmediate',
62-
'clearImmediate',
6362
'Date',
6463
],
6564
},

packages/app/src/cli/services/app-logs/logs-command/ui/components/Logs.test.tsx

Lines changed: 107 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -124,29 +124,29 @@ describe('Logs', () => {
124124
const lastFrame = renderInstance.lastFrame()
125125

126126
expect(unstyled(lastFrame!)).toMatchInlineSnapshot(`
127-
"2024-06-18 16:02:04.868 my-store my-function Success export \\"run\\" executed in 0.5124M instructions
128-
test logs
127+
"2024-06-18 16:02:04.868 my-store my-function Success export "run" executed in 0.5124M instructions
128+
test logs
129129
130-
Input Query Variables:
130+
Input Query Variables:
131131
132-
Namespace: inputQueryVariablesMetafieldNamespace
133-
Key: inputQueryVariablesMetafieldKey
132+
Namespace: inputQueryVariablesMetafieldNamespace
133+
Key: inputQueryVariablesMetafieldKey
134134
135-
{
136-
\\"key\\": \\"value\\"
137-
}
135+
{
136+
"key": "value"
137+
}
138138
139-
Input (10 bytes):
139+
Input (10 bytes):
140140
141-
{
142-
\\"test\\": \\"input\\"
143-
}
141+
{
142+
"test": "input"
143+
}
144144
145-
Output (10 bytes):
145+
Output (10 bytes):
146146
147-
{
148-
\\"test\\": \\"output\\"
149-
}"
147+
{
148+
"test": "output"
149+
}"
150150
`)
151151

152152
renderInstance.unmount()
@@ -174,7 +174,7 @@ describe('Logs', () => {
174174
const lastFrame = renderInstance.lastFrame()
175175

176176
expect(unstyled(lastFrame!)).toMatchInlineSnapshot(`
177-
"2024-06-18 16:02:04.868 my-store my-function Success export \\"run\\" executed in 0.5124M instructions
177+
"2024-06-18 16:02:04.868 my-store my-function Success export "run" executed in 0.5124M instructions
178178
test logs
179179
180180
Input Query Variables:
@@ -187,15 +187,15 @@ describe('Logs', () => {
187187
Input (10 bytes):
188188
189189
{
190-
\\"test\\": \\"input\\"
190+
"test": "input"
191191
}
192192
193193
Output (10 bytes):
194194
195195
{
196-
\\"test\\": \\"output\\"
196+
"test": "output"
197197
}"
198-
`)
198+
`)
199199

200200
renderInstance.unmount()
201201
})
@@ -225,20 +225,20 @@ describe('Logs', () => {
225225
const lastFrame = renderInstance.lastFrame()
226226

227227
expect(unstyled(lastFrame!)).toMatchInlineSnapshot(`
228-
"2024-06-18 16:02:04.868 my-store my-function Success export \\"run\\" executed in 0.5124M instructions
229-
test logs
228+
"2024-06-18 16:02:04.868 my-store my-function Success export "run" executed in 0.5124M instructions
229+
test logs
230230
231-
Input (10 bytes):
231+
Input (10 bytes):
232232
233-
{
234-
\\"test\\": \\"input\\"
235-
}
233+
{
234+
"test": "input"
235+
}
236236
237-
Output (10 bytes):
237+
Output (10 bytes):
238238
239-
{
240-
\\"test\\": \\"output\\"
241-
}"
239+
{
240+
"test": "output"
241+
}"
242242
`)
243243

244244
renderInstance.unmount()
@@ -280,27 +280,27 @@ describe('Logs', () => {
280280
const lastFrame = renderInstance.lastFrame()
281281

282282
expect(unstyled(lastFrame!)).toMatchInlineSnapshot(`
283-
"2024-06-18 16:02:04.868 my-store my-function Success network access response from cache
284-
Cache write time: 2023-05-12T15:17:01.000Z
285-
Cache TTL: 300 s
286-
HTTP request:
287-
{
288-
\\"url\\": \\"https://api.example.com/hello\\",
289-
\\"method\\": \\"GET\\",
290-
\\"headers\\": {},
291-
\\"body\\": null,
292-
\\"policy\\": {
293-
\\"read_timeout_ms\\": 500
294-
}
295-
}
296-
HTTP response:
297-
{
298-
\\"status\\": 200,
299-
\\"body\\": \\"Success\\",
300-
\\"headers\\": {
301-
\\"header1\\": \\"value1\\"
283+
"2024-06-18 16:02:04.868 my-store my-function Success network access response from cache
284+
Cache write time: 2023-05-12T15:17:01.000Z
285+
Cache TTL: 300 s
286+
HTTP request:
287+
{
288+
"url": "https://api.example.com/hello",
289+
"method": "GET",
290+
"headers": {},
291+
"body": null,
292+
"policy": {
293+
"read_timeout_ms": 500
294+
}
302295
}
303-
}"
296+
HTTP response:
297+
{
298+
"status": 200,
299+
"body": "Success",
300+
"headers": {
301+
"header1": "value1"
302+
}
303+
}"
304304
`)
305305

306306
renderInstance.unmount()
@@ -342,28 +342,28 @@ describe('Logs', () => {
342342
const lastFrame = renderInstance.lastFrame()
343343

344344
expect(unstyled(lastFrame!)).toMatchInlineSnapshot(`
345-
"2024-06-18 16:02:04.868 my-store my-function Success network access request executed in 80 ms
346-
Attempt: 1
347-
Connect time: 40 ms
348-
Write read time: 40 ms
349-
HTTP request:
350-
{
351-
\\"url\\": \\"https://api.example.com/hello\\",
352-
\\"method\\": \\"GET\\",
353-
\\"headers\\": {},
354-
\\"body\\": null,
355-
\\"policy\\": {
356-
\\"read_timeout_ms\\": 500
345+
"2024-06-18 16:02:04.868 my-store my-function Success network access request executed in 80 ms
346+
Attempt: 1
347+
Connect time: 40 ms
348+
Write read time: 40 ms
349+
HTTP request:
350+
{
351+
"url": "https://api.example.com/hello",
352+
"method": "GET",
353+
"headers": {},
354+
"body": null,
355+
"policy": {
356+
"read_timeout_ms": 500
357+
}
357358
}
358-
}
359-
HTTP response:
360-
{
361-
\\"status\\": 200,
362-
\\"body\\": \\"Success\\",
363-
\\"headers\\": {
364-
\\"header1\\": \\"value1\\"
365-
}
366-
}"
359+
HTTP response:
360+
{
361+
"status": 200,
362+
"body": "Success",
363+
"headers": {
364+
"header1": "value1"
365+
}
366+
}"
367367
`)
368368

369369
renderInstance.unmount()
@@ -405,19 +405,19 @@ describe('Logs', () => {
405405
const lastFrame = renderInstance.lastFrame()
406406

407407
expect(unstyled(lastFrame!)).toMatchInlineSnapshot(`
408-
"2024-06-18 16:02:04.868 my-store my-function Failure network access request executed
409-
Attempt: 1
410-
HTTP request:
411-
{
412-
\\"url\\": \\"https://api.example.com/hello\\",
413-
\\"method\\": \\"GET\\",
414-
\\"headers\\": {},
415-
\\"body\\": null,
416-
\\"policy\\": {
417-
\\"read_timeout_ms\\": 500
408+
"2024-06-18 16:02:04.868 my-store my-function Failure network access request executed
409+
Attempt: 1
410+
HTTP request:
411+
{
412+
"url": "https://api.example.com/hello",
413+
"method": "GET",
414+
"headers": {},
415+
"body": null,
416+
"policy": {
417+
"read_timeout_ms": 500
418+
}
418419
}
419-
}
420-
Error: Timeout Error"
420+
Error: Timeout Error"
421421
`)
422422

423423
renderInstance.unmount()
@@ -455,18 +455,18 @@ describe('Logs', () => {
455455
const lastFrame = renderInstance.lastFrame()
456456

457457
expect(unstyled(lastFrame!)).toMatchInlineSnapshot(`
458-
"2024-06-18 16:02:04.868 my-store my-function Success network access request executing in background
459-
Reason: No cached response available
460-
HTTP request:
461-
{
462-
\\"url\\": \\"https://api.example.com/hello\\",
463-
\\"method\\": \\"GET\\",
464-
\\"headers\\": {},
465-
\\"body\\": null,
466-
\\"policy\\": {
467-
\\"read_timeout_ms\\": 500
468-
}
469-
}"
458+
"2024-06-18 16:02:04.868 my-store my-function Success network access request executing in background
459+
Reason: No cached response available
460+
HTTP request:
461+
{
462+
"url": "https://api.example.com/hello",
463+
"method": "GET",
464+
"headers": {},
465+
"body": null,
466+
"policy": {
467+
"read_timeout_ms": 500
468+
}
469+
}"
470470
`)
471471

472472
renderInstance.unmount()
@@ -504,18 +504,18 @@ describe('Logs', () => {
504504
const lastFrame = renderInstance.lastFrame()
505505

506506
expect(unstyled(lastFrame!)).toMatchInlineSnapshot(`
507-
"2024-06-18 16:02:04.868 my-store my-function Success network access request executing in background
508-
Reason: Cache is about to expire
509-
HTTP request:
510-
{
511-
\\"url\\": \\"https://api.example.com/hello\\",
512-
\\"method\\": \\"GET\\",
513-
\\"headers\\": {},
514-
\\"body\\": null,
515-
\\"policy\\": {
516-
\\"read_timeout_ms\\": 500
517-
}
518-
}"
507+
"2024-06-18 16:02:04.868 my-store my-function Success network access request executing in background
508+
Reason: Cache is about to expire
509+
HTTP request:
510+
{
511+
"url": "https://api.example.com/hello",
512+
"method": "GET",
513+
"headers": {},
514+
"body": null,
515+
"policy": {
516+
"read_timeout_ms": 500
517+
}
518+
}"
519519
`)
520520

521521
renderInstance.unmount()

0 commit comments

Comments
 (0)