|
8 | 8 | */
|
9 | 9 |
|
10 | 10 | import ts from 'typescript'
|
| 11 | +import { platform } from 'node:os' |
11 | 12 | import { test } from '@japa/runner'
|
| 13 | +import { join, sep } from 'node:path' |
12 | 14 | import { cliui } from '@poppinss/cliui'
|
13 | 15 | import { setTimeout as sleep } from 'node:timers/promises'
|
| 16 | + |
14 | 17 | import { DevServer } from '../index.ts'
|
15 |
| -import { join, sep } from 'node:path' |
16 |
| -import { platform } from 'node:os' |
| 18 | + |
| 19 | +/** |
| 20 | + * When filePath using backward slashes is written to a file, the backslashes |
| 21 | + * are considered as escape charcaters, hence results in a wrong path. |
| 22 | + * |
| 23 | + * This method replaces the backward slashes with two backward slashes |
| 24 | + */ |
| 25 | +function normalizePathForWindows(filePath: string) { |
| 26 | + if (platform() === 'win32') { |
| 27 | + filePath = filePath.split(sep).join('\\\\') |
| 28 | + } |
| 29 | + return filePath |
| 30 | +} |
17 | 31 |
|
18 | 32 | test.group('DevServer', () => {
|
19 | 33 | test('start() and execute dev server hook', async ({ fs, assert, cleanup }) => {
|
@@ -215,16 +229,10 @@ test.group('DevServer', () => {
|
215 | 229 | }).timeout(8 * 1000)
|
216 | 230 |
|
217 | 231 | test('restart server if hot-hook:full-reload message is received', async ({ assert, fs }) => {
|
218 |
| - let filePath = join(fs.basePath, 'start/routes.ts') |
219 |
| - if (platform() === 'win32') { |
220 |
| - filePath = filePath.split(sep).join('\\\\') |
221 |
| - console.log({ filePath }) |
222 |
| - } |
223 |
| - |
224 | 232 | await fs.createJson('tsconfig.json', { include: ['**/*'], exclude: [] })
|
225 | 233 | await fs.create(
|
226 | 234 | 'bin/server.ts',
|
227 |
| - `process.send({ type: 'hot-hook:full-reload', path: "${filePath}" });` |
| 235 | + `process.send({ type: 'hot-hook:full-reload', path: '${normalizePathForWindows(join(fs.basePath, 'start/routes.ts'))}' });` |
228 | 236 | )
|
229 | 237 | await fs.dump('bin/server.ts')
|
230 | 238 | await fs.create('start/routes.ts', ``)
|
@@ -256,7 +264,7 @@ test.group('DevServer', () => {
|
256 | 264 | await fs.createJson('tsconfig.json', { include: ['**/*'], exclude: [] })
|
257 | 265 | await fs.create(
|
258 | 266 | 'bin/server.ts',
|
259 |
| - `process.send({ type: 'hot-hook:invalidated', path: '${join(fs.basePath, 'start/routes.ts')}' });` |
| 267 | + `process.send({ type: 'hot-hook:invalidated', path: '${normalizePathForWindows(join(fs.basePath, 'start/routes.ts'))}' });` |
260 | 268 | )
|
261 | 269 | await fs.create('start/routes.ts', ``)
|
262 | 270 | await fs.create('.env', 'PORT=3334')
|
@@ -285,7 +293,7 @@ test.group('DevServer', () => {
|
285 | 293 | await fs.createJson('tsconfig.json', { include: ['**/*'], exclude: [] })
|
286 | 294 | await fs.create(
|
287 | 295 | 'bin/server.ts',
|
288 |
| - `process.send({ type: 'hot-hook:file-changed', action: 'change', path: '${join(fs.basePath, 'start/routes.ts')}' });` |
| 296 | + `process.send({ type: 'hot-hook:file-changed', action: 'change', path: '${normalizePathForWindows(join(fs.basePath, 'start/routes.ts'))}' });` |
289 | 297 | )
|
290 | 298 | await fs.create('start/routes.ts', ``)
|
291 | 299 | await fs.create('.env', 'PORT=3334')
|
|
0 commit comments