Skip to content

Commit

Permalink
feat: add default exportConditions for both jsdom and node envi…
Browse files Browse the repository at this point in the history
…ronments (#11924)
  • Loading branch information
piranna committed Feb 9, 2022
1 parent 7e484b2 commit 432dfb6
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 12 deletions.
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

0 comments on commit 432dfb6

Please sign in to comment.