Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add default exportConditions for both jsdom and node environments #11924

Merged
merged 10 commits into from Feb 9, 2022
3 changes: 3 additions & 0 deletions CHANGELOG.md
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
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
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 {
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
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
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
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
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