Skip to content

Commit

Permalink
Merge branch 'main' into refactor-config-normalize
Browse files Browse the repository at this point in the history
  • Loading branch information
mrazauskas committed Apr 20, 2022
2 parents c0c2351 + d2f03ef commit 5f8cb12
Show file tree
Hide file tree
Showing 156 changed files with 1,633 additions and 1,034 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Expand Up @@ -54,5 +54,5 @@ workflows:
name: test-node-partial-<< matrix.node-version >>
matrix:
parameters:
node-version: ['12', '14', '16', '17']
node-version: ['12', '14', '16', '17', '18']
- test-jest-jasmine
9 changes: 3 additions & 6 deletions .eslintrc.cjs
Expand Up @@ -237,10 +237,10 @@ module.exports = {
},
{
files: [
'e2e/**',
'website/**',
'**/__benchmarks__/**',
'**/__tests__/**',
'e2e/**',
'**/pretty-format/perf/**',
'packages/jest-types/**/*',
'.eslintplugin/**',
],
Expand All @@ -263,6 +263,7 @@ module.exports = {
{
files: [
'scripts/*',
'packages/*/__benchmarks__/test.js',
'packages/jest-cli/src/init/index.ts',
'packages/jest-repl/src/cli/runtime-cli.ts',
],
Expand All @@ -274,14 +275,10 @@ module.exports = {
files: [
'e2e/**',
'examples/**',
'scripts/*',
'website/**',
'**/__mocks__/**',
'**/__tests__/**',
'**/__typetests__/**',
'**/__performance_tests__/**',
'packages/diff-sequences/perf/index.js',
'packages/pretty-format/perf/test.js',
],
rules: {
'@typescript-eslint/no-unused-vars': 'off',
Expand Down
18 changes: 16 additions & 2 deletions .github/workflows/nodejs.yml
Expand Up @@ -59,7 +59,7 @@ jobs:
run: yarn verify-old-ts

lint:
name: Running ESLint
name: Running Lint
runs-on: ubuntu-latest
needs: prepare-yarn-cache

Expand All @@ -82,12 +82,26 @@ jobs:
- name: check copyright headers
run: yarn check-copyright-headers

yarn-validate:
name: Validate Yarn constraints
runs-on: ubuntu-latest
needs: prepare-yarn-cache
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: lts/*
cache: yarn
- name: 'Check for unmet constraints (fix w/ "yarn constraints --fix")'
run: |
yarn constraints
test:
name: Node v${{ matrix.node-version }} on ${{ matrix.os }} (${{ matrix.shard }})
strategy:
fail-fast: false
matrix:
node-version: [12.x, 14.x, 16.x, 17.x]
node-version: [12.x, 14.x, 16.x, 17.x, 18.x]
os: [ubuntu-latest, macOS-latest, windows-latest]
shard: ['1/4', '2/4', '3/4', '4/4']
runs-on: ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion .prettierignore
Expand Up @@ -9,7 +9,7 @@ coverage
/packages/*/build
/packages/*/dist
/packages/jest-config/src/__tests__/jest-preset.json
/packages/pretty-format/perf/world.geo.json
/packages/pretty-format/__benchmarks__/world.geo.json

# Breaks tests
/e2e/coverage-handlebars/greet.hbs
Expand Down
31 changes: 0 additions & 31 deletions .yarn/patches/react-native-npm-0.68.0-9eb3ecb60a.patch

This file was deleted.

18 changes: 18 additions & 0 deletions .yarn/patches/react-native-npm-0.68.1-8830b7be0d.patch
@@ -0,0 +1,18 @@
diff --git a/jest/setup.js b/jest/setup.js
index 5bc65447594091c2da6dadb4be6bc1c6da43c7a0..356e7ff3eb55947e084db5d1df9b2d9f0544a15b 100644
--- a/jest/setup.js
+++ b/jest/setup.js
@@ -17,13 +17,8 @@ jest.requireActual('@react-native/polyfills/error-guard');

global.__DEV__ = true;

-global.performance = {
- now: jest.fn(Date.now),
-};
-
global.Promise = jest.requireActual('promise');
global.regeneratorRuntime = jest.requireActual('regenerator-runtime/runtime');
-global.window = global;

global.requestAnimationFrame = function (callback) {
return setTimeout(callback, 0);
52 changes: 52 additions & 0 deletions .yarn/plugins/@yarnpkg/plugin-constraints.cjs

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions .yarnrc.yml
Expand Up @@ -17,16 +17,13 @@ packageExtensions:
react-native-codegen@*:
peerDependencies:
"@babel/preset-env": ^7.1.6
react-native-gradle-plugin@*:
peerDependencies:
"@babel/preset-env": ^7.1.6
react-native@*:
dependencies:
metro-babel-register: 0.67.0
peerDependencies:
"@babel/preset-env": ^7.1.6

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-constraints.cjs
spec: "@yarnpkg/plugin-constraints"
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: "@yarnpkg/plugin-interactive-tools"
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
Expand Down
14 changes: 10 additions & 4 deletions CHANGELOG.md
Expand Up @@ -26,7 +26,7 @@
- `[jest-environment-node]` [**BREAKING**] Add default `node` and `node-addon` conditions to `exportConditions` for `node` environment ([#11924](https://github.com/facebook/jest/pull/11924))
- `[jest-environment-node]` [**BREAKING**] Pass global config to Jest environment constructor for `node` environment ([#12461](https://github.com/facebook/jest/pull/12461))
- `[jest-environment-node]` [**BREAKING**] Second argument `context` to constructor is mandatory ([#12469](https://github.com/facebook/jest/pull/12469))
- `[jest-environment-node]` Add all available globals to test globals, not just explicit ones ([#12642](https://github.com/facebook/jest/pull/12642))
- `[jest-environment-node]` Add all available globals to test globals, not just explicit ones ([#12642](https://github.com/facebook/jest/pull/12642), [#12696](https://github.com/facebook/jest/pull/12696))
- `[@jest/expect]` New module which extends `expect` with `jest-snapshot` matchers ([#12404](https://github.com/facebook/jest/pull/12404), [#12410](https://github.com/facebook/jest/pull/12410), [#12418](https://github.com/facebook/jest/pull/12418))
- `[@jest/expect-utils]` New module exporting utils for `expect` ([#12323](https://github.com/facebook/jest/pull/12323))
- `[@jest/fake-timers]` [**BREAKING**] Rename `timers` configuration option to `fakeTimers` ([#12572](https://github.com/facebook/jest/pull/12572))
Expand All @@ -38,8 +38,8 @@
- `[jest-mock]` [**BREAKING**] Improve the usage of `jest.fn` generic type argument ([#12489](https://github.com/facebook/jest/pull/12489))
- `[jest-mock]` Add support for auto-mocking async generator functions ([#11080](https://github.com/facebook/jest/pull/11080))
- `[jest-mock]` Add `contexts` member to mock functions ([#12601](https://github.com/facebook/jest/pull/12601))
- `[jest-reporters]` Add GitHub Actions reporter ([#11320](https://github.com/facebook/jest/pull/11320), [#12658](https://github.com/facebook/jest/pull/12658)
- `[jest-reporters]` Pass `reporterContext` to custom reporter constructors as third argument ([#12657](https://github.com/facebook/jest/pull/12657))
- `[@jest/reporters]` Add GitHub Actions reporter ([#11320](https://github.com/facebook/jest/pull/11320), [#12658](https://github.com/facebook/jest/pull/12658)
- `[@jest/reporters]` Pass `reporterContext` to custom reporter constructors as third argument ([#12657](https://github.com/facebook/jest/pull/12657))
- `[jest-resolve]` [**BREAKING**] Add support for `package.json` `exports` ([#11961](https://github.com/facebook/jest/pull/11961), [#12373](https://github.com/facebook/jest/pull/12373))
- `[jest-resolve]` Support package self-reference ([#12682](https://github.com/facebook/jest/pull/12682))
- `[jest-resolve, jest-runtime]` Add support for `data:` URI import and mock ([#12392](https://github.com/facebook/jest/pull/12392))
Expand All @@ -50,15 +50,19 @@
- `[jest-runtime]` [**BREAKING**] `Runtime.createHasteMap` now returns a promise ([#12008](https://github.com/facebook/jest/pull/12008))
- `[jest-runtime]` Calling `jest.resetModules` function will clear FS and transform cache ([#12531](https://github.com/facebook/jest/pull/12531))
- `[jest-runtime]` [**BREAKING**] Remove `Context` type export, it must be imported from `@jest/test-result` ([#12685](https://github.com/facebook/jest/pull/12685))
- `[jest-runtime]` Add `import.meta.jest` ([#12698](https://github.com/facebook/jest/pull/12698))
- `[@jest/schemas]` New module for JSON schemas for Jest's config ([#12384](https://github.com/facebook/jest/pull/12384))
- `[@jest/source-map]` Migrate from `source-map` to `@jridgewell/trace-mapping` ([#12692](https://github.com/facebook/jest/pull/12692))
- `[jest-transform]` [**BREAKING**] Make it required for `process()` and `processAsync()` methods to always return structured data ([#12638](https://github.com/facebook/jest/pull/12638))
- `[jest-test-result]` Add duration property to JSON test output ([#12518](https://github.com/facebook/jest/pull/12518))
- `[jest-watcher]` [**BREAKING**] Make `PatternPrompt` class to take `entityName` as third constructor parameter instead of `this._entityName` ([#12591](https://github.com/facebook/jest/pull/12591))
- `[jest-worker]` [**BREAKING**] Allow only absolute `workerPath` ([#12343](https://github.com/facebook/jest/pull/12343))
- `[jest-worker]` [**BREAKING**] Default to advanced serialization when using child process workers ([#10983] (https://github.com/facebook/jest/pull/10983))
- `[pretty-format]` New `maxWidth` parameter ([#12402](https://github.com/facebook/jest/pull/12402))

### Fixes

- `[babel-jest]` [**BREAKING**] Pass `rootDir` as `root` in Babel's options ([#12689](https://github.com/facebook/jest/pull/12689))
- `[expect]` Move typings of `.not`, `.rejects` and `.resolves` modifiers outside of `Matchers` interface ([#12346](https://github.com/facebook/jest/pull/12346))
- `[expect]` Throw useful error if `expect.extend` is called with invalid matchers ([#12488](https://github.com/facebook/jest/pull/12488))
- `[expect]` Fix `iterableEquality` ignores other properties ([#8359](https://github.com/facebook/jest/pull/8359))
Expand All @@ -83,8 +87,9 @@
- `[jest-matcher-utils]` Pass maxWidth to `pretty-format` to avoid printing every element in arrays by default ([#12402](https://github.com/facebook/jest/pull/12402))
- `[jest-mock]` Fix function overloads for `spyOn` to allow more correct type inference in complex object ([#12442](https://github.com/facebook/jest/pull/12442))
- `[jest-mock]` Handle overridden `Function.name` property ([#12674](https://github.com/facebook/jest/pull/12674))
- `[jest-reporters]` Notifications generated by the `--notify` flag are no longer persistent in GNOME Shell. ([#11733](https://github.com/facebook/jest/pull/11733))
- `[@jest/reporters]` Notifications generated by the `--notify` flag are no longer persistent in GNOME Shell. ([#11733](https://github.com/facebook/jest/pull/11733))
- `[@jest/reporters]` Move missing icon file which is needed for `NotifyReporter` class. ([#12593](https://github.com/facebook/jest/pull/12593))
- `[@jest/reporters]` Update `v8-to-istanbul` ([#12697](https://github.com/facebook/jest/pull/12697))
- `[jest-resolver]` Call custom resolver with core node.js modules ([#12654](https://github.com/facebook/jest/pull/12654))
- `[jest-worker]` Fix `Farm` execution results memory leak ([#12497](https://github.com/facebook/jest/pull/12497))

Expand All @@ -99,6 +104,7 @@
- `[docs, examples]` Update React examples to match with the new React guidelines for code examples ([#12217](https://github.com/facebook/jest/pull/12217))
- `[docs]` Add clarity for module factory hoisting limitations ([#12453](https://github.com/facebook/jest/pull/12453))
- `[docs]` Add more information about how code transformers work ([#12407](https://github.com/facebook/jest/pull/12407))
- `[docs]` Add upgrading guide ([#12633](https://github.com/facebook/jest/pull/12633))
- `[expect]` [**BREAKING**] Remove support for importing `build/utils` ([#12323](https://github.com/facebook/jest/pull/12323))
- `[expect]` [**BREAKING**] Migrate to ESM ([#12344](https://github.com/facebook/jest/pull/12344))
- `[expect]` [**BREAKING**] Snapshot matcher types are moved to `@jest/expect` ([#12404](https://github.com/facebook/jest/pull/12404))
Expand Down
12 changes: 12 additions & 0 deletions CONTRIBUTING.md
Expand Up @@ -129,6 +129,18 @@ Time: 0.232 s, estimated 1 s
Ran all test suites.
```

## Checking Constraints

We use [Yarn Constraints](https://yarnpkg.com/features/constraints) to enforce various rules across the repository. They are declared inside the [`constraints.pro` file](https://github.com/facebook/jest/blob/main/constraints.pro) and their purposes are documented with comments.

Constraints can be checked with `yarn constraints`, and fixed with `yarn constraints --fix`. Generally speaking:

- Workspaces must not depend on conflicting ranges of dependencies. Use the `-i,--interactive` flag and select "Reuse" when installing dependencies and you shouldn't ever have to deal with this rule.

- A dependency doesn't appear in both `dependencies` and `devDependencies` of the same workspace.

- Workspaces must point our repository through the `repository` field.

##### Using jest-circus

There may be cases where you want to run jest using `jest-circus` instead of `jest-jasmine2` (which is the default runner) for integration testing. In situations like this, set the environment variable `JEST_CIRCUS` to 1. That will configure jest to use `jest-circus`. So something like this.
Expand Down
82 changes: 82 additions & 0 deletions constraints.pro
@@ -0,0 +1,82 @@
constraints_min_version(1).

% This file is written in Prolog
% It contains rules that the project must respect.
% Check with "yarn constraints" (fix w/ "yarn constraints --fix")
% Yarn Constraints https://yarnpkg.com/features/constraints
% Reference for other constraints:
% https://github.com/babel/babel/blob/main/constraints.pro
% https://github.com/yarnpkg/berry/blob/master/constraints.pro

% This rule will enforce that a workspace MUST depend on the same version of a dependency as the one used by the other workspaces
gen_enforced_dependency(WorkspaceCwd, DependencyIdent, DependencyRange2, DependencyType) :-
% Iterates over all dependencies from all workspaces
workspace_has_dependency(WorkspaceCwd, DependencyIdent, DependencyRange, DependencyType),
% Iterates over similarly-named dependencies from all workspaces (again)
workspace_has_dependency(OtherWorkspaceCwd, DependencyIdent, DependencyRange2, DependencyType2),
% Ignore peer dependencies
DependencyType \= 'peerDependencies',
DependencyType2 \= 'peerDependencies',
% Ignore workspace:*: we use both `workspace:*` and real version such as `^28.0.0-alpha.8` to reference package in monorepo
% TODO: in the future we should make it consistent and remove this ignore
DependencyRange \= 'workspace:*',
DependencyRange2 \= 'workspace:*',
% Get the workspace name
workspace_ident(WorkspaceCwd, WorkspaceIdent),
workspace_ident(OtherWorkspaceCwd, OtherWorkspaceIdent),
% @types/node in the root need to stay on ~12.12.0
(
(WorkspaceIdent = '@jest/monorepo'; OtherWorkspaceIdent = '@jest/monorepo') ->
DependencyIdent \= '@types/node'
;
true
),
% Allow enzyme example workspace use a older version react and react-dom, because enzyme don't support react 17
(
(WorkspaceIdent = 'example-enzyme'; OtherWorkspaceIdent = 'example-enzyme') ->
\+ member(DependencyIdent, ['react', 'react-dom'])
;
true
).

% Enforces that a dependency doesn't appear in both `dependencies` and `devDependencies`
gen_enforced_dependency(WorkspaceCwd, DependencyIdent, null, 'devDependencies') :-
workspace_has_dependency(WorkspaceCwd, DependencyIdent, _, 'devDependencies'),
workspace_has_dependency(WorkspaceCwd, DependencyIdent, _, 'dependencies').

% Enforces the license in all public workspaces while removing it from private workspaces
gen_enforced_field(WorkspaceCwd, 'license', 'MIT') :-
\+ workspace_field(WorkspaceCwd, 'private', true).
gen_enforced_field(WorkspaceCwd, 'license', null) :-
workspace_field(WorkspaceCwd, 'private', true).

% Enforces the repository field for all public workspaces while removing it from private workspaces
gen_enforced_field(WorkspaceCwd, 'repository.type', 'git') :-
\+ workspace_field(WorkspaceCwd, 'private', true).
gen_enforced_field(WorkspaceCwd, 'repository.url', 'https://github.com/facebook/jest.git') :-
\+ workspace_field(WorkspaceCwd, 'private', true).
gen_enforced_field(WorkspaceCwd, 'repository.directory', WorkspaceCwd) :-
\+ workspace_field(WorkspaceCwd, 'private', true).
gen_enforced_field(WorkspaceCwd, 'repository', null) :-
workspace_field(WorkspaceCwd, 'private', true).

% Enforces 'publishConfig.access' is set to public for public workspaces while removing it from private workspaces
gen_enforced_field(WorkspaceCwd, 'publishConfig.access', 'public') :-
\+ workspace_field(WorkspaceCwd, 'private', true).
gen_enforced_field(WorkspaceCwd, 'publishConfig.access', null) :-
workspace_field(WorkspaceCwd, 'private', true).

% Enforces the engines.node field for public workspace
gen_enforced_field(WorkspaceCwd, 'engines.node', '^12.13.0 || ^14.15.0 || ^16.13.0 || >=17.0.0') :-
\+ workspace_field(WorkspaceCwd, 'private', true).

% Enforces the main and types field to start with ./
gen_enforced_field(WorkspaceCwd, FieldName, ExpectedValue) :-
% Fields the rule applies to
member(FieldName, ['main', 'types']),
% Get current value
workspace_field(WorkspaceCwd, FieldName, CurrentValue),
% Must not start with ./ already
\+ atom_concat('./', _, CurrentValue),
% Store './' + CurrentValue in ExpectedValue
atom_concat('./', CurrentValue, ExpectedValue).
7 changes: 6 additions & 1 deletion docs/ECMAScriptModules.md
Expand Up @@ -23,14 +23,19 @@ With the warnings out of the way, this is how you activate ESM support in your t

## Differences between ESM and CommonJS

Most of the differences are explained in [Node's documentation](https://nodejs.org/api/esm.html#esm_differences_between_es_modules_and_commonjs), but in addition to the things mentioned there, Jest injects a special variable into all executed files - the [`jest` object](JestObjectAPI.md). To access this object in ESM, you need to import it from the `@jest/globals` module.
Most of the differences are explained in [Node's documentation](https://nodejs.org/api/esm.html#esm_differences_between_es_modules_and_commonjs), but in addition to the things mentioned there, Jest injects a special variable into all executed files - the [`jest` object](JestObjectAPI.md). To access this object in ESM, you need to import it from the `@jest/globals` module or use `import.meta`.

```js
import {jest} from '@jest/globals';

jest.useFakeTimers();

// etc.

// alternatively
import.meta.jest.useFakeTimers();

// jest === import.meta.jest => true
```

Please note that we currently don't support `jest.mock` in a clean way in ESM, but that is something we intend to add proper support for in the future. Follow [this issue](https://github.com/facebook/jest/issues/10025) for updates.

0 comments on commit 5f8cb12

Please sign in to comment.