diff --git a/src/watch/index.ts b/src/watch/index.ts index 91f52a9ec..8629ade9e 100644 --- a/src/watch/index.ts +++ b/src/watch/index.ts @@ -245,9 +245,11 @@ export const watchCommand = command({ ).on('all', reRun); if (resolvedIncludes.length > 0) { - const globParents = resolvedIncludes.map(pattern => (isGlob(pattern) - ? globParent(pattern) - : pattern)); + const globParents = resolvedIncludes.map(pattern => ( + isGlob(pattern) + ? globParent(pattern) + : pattern + )); watch(globParents, { cwd: process.cwd(), @@ -255,8 +257,13 @@ export const watchCommand = command({ ignorePermissionErrors: true, // ignore all files not in includes or explicitly excluded // we need to make sure not to ignore directories otherwise chokidar won't check for it - ignored: file => !globParents.includes(file) - && (!isOptionsInclude(file) || isOptionsExclude(file)), + ignored: file => ( + !globParents.includes(file) + && ( + !isOptionsInclude(file) + || isOptionsExclude(file) + ) + ), }).on('all', reRun); } diff --git a/tests/specs/watch.ts b/tests/specs/watch.ts index 66b0740f9..acae26fa5 100644 --- a/tests/specs/watch.ts +++ b/tests/specs/watch.ts @@ -225,7 +225,8 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { describe('include', ({ test }) => { test('file path & glob', async () => { const entryFile = 'index.js'; - const fileA = 'file-a'; + // Watches hidden file + const fileA = '.file-a'; const fileB = 'directory/file-b'; await using fixture = await createFixture({ [entryFile]: ` @@ -363,7 +364,7 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { const fileB = 'directory/file-b.js'; const depA = 'node_modules/a/index.js'; - await using fixtureGlob = await createFixture({ + await using fixture = await createFixture({ [fileA]: 'export default "logA"', [fileB]: 'export default "logB"', [depA]: 'export default "logC"', @@ -380,11 +381,11 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { 'watch', '--clear-screen=false', `--ignore=../${fileA}`, - '--ignore=abra.js', + '--ignore=doesnt-exist.js', '--exclude=../directory/*', 'index.js', ], - path.join(fixtureGlob.path, 'process-directory'), + fixture.getPath('process-directory'), ); onTestFail(async () => { @@ -411,13 +412,13 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { if (data === 'logA logB logC\n') { // These changes should not trigger a re-run await Promise.all([ - fixtureGlob.writeFile(fileA, `export default "${negativeSignal}"`), - fixtureGlob.writeFile(fileB, `export default "${negativeSignal}"`), - fixtureGlob.writeFile(depA, `export default "${negativeSignal}"`), + fixture.writeFile(fileA, `export default "${negativeSignal}"`), + fixture.writeFile(fileB, `export default "${negativeSignal}"`), + fixture.writeFile(depA, `export default "${negativeSignal}"`), ]); await setTimeout(1000); - fixtureGlob.writeFile(entryFile, 'console.log("TERMINATE")'); + fixture.writeFile(entryFile, 'console.log("TERMINATE")'); return true; } },