From 38f1c6ccc642e941f65f5b2b370116804827801b Mon Sep 17 00:00:00 2001 From: "William.Tung" Date: Sat, 3 Jun 2023 16:50:28 +0800 Subject: [PATCH] fix: detect file changes on Windows (#234) closes https://github.com/eggjs/egg-bin/issues/233 --- src/cmd/test.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/cmd/test.ts b/src/cmd/test.ts index 3cd8858a..b47216bd 100644 --- a/src/cmd/test.ts +++ b/src/cmd/test.ts @@ -152,7 +152,7 @@ export class TestCommand extends BaseCommand { pattern = process.env.TESTS.split(','); } - // collect test files + // collect test files when nothing is changed if (!pattern.length) { pattern = [ `test/**/*.test.${ext}` ]; } @@ -196,10 +196,15 @@ export class TestCommand extends BaseCommand { const res = await getChangedFilesForRoots([ path.join(dir, 'test') ], {}); const changedFiles = res.changedFiles; const files: string[] = []; - for (const file of changedFiles) { + for (let cf of changedFiles) { // only find test/**/*.test.(js|ts) - if (file.endsWith(`.test.${ext}`)) { - files.push(file); + if (cf.endsWith(`.test.${ext}`)) { + // Patterns MUST use forward slashes (not backslashes) + // This should be converted on Windows + if (process.platform === 'win32') { + cf = cf.replace(/\\/g, '/'); + } + files.push(cf); } } return files;