Skip to content

Commit 02bd183

Browse files
committed
woo, some great test improvements
1 parent 6f6e609 commit 02bd183

File tree

15 files changed

+315
-37
lines changed

15 files changed

+315
-37
lines changed

epicshop/fix-watch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ async function run() {
5454
await $({
5555
stdio: 'inherit',
5656
cwd: workshopRoot,
57-
})`node ./scripts/fix.js`
57+
})`node ./epicshop/fix.js`
5858
} catch (error) {
5959
throw error
6060
} finally {

exercises/04.code-splitting/01.problem.lazy/tests/code-split.test.js renamed to exercises/04.code-splitting/01.problem.lazy/tests/code-split.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ test('should load the globe and countries modules on demand', async ({
1919
const jsRequests = await page.evaluate(() =>
2020
performance
2121
.getEntriesByType('resource')
22-
.filter((entry) => entry.initiatorType === 'script')
22+
.filter(
23+
(entry) =>
24+
(entry as PerformanceResourceTiming).initiatorType === 'script',
25+
)
2326
.map((entry) => entry.name),
2427
)
2528

exercises/04.code-splitting/01.solution.lazy/tests/code-split.test.js renamed to exercises/04.code-splitting/01.solution.lazy/tests/code-split.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ test('should load the globe and countries modules on demand', async ({
1919
const jsRequests = await page.evaluate(() =>
2020
performance
2121
.getEntriesByType('resource')
22-
.filter((entry) => entry.initiatorType === 'script')
22+
.filter(
23+
(entry) =>
24+
(entry as PerformanceResourceTiming).initiatorType === 'script',
25+
)
2326
.map((entry) => entry.name),
2427
)
2528

exercises/04.code-splitting/02.problem.eager/tests/eager-loading.test.js renamed to exercises/04.code-splitting/02.problem.eager/tests/eager-loading.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ test('should load the globe and countries modules on hover', async ({
1313
const jsRequests = await page.evaluate(() =>
1414
performance
1515
.getEntriesByType('resource')
16-
.filter((entry) => entry.initiatorType === 'script')
16+
.filter(
17+
(entry) =>
18+
(entry as PerformanceResourceTiming).initiatorType === 'script',
19+
)
1720
.map((entry) => entry.name),
1821
)
1922

@@ -41,7 +44,10 @@ test('should load the globe and countries modules on focus', async ({
4144
const jsRequests = await page.evaluate(() =>
4245
performance
4346
.getEntriesByType('resource')
44-
.filter((entry) => entry.initiatorType === 'script')
47+
.filter(
48+
(entry) =>
49+
(entry as PerformanceResourceTiming).initiatorType === 'script',
50+
)
4551
.map((entry) => entry.name),
4652
)
4753

exercises/04.code-splitting/02.solution.eager/tests/eager-loading.test.js renamed to exercises/04.code-splitting/02.solution.eager/tests/eager-loading.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ test('should load the globe and countries modules on hover', async ({
1313
const jsRequests = await page.evaluate(() =>
1414
performance
1515
.getEntriesByType('resource')
16-
.filter((entry) => entry.initiatorType === 'script')
16+
.filter(
17+
(entry) =>
18+
(entry as PerformanceResourceTiming).initiatorType === 'script',
19+
)
1720
.map((entry) => entry.name),
1821
)
1922

@@ -41,7 +44,10 @@ test('should load the globe and countries modules on focus', async ({
4144
const jsRequests = await page.evaluate(() =>
4245
performance
4346
.getEntriesByType('resource')
44-
.filter((entry) => entry.initiatorType === 'script')
47+
.filter(
48+
(entry) =>
49+
(entry as PerformanceResourceTiming).initiatorType === 'script',
50+
)
4551
.map((entry) => entry.name),
4652
)
4753

exercises/04.code-splitting/03.problem.transition/tests/flash.test.js renamed to exercises/04.code-splitting/03.problem.transition/tests/flash.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ test('should not show a pending UI when the globe is ready', async ({
1313
const jsRequests = await page.evaluate(() =>
1414
performance
1515
.getEntriesByType('resource')
16-
.filter((entry) => entry.initiatorType === 'script')
16+
.filter(
17+
(entry) =>
18+
(entry as PerformanceResourceTiming).initiatorType === 'script',
19+
)
1720
.map((entry) => entry.name),
1821
)
1922

exercises/04.code-splitting/03.solution.transition/tests/flash.test.js renamed to exercises/04.code-splitting/03.solution.transition/tests/flash.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ test('should not show a pending UI when the globe is ready', async ({
1313
const jsRequests = await page.evaluate(() =>
1414
performance
1515
.getEntriesByType('resource')
16-
.filter((entry) => entry.initiatorType === 'script')
16+
.filter(
17+
(entry) =>
18+
(entry as PerformanceResourceTiming).initiatorType === 'script',
19+
)
1720
.map((entry) => entry.name),
1821
)
1922

exercises/05.calculations/01.problem.use-memo/tests/todo.test.js

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { test, expect } from '@playwright/test'
2+
3+
test('searchCities should not be called when clicking force rerender', async ({
4+
page,
5+
}) => {
6+
await page.route('**/cities/index.ts', async (route) => {
7+
const response = await route.fetch()
8+
let content = await response.text()
9+
content = content.replace(
10+
'export function searchCities',
11+
'function searchCities',
12+
)
13+
const instrumentedCode = `
14+
// code below is added by the test:
15+
window.__epicshop = { clearSearchCitiesCalls: () => window.__epicshop.searchCitiesCalls = [] }
16+
window.__epicshop.clearSearchCitiesCalls()
17+
18+
function searchCitiesInstrumented(...args) {
19+
window.__epicshop.searchCitiesCalls.push(args)
20+
return searchCities(...args)
21+
}
22+
23+
export { searchCitiesInstrumented as searchCities }
24+
`
25+
content = `${content}\n\n${instrumentedCode}`
26+
27+
route.fulfill({ body: content, headers: response.headers() })
28+
})
29+
await page.goto('/')
30+
await page.waitForLoadState('networkidle')
31+
32+
await page.evaluate(() => (window as any).__epicshop.clearSearchCitiesCalls())
33+
await page.getByRole('button', { name: /force/i }).click()
34+
const searchCitiesCalls: Array<Array<string>> = await page.evaluate(
35+
() => (window as any).__epicshop.searchCitiesCalls,
36+
)
37+
38+
expect(
39+
searchCitiesCalls,
40+
'🚨 searchCities was called when clicking force rerender. Because nothing changed in the user input when clicking that button, searchCities should not have been called. Wrap searchCities inside useMemo with the input as a dependency to fix this.',
41+
).toHaveLength(0)
42+
})

exercises/05.calculations/01.solution.use-memo/tests/todo.test.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)