Skip to content

Commit 432dfb6

Browse files
authored
feat: add default exportConditions for both jsdom and node environments (#11924)
1 parent 7e484b2 commit 432dfb6

9 files changed

Lines changed: 32 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
### Features
44

5+
- `[jest-environment-jsdom]` [**BREAKING**] Add default `browser` condtion to `exportConditions` for `jsdom` environment ([#11924](https://github.com/facebook/jest/pull/11924))
6+
- `[jest-environment-node]` [**BREAKING**] Add default `node` and `node-addon` conditions to `exportConditions` for `node` environment ([#11924](https://github.com/facebook/jest/pull/11924))
7+
58
### Fixes
69

710
### Chore & Maintenance

e2e/resolve-conditions/__tests__/browser.test.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @jest-environment <rootDir>/browser-env.js
7+
* @jest-environment jest-environment-jsdom
88
*/
99

1010
import {fn} from 'fake-dual-dep';

e2e/resolve-conditions/browser-env.js renamed to e2e/resolve-conditions/__tests__/deno.test.mjs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
*
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @jest-environment <rootDir>/deno-env.js
68
*/
79

8-
'use strict';
9-
10-
const BrowserEnv = require('jest-environment-jsdom');
10+
import {fn} from 'fake-dual-dep';
1111

12-
module.exports = class BrowserEnvWithConditions extends BrowserEnv {
13-
exportConditions() {
14-
return ['browser'];
15-
}
16-
};
12+
test('returns correct message', () => {
13+
expect(fn()).toEqual('hello from deno');
14+
});

e2e/resolve-conditions/__tests__/node.test.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @jest-environment <rootDir>/node-env.js
7+
* @jest-environment jest-environment-node
88
*/
99

1010
import {fn} from 'fake-dual-dep';
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
const NodeEnv = require('jest-environment-node');
1111

12-
module.exports = class NodeEnvWithConditions extends NodeEnv {
12+
module.exports = class DenoEnvWithConditions extends NodeEnv {
1313
exportConditions() {
14-
return ['node'];
14+
return ['deno'];
1515
}
1616
};

e2e/resolve-conditions/node_modules/fake-dual-dep/deno.mjs

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

e2e/resolve-conditions/node_modules/fake-dual-dep/package.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/jest-environment-jsdom/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ class JSDOMEnvironment implements JestEnvironment<number> {
149149
this.fakeTimersModern = null;
150150
}
151151

152+
exportConditions(): Array<string> {
153+
return ['browser'];
154+
}
155+
152156
getVmContext(): Context | null {
153157
if (this.dom) {
154158
return this.dom.getInternalVMContext();

packages/jest-environment-node/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ class NodeEnvironment implements JestEnvironment<Timer> {
133133
this.fakeTimersModern = null;
134134
}
135135

136+
exportConditions(): Array<string> {
137+
return ['node', 'node-addons'];
138+
}
139+
136140
getVmContext(): Context | null {
137141
return this.context;
138142
}

0 commit comments

Comments
 (0)