Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 53 additions & 3 deletions e2e/browser-mode/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,35 @@ export const shouldRunHeadedBrowserTests =
canRunHeadedBrowser &&
Boolean(process.env.CI || process.env.RSTEST_E2E_RUN_HEADED);

/**
* Framework-level warnings that the build pipeline must not emit. Browser-mode
* tests launch rstest as a subprocess, so any Rsbuild/Rspack build warning or
* Node deprecation notice lands in `cli.stdout`/`cli.stderr` and is otherwise
* swallowed by the parent test runner. Asserting against this pattern turns
* silent regressions (e.g. a dynamic import losing its `webpackIgnore` magic
* comment) into explicit test failures.
*/
const FRAMEWORK_WARNING_PATTERN =
/Build warning:|Critical dependency:|DeprecationWarning:|\[MODULE_TYPELESS_PACKAGE_JSON\]/;

export const expectNoFrameworkWarnings = (cli: {
stdout: string;
stderr: string;
}): void => {
if (
!FRAMEWORK_WARNING_PATTERN.test(cli.stdout) &&
!FRAMEWORK_WARNING_PATTERN.test(cli.stderr)
) {
return;
}
const offending = `${cli.stdout}\n${cli.stderr}`
.split('\n')
.filter((line) => FRAMEWORK_WARNING_PATTERN.test(line));
throw new Error(
`Expected no framework warnings in CLI output, found:\n${offending.join('\n')}`,
);
};

/**
* Run browser mode CLI with specified fixture
*/
Expand All @@ -44,7 +73,7 @@ export const runBrowserCli = async (
) => {
const args = extra?.args || [];

return await runRstestCli({
const result = await runRstestCli({
command: 'rstest',
args: ['run', ...args],
options: {
Expand All @@ -54,6 +83,13 @@ export const runBrowserCli = async (
},
},
});
return {
...result,
expectExecSuccess: async () => {
await result.expectExecSuccess();
expectNoFrameworkWarnings(result.cli);
},
};
};

/**
Expand All @@ -66,7 +102,7 @@ export const runBrowserWatchCli = async (
env?: Record<string, string>;
},
) => {
return await runRstestCli({
const result = await runRstestCli({
command: 'rstest',
args: ['watch', '--disableConsoleIntercept', ...(extra?.args || [])],
options: {
Expand All @@ -76,6 +112,13 @@ export const runBrowserWatchCli = async (
},
},
});
return {
...result,
expectExecSuccess: async () => {
await result.expectExecSuccess();
expectNoFrameworkWarnings(result.cli);
},
};
};

/**
Expand All @@ -88,7 +131,7 @@ export const runBrowserCliWithCwd = async (
env?: Record<string, string>;
},
) => {
return await runRstestCli({
const result = await runRstestCli({
command: 'rstest',
args: ['run', ...(extra?.args || [])],
options: {
Expand All @@ -98,4 +141,11 @@ export const runBrowserCliWithCwd = async (
},
},
});
return {
...result,
expectExecSuccess: async () => {
await result.expectExecSuccess();
expectNoFrameworkWarnings(result.cli);
},
};
};
Loading