From beeb2a8890ce2ebef63466ed19d6b1144f8d1e2d Mon Sep 17 00:00:00 2001 From: 9aoy Date: Fri, 24 Jan 2025 15:55:15 +0800 Subject: [PATCH] test: fix occasional `directory not empty` error in e2e (#4428) --- e2e/cases/cli/watch-files/index.test.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/e2e/cases/cli/watch-files/index.test.ts b/e2e/cases/cli/watch-files/index.test.ts index 702c01a0dd..ecbf0ca348 100644 --- a/e2e/cases/cli/watch-files/index.test.ts +++ b/e2e/cases/cli/watch-files/index.test.ts @@ -5,6 +5,7 @@ import { awaitFileExists, getRandomPort, rspackOnlyTest } from '@e2e/helper'; import { expect, test } from '@playwright/test'; const dist = path.join(__dirname, 'dist'); +const distIndexFile = path.join(__dirname, 'dist/static/js/index.js'); const tempConfigPath = './test-temp-config.ts'; const tempOutputFile = path.join(__dirname, 'test-temp-file.txt'); const extraConfigFile = path.join(__dirname, tempConfigPath); @@ -29,7 +30,7 @@ rspackOnlyTest( }); // the first build - await awaitFileExists(dist); + await awaitFileExists(distIndexFile); fs.rmSync(tempOutputFile, { force: true }); // temp config changed and trigger rebuild @@ -55,9 +56,9 @@ rspackOnlyTest( }, }); - await awaitFileExists(dist); + await awaitFileExists(distIndexFile); - fs.rmSync(dist, { recursive: true }); + fs.rmSync(distIndexFile); // temp config changed fs.writeFileSync(extraConfigFile, 'export default 2;'); @@ -79,9 +80,11 @@ rspackOnlyTest( }, }); - await awaitFileExists(dist); + // Fix occasional 'directory not empty' error when wait and rm dist. + // Sometimes the dist directory exists, but the files in the dist directory have not been completely written. + await awaitFileExists(distIndexFile); - fs.rmSync(dist, { recursive: true }); + fs.rmSync(distIndexFile); // temp config changed fs.writeFileSync(extraConfigFile, 'export default 2;');