Skip to content

Commit df714b4

Browse files
authored
fix(browser): expose process.env.RSTEST in browser mode (#1356)
1 parent 0ffa432 commit df714b4

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

e2e/browser-mode/fixtures/env/tests/env.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,11 @@ describe('browser env injection', () => {
3535
it('should expose NODE_ENV via import.meta.env in browser mode', () => {
3636
expect(import.meta.env.NODE_ENV).toBe('test');
3737
});
38+
39+
it('should expose the RSTEST flag in browser mode', () => {
40+
// Matches Node mode, where `prepare.ts` sets `process.env.RSTEST = 'true'`.
41+
// See https://github.com/web-infra-dev/rstest/issues/1351
42+
expect(process.env.RSTEST).toBe('true');
43+
expect(import.meta.env.RSTEST).toBe('true');
44+
});
3845
});

packages/browser/src/hostController.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -830,11 +830,15 @@ const getRuntimeConfigFromProject = (
830830
} = project.normalizedConfig;
831831

832832
return {
833-
// Propagate NODE_ENV from the host so `import.meta.env.NODE_ENV` resolves
834-
// to `'test'` in browser tests (matches Node mode). User-supplied `env`
835-
// wins so explicit overrides still take effect.
833+
// Propagate NODE_ENV and the RSTEST flag from the host so
834+
// `process.env.NODE_ENV` / `process.env.RSTEST` (rewritten to the
835+
// `rstest.env` symbol store) resolve in browser tests the same way they do
836+
// in Node mode, where `prepare.ts` sets them on the real `process.env`.
837+
// User-supplied `env` wins so explicit overrides still take effect.
838+
// See https://github.com/web-infra-dev/rstest/issues/1351
836839
env: {
837840
NODE_ENV: process.env.NODE_ENV,
841+
RSTEST: 'true',
838842
...env,
839843
},
840844
testNamePattern,

0 commit comments

Comments
 (0)