Skip to content

Commit bd8bf3d

Browse files
committed
chore: wait to kill processes
1 parent 5d6a551 commit bd8bf3d

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ on:
77
schedule:
88
- cron: '0 0 * * *'
99

10+
concurrency:
11+
group: ${{ github.head_ref }}
12+
cancel-in-progress: true
13+
1014
jobs:
1115
build:
1216
name: Unit tests

test/index.spec.js

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,6 +1788,13 @@ describe('onPreDev', () => {
17881788

17891789
const watcherPath = require.resolve('@netlify/plugin-nextjs/lib/helpers/watcher')
17901790

1791+
// Kill the process and resolve a promise when the process exits
1792+
const killProcess = (process) =>
1793+
new Promise((resolve) => {
1794+
process.on('exit', resolve)
1795+
process.kill()
1796+
})
1797+
17911798
describe('the dev middleware watcher', () => {
17921799
it.skip('should compile once and exit if run with the --once flag', async () => {
17931800
await moveNextDist('.next', true)
@@ -1817,7 +1824,8 @@ describe('the dev middleware watcher', () => {
18171824
const watcher = execa.node(watcherPath, [process.cwd()])
18181825
await wait()
18191826
expect(middlewareExists()).toBeTruthy()
1820-
expect(watcher.kill()).toBeTruthy()
1827+
await killProcess(watcher)
1828+
expect(watcher.killed).toBeTruthy()
18211829
})
18221830

18231831
it('should compile a file if it is written after the watcher starts', async () => {
@@ -1828,7 +1836,8 @@ describe('the dev middleware watcher', () => {
18281836
await writeFile(path.join(process.cwd(), 'middleware.ts'), middlewareSourceTs)
18291837
await wait()
18301838
expect(middlewareExists()).toBeTruthy()
1831-
expect(watcher.kill()).toBeTruthy()
1839+
await killProcess(watcher)
1840+
expect(watcher.killed).toBeTruthy()
18321841
})
18331842

18341843
it('should remove the output if the middleware is removed after the watcher starts', async () => {
@@ -1843,7 +1852,8 @@ describe('the dev middleware watcher', () => {
18431852
await unlink(path.join(process.cwd(), 'middleware.ts'))
18441853
await wait()
18451854
expect(middlewareExists()).toBeFalsy()
1846-
expect(watcher.kill()).toBeTruthy()
1855+
await killProcess(watcher)
1856+
expect(watcher.killed).toBeTruthy()
18471857
})
18481858

18491859
it.skip('should remove the output if invalid middleware is written after the watcher starts', async () => {
@@ -1857,7 +1867,8 @@ describe('the dev middleware watcher', () => {
18571867
await writeFile(path.join(process.cwd(), 'middleware.ts'), 'this is not valid middleware')
18581868
await wait()
18591869
expect(middlewareExists()).toBeFalsy()
1860-
expect(watcher.kill()).toBeTruthy()
1870+
await killProcess(watcher)
1871+
expect(watcher.killed).toBeTruthy()
18611872
})
18621873

18631874
it.skip('should recompile the middleware if it is moved into the src directory after the watcher starts', async () => {
@@ -1872,7 +1883,8 @@ describe('the dev middleware watcher', () => {
18721883
await move(path.join(process.cwd(), 'middleware.ts'), path.join(process.cwd(), 'src', 'middleware.ts'))
18731884
await wait()
18741885
expect(middlewareExists()).toBeTruthy()
1875-
expect(watcher.kill()).toBeTruthy()
1886+
await killProcess(watcher)
1887+
expect(watcher.killed).toBeTruthy()
18761888
})
18771889

18781890
it.skip('should recompile the middleware if it is moved into the root directory after the watcher starts', async () => {
@@ -1886,7 +1898,8 @@ describe('the dev middleware watcher', () => {
18861898
await move(path.join(process.cwd(), 'src', 'middleware.ts'), path.join(process.cwd(), 'middleware.ts'))
18871899
await wait()
18881900
expect(middlewareExists()).toBeTruthy()
1889-
expect(watcher.kill()).toBeTruthy()
1901+
await killProcess(watcher)
1902+
expect(watcher.killed).toBeTruthy()
18901903
})
18911904

18921905
it.skip('should compile the middleware if invalid source is replaced with valid source after the watcher starts', async () => {
@@ -1900,7 +1913,8 @@ describe('the dev middleware watcher', () => {
19001913
await writeFile(path.join(process.cwd(), 'middleware.ts'), middlewareSourceTs)
19011914
await wait()
19021915
expect(middlewareExists()).toBeTruthy()
1903-
expect(watcher.kill()).toBeTruthy()
1916+
await killProcess(watcher)
1917+
expect(watcher.killed).toBeTruthy()
19041918
})
19051919

19061920
it.skip('should not compile middleware if more than one middleware file exists', async () => {
@@ -1912,7 +1926,8 @@ describe('the dev middleware watcher', () => {
19121926
const watcher = execa.node(watcherPath, [process.cwd()])
19131927
await wait()
19141928
expect(middlewareExists()).toBeFalsy()
1915-
expect(watcher.kill()).toBeTruthy()
1929+
await killProcess(watcher)
1930+
expect(watcher.killed).toBeTruthy()
19161931
})
19171932

19181933
it.skip('should not compile middleware if a second middleware file is added after the watcher starts', async () => {
@@ -1926,7 +1941,8 @@ describe('the dev middleware watcher', () => {
19261941
await writeFile(path.join(process.cwd(), 'middleware.js'), middlewareSourceJs)
19271942
await wait()
19281943
expect(middlewareExists()).toBeFalsy()
1929-
expect(watcher.kill()).toBeTruthy()
1944+
await killProcess(watcher)
1945+
expect(watcher.killed).toBeTruthy()
19301946
})
19311947

19321948
it.skip('should compile middleware if a second middleware file is removed after the watcher starts', async () => {
@@ -1941,7 +1957,8 @@ describe('the dev middleware watcher', () => {
19411957
await unlink(path.join(process.cwd(), 'middleware.js'))
19421958
await wait()
19431959
expect(middlewareExists()).toBeTruthy()
1944-
expect(watcher.kill()).toBeTruthy()
1960+
await killProcess(watcher)
1961+
expect(watcher.killed).toBeTruthy()
19451962
})
19461963

19471964
it.skip('should generate the correct output for each case when middleware is compiled, added, removed and for error states', async () => {
@@ -1975,6 +1992,7 @@ describe('the dev middleware watcher', () => {
19751992
expect(stdioString).toContain('Multiple middleware files found')
19761993
expect(middlewareExists()).toBeFalsy()
19771994

1978-
expect(watcher.kill()).toBeTruthy()
1995+
await killProcess(watcher)
1996+
expect(watcher.killed).toBeTruthy()
19791997
})
19801998
})

0 commit comments

Comments
 (0)