From fb1d14ca195fe835013fc4cd5d623c3140f60e4a Mon Sep 17 00:00:00 2001 From: Qingyu Wang Date: Fri, 27 Feb 2026 15:38:57 +0800 Subject: [PATCH 1/2] test: ensure proper error handling for invalid config --- test/error-handling/index.test.ts | 34 +++++++++++++++++++++++++++++++ test/error-handling/src/index.js | 1 + 2 files changed, 35 insertions(+) create mode 100644 test/error-handling/index.test.ts create mode 100644 test/error-handling/src/index.js diff --git a/test/error-handling/index.test.ts b/test/error-handling/index.test.ts new file mode 100644 index 0000000..dbc13be --- /dev/null +++ b/test/error-handling/index.test.ts @@ -0,0 +1,34 @@ +import { dirname } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { expect, test } from '@playwright/test'; +import { createRsbuild } from '@rsbuild/core'; +import { pluginTailwindCSS } from '../../src'; + +const __dirname = dirname(fileURLToPath(import.meta.url)); + +test('should fail with clear error when config file is missing', async () => { + const rsbuild = await createRsbuild({ + cwd: __dirname, + rsbuildConfig: { + plugins: [ + pluginTailwindCSS({ + config: './does-not-exist.js', + }), + ], + }, + }); + + // We expect the build to fail + try { + await rsbuild.build(); + // If it doesn't fail, fail the test + expect(true).toBe(false); + } catch (err: unknown) { + const error = err as Error; + // Check for error message + // Rsbuild might wrap the error, so we check for generic failure or specific message + expect(error.message).toMatch( + /Rspack build failed|Cannot find module|ENOENT|no such file/i, + ); + } +}); diff --git a/test/error-handling/src/index.js b/test/error-handling/src/index.js new file mode 100644 index 0000000..75f4f0f --- /dev/null +++ b/test/error-handling/src/index.js @@ -0,0 +1 @@ +console.log('Error handling test'); From 3dfdab52963b92a983373f24cbe167279f0bbc59 Mon Sep 17 00:00:00 2001 From: Qingyu Wang <40660121+colinaaa@users.noreply.github.com> Date: Fri, 27 Feb 2026 16:15:38 +0800 Subject: [PATCH 2/2] Update test/error-handling/index.test.ts Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- test/error-handling/index.test.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/error-handling/index.test.ts b/test/error-handling/index.test.ts index dbc13be..41c6fe3 100644 --- a/test/error-handling/index.test.ts +++ b/test/error-handling/index.test.ts @@ -21,8 +21,7 @@ test('should fail with clear error when config file is missing', async () => { // We expect the build to fail try { await rsbuild.build(); - // If it doesn't fail, fail the test - expect(true).toBe(false); + throw new Error('Build was expected to fail, but it succeeded.'); } catch (err: unknown) { const error = err as Error; // Check for error message