diff --git a/tests/integration/cli/build-watch/build.test.ts b/tests/integration/cli/build-watch/build.test.ts index dd9d6d189..545c1f4b5 100644 --- a/tests/integration/cli/build-watch/build.test.ts +++ b/tests/integration/cli/build-watch/build.test.ts @@ -58,11 +58,12 @@ export default defineConfig({ describe('build --watch should handle add / change / unlink', async () => { test('basic', async () => { const tempSrcPath = path.join(__dirname, 'test-temp-src'); + const tempConfigFile = path.join(__dirname, 'test-temp-rslib.config.mjs'); await fse.remove(tempSrcPath); await fse.remove(path.join(__dirname, 'dist')); - await fse.copy(path.join(__dirname, 'src'), path.resolve(tempSrcPath)); - const tempConfigFile = path.join(__dirname, 'test-temp-rslib.config.mjs'); await fse.remove(tempConfigFile); + + await fse.copy(path.join(__dirname, 'src'), path.resolve(tempSrcPath)); fse.outputFileSync( tempConfigFile, `import { defineConfig } from '@rslib/core'; @@ -102,11 +103,11 @@ export default defineConfig({ shell: true, }, ); - await awaitFileExists(distIndexFile); fse.outputFileSync(srcFooFile, `export const foo = 'foo';`); fse.outputFileSync(srcFoo2File, `export const foo2 = 'foo2';`); + await awaitFileExists(distFooFile); await awaitFileExists(distFoo2File); const content1 = await fse.readFile(distFooFile, 'utf-8'); expect(content1!).toMatchInlineSnapshot(` @@ -126,7 +127,7 @@ export default defineConfig({ fse.removeSync(srcIndexFile); // change - const wait = await awaitFileChanges(distFooFile); + const wait = await awaitFileChanges(distFooFile, 'foo1'); fse.outputFileSync(srcFooFile, `export const foo = 'foo1';`); await wait(); const content3 = await fse.readFile(distFooFile, 'utf-8'); diff --git a/tests/scripts/helper.ts b/tests/scripts/helper.ts index 83b52f0ba..22e7e6d3c 100644 --- a/tests/scripts/helper.ts +++ b/tests/scripts/helper.ts @@ -95,13 +95,16 @@ export const awaitFileExists = async (dir: string) => { } }; -export const awaitFileChanges = async (file: string) => { +export const awaitFileChanges = async (file: string, content: string) => { const oldContent = await fse.readFile(file, 'utf-8'); return async () => { const result = await waitFor( () => { try { - return fse.readFileSync(file, 'utf-8') !== oldContent; + return ( + fse.readFileSync(file, 'utf-8') !== oldContent && + fse.readFileSync(file, 'utf-8').includes(content) + ); } catch (e) { return false; }