test(e2e): add helper to assert no logs#5877
Conversation
✅ Deploy Preview for rsbuild ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull Request Overview
This PR refactors logging test utilities by replacing manual log checks with standardized helper methods and cleaning up test setup code.
- Renamed
createLogMatchertocreateLogHelperfor better clarity - Added new
expectNoLoghelper method to complement existingexpectLogfunctionality - Removed unnecessary file deletion operations in test setup code
Reviewed Changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| e2e/helper/logs.ts | Added expectNoLog helper and renamed function/types for clarity |
| e2e/helper/jsApi.ts | Updated variable names to use singular logHelper consistently |
| e2e/helper/cli.ts | Simplified helper usage by spreading all methods from logHelper |
| e2e/cases/server/overlay/index.test.ts | Updated import to use renamed createLogHelper |
| e2e/cases/server/overlay-type-errors/index.test.ts | Updated import to use renamed createLogHelper |
| e2e/cases/rsdoctor/index.test.ts | Replaced manual log checks with expectLog/expectNoLog helpers |
| e2e/cases/print-file-size/with-error/index.test.ts | Replaced manual log check with expectNoLog helper |
| e2e/cases/lazy-compilation/port-placeholder/index.test.ts | Replaced manual log check with expectNoLog helper |
| e2e/cases/lazy-compilation/dynamic-import/index.test.ts | Replaced manual log check with expectNoLog helper and removed unused import |
| e2e/cases/lazy-compilation/basic/index.test.ts | Replaced manual log checks with expectNoLog helper |
| e2e/cases/css/import-common-css/index.test.ts | Removed manual log check code |
| e2e/cases/css/enable-experiments-css/index.test.ts | Replaced manual log checks with expectNoLog helper |
| e2e/cases/config/stats-options/index.test.ts | Replaced manual log checks with expectLog/expectNoLog helpers |
| e2e/cases/config/inspect-config/index.test.ts | Replaced manual log checks with expectLog helper |
| e2e/cases/config/debug-mode/index.test.ts | Replaced manual log checks with expectLog helper |
| e2e/cases/cli/watch-files/index.test.ts | Removed unnecessary file deletion in test setup |
| e2e/cases/cli/watch-files-array/index.test.ts | Removed unnecessary file deletion in test setup |
| e2e/cases/cli/reload-env/index.test.ts | Removed file deletions and added proper async log expectations |
| e2e/cases/cli/build-watch/index.test.ts | Removed unnecessary file deletions in test setup |
| e2e/cases/cli/build-watch-restart/index.test.ts | Improved test flow with proper async expectations and removed file deletions |
| e2e/cases/cli/build-watch-options/index.test.ts | Replaced manual log check with expectNoLog helper |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| }); | ||
| }; | ||
|
|
||
| const expectNoLog = (pattern: LogPattern) => { |
There was a problem hiding this comment.
The expectNoLog function returns a boolean synchronously, which is inconsistent with expectLog that returns a Promise. This could cause issues when used with await statements in test files. Consider making this function async or removing the return statement to match the pattern of other expectation functions.
| const expectNoLog = (pattern: LogPattern) => { | |
| const expectNoLog = async (pattern: LogPattern) => { |
| expect( | ||
| logs.some((log) => log.includes('@rsdoctor') && log.includes('enabled')), | ||
| ).toBe(false); | ||
| expectNoLog(RSDOCTOR_LOG); |
There was a problem hiding this comment.
The expectNoLog call is missing await. Since this function is used in an async context and other expectLog calls are awaited, this should also be awaited for consistency and proper test execution flow.
| expectNoLog(RSDOCTOR_LOG); | |
| await expectNoLog(RSDOCTOR_LOG); |
| expect( | ||
| logs.some((log) => log.includes('@rsdoctor') && log.includes('enabled')), | ||
| ).toBe(false); | ||
| expectNoLog(RSDOCTOR_LOG); |
There was a problem hiding this comment.
The expectNoLog call is missing await. Since this function is used in an async context and other expectLog calls are awaited, this should also be awaited for consistency and proper test execution flow.
| expectNoLog(RSDOCTOR_LOG); | |
| await expectNoLog(RSDOCTOR_LOG); |
|
|
||
| expect(rsbuild.buildError).toBeTruthy(); | ||
| expect(rsbuild.logs.some((log) => log.includes('Total:'))).toBeFalsy(); | ||
| rsbuild.expectNoLog('Total:'); |
There was a problem hiding this comment.
The expectNoLog call is missing await. Since this is used in an async test context, it should be awaited for proper test execution.
| rsbuild.expectNoLog('Total:'); | |
| await rsbuild.expectNoLog('Total:'); |
| expect( | ||
| rsbuild.logs.some((log) => log.includes('building src/page2/index.js')), | ||
| ).toBeFalsy(); | ||
| rsbuild.expectNoLog('building src/page2/index.js'); |
There was a problem hiding this comment.
The expectNoLog call is missing await. Since this is used in an async test context and other expectLog calls are awaited, this should also be awaited for consistency.
| rsbuild.expectNoLog('building src/page2/index.js'); | |
| await rsbuild.expectNoLog('building src/page2/index.js'); |
| expect( | ||
| rsbuild.logs.some((log) => log.includes('building src/page2/index.js')), | ||
| ).toBeFalsy(); | ||
| rsbuild.expectNoLog('building src/page2/index.js'); |
There was a problem hiding this comment.
The expectNoLog call is missing await. Since this is used in an async test context and other expectLog calls are awaited, this should also be awaited for consistency.
| rsbuild.expectNoLog('building src/page2/index.js'); | |
| await rsbuild.expectNoLog('building src/page2/index.js'); |
| expect( | ||
| rsbuild.logs.some((log) => log.includes('Compile Warning')), | ||
| ).toBeFalsy(); | ||
| rsbuild.expectNoLog(COMPILE_WARNING); |
There was a problem hiding this comment.
The expectNoLog call is missing await. Since this is used in an async test context, it should be awaited for proper test execution.
| rsbuild.expectNoLog(COMPILE_WARNING); | |
| await rsbuild.expectNoLog(COMPILE_WARNING); |
| expect( | ||
| rsbuild.logs.some((log) => log.includes('Compile Warning')), | ||
| ).toBeFalsy(); | ||
| rsbuild.expectNoLog(COMPILE_WARNING); |
There was a problem hiding this comment.
The expectNoLog call is missing await. Since this is used in an async test context, it should be awaited for proper test execution.
| rsbuild.expectNoLog(COMPILE_WARNING); | |
| await rsbuild.expectNoLog(COMPILE_WARNING); |
| ), | ||
| ).toBeFalsy(); | ||
|
|
||
| rsbuild.expectNoLog(WARNING_MSG); |
There was a problem hiding this comment.
The expectNoLog call is missing await. Since this is used in an async test context and other expectLog calls are awaited, this should also be awaited for consistency.
| rsbuild.expectNoLog(WARNING_MSG); | |
| await rsbuild.expectNoLog(WARNING_MSG); |
| expect( | ||
| logs.some((log) => /building test-temp-src[\\/]bar.js/.test(log)), | ||
| ).toBeFalsy(); | ||
| expectNoLog(/building test-temp-src[\\/]bar.js/); |
There was a problem hiding this comment.
The expectNoLog call is missing await. Since this is used in an async test context and other expectLog calls are awaited, this should also be awaited for consistency.
| expectNoLog(/building test-temp-src[\\/]bar.js/); | |
| await expectNoLog(/building test-temp-src[\\/]bar.js/); |

Summary
expectLogandexpectNoLoghelper methodscreateLogMatchertocreateLogHelperfor clarityChecklist