Skip to content
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

### Features

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

### Fixes

### Chore & Maintenance
Expand Down
2 changes: 1 addition & 1 deletion e2e/resolve-conditions/__tests__/browser.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @jest-environment <rootDir>/browser-env.js
* @jest-environment jest-environment-jsdom
*/

import {fn} from 'fake-dual-dep';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @jest-environment <rootDir>/deno-env.js
*/

'use strict';

const BrowserEnv = require('jest-environment-jsdom');
import {fn} from 'fake-dual-dep';

module.exports = class BrowserEnvWithConditions extends BrowserEnv {
Comment thread
piranna marked this conversation as resolved.
exportConditions() {
return ['browser'];
}
};
test('returns correct message', () => {
expect(fn()).toEqual('hello from deno');
});
2 changes: 1 addition & 1 deletion e2e/resolve-conditions/__tests__/node.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @jest-environment <rootDir>/node-env.js
* @jest-environment jest-environment-node
*/

import {fn} from 'fake-dual-dep';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

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

module.exports = class NodeEnvWithConditions extends NodeEnv {
module.exports = class DenoEnvWithConditions extends NodeEnv {
exportConditions() {
return ['node'];
return ['deno'];
}
};
10 changes: 10 additions & 0 deletions e2e/resolve-conditions/node_modules/fake-dual-dep/deno.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/jest-environment-jsdom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ class JSDOMEnvironment implements JestEnvironment<number> {
this.fakeTimersModern = null;
}

exportConditions(): Array<string> {
return ['browser'];
}

getVmContext(): Context | null {
if (this.dom) {
return this.dom.getInternalVMContext();
Expand Down
4 changes: 4 additions & 0 deletions packages/jest-environment-node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ class NodeEnvironment implements JestEnvironment<Timer> {
this.fakeTimersModern = null;
}

exportConditions(): Array<string> {
return ['node', 'node-addons'];
}

getVmContext(): Context | null {
return this.context;
}
Expand Down