Skip to content

Commit

Permalink
Merge branch 'main' into fix-expect-add-types-test
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Oct 15, 2021
2 parents e5ff48e + 46c9c13 commit 9e9454c
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 48 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@

- `[expect]` Tweak and improve types ([#11949](https://github.com/facebook/jest/pull/11949))
- `[jest-runtime]` Ensure absolute paths can be resolved within test modules ([#11943](https://github.com/facebook/jest/pull/11943))
- `[jest-runtime]` Fix `instanceof` for `ModernFakeTimers` and `LegacyFakeTimers` methods ([#11946](https://github.com/facebook/jest/pull/11946))

### Chore & Maintenance

Expand Down
9 changes: 4 additions & 5 deletions docs/Puppeteer.md
Expand Up @@ -55,10 +55,9 @@ Here's an example of the GlobalSetup script

```js
// setup.js
const {writeFile} = require('fs').promises;
const {mkdir, writeFile} = require('fs').promises;
const os = require('os');
const path = require('path');
const mkdirp = require('mkdirp');
const puppeteer = require('puppeteer');

const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup');
Expand All @@ -70,7 +69,7 @@ module.exports = async function () {
global.__BROWSER_GLOBAL__ = browser;

// use the file system to expose the wsEndpoint for TestEnvironments
mkdirp.sync(DIR);
await mkdir(DIR, {recursive: true});
await writeFile(path.join(DIR, 'wsEndpoint'), browser.wsEndpoint());
};
```
Expand Down Expand Up @@ -122,17 +121,17 @@ Finally, we can close the puppeteer instance and clean-up the file

```js
// teardown.js
const fs = require('fs').promises;
const os = require('os');
const path = require('path');
const rimraf = require('rimraf');

const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup');
module.exports = async function () {
// close the browser instance
await global.__BROWSER_GLOBAL__.close();

// clean-up the wsEndpoint file
rimraf.sync(DIR);
await fs.rm(DIR, {recursive: true, force: true});
};
```

Expand Down
2 changes: 1 addition & 1 deletion e2e/resolve-conditions/package.json
Expand Up @@ -13,6 +13,6 @@
"transform": {}
},
"dependencies": {
"resolve.exports": "^1.0.2"
"resolve.exports": "^1.1.0"
}
}
8 changes: 1 addition & 7 deletions e2e/resolve-conditions/resolver.js
Expand Up @@ -24,13 +24,7 @@ function createPathFilter(conditions) {
const path = relativePath === 'index' ? '.' : relativePath;

return (
resolveExports(pkg, path, {
// `resolve.exports adds `node` unless `browser` is `false`, so let's add this ugly thing
browser: conditions.includes('browser'),
conditions,
// `resolve.exports adds `import` unless `require` is `false`, so let's add this ugly thing
require: conditions.includes('require'),
}) || relativePath
resolveExports(pkg, path, {conditions, unsafe: true}) || relativePath
);
};
}
10 changes: 5 additions & 5 deletions e2e/resolve-conditions/yarn.lock
Expand Up @@ -5,17 +5,17 @@ __metadata:
version: 4
cacheKey: 7

"resolve.exports@npm:^1.0.2":
version: 1.0.2
resolution: "resolve.exports@npm:1.0.2"
checksum: 012a46e3ae41c53762abf5b50ea1b4adf2de617bbea1dbc7bf6e609c1ceaedee7782acbc92d443951d5dd0c3a8fb1090ce73285a9ccc24b530e33b5e09ae196f
"resolve.exports@npm:^1.1.0":
version: 1.1.0
resolution: "resolve.exports@npm:1.1.0"
checksum: d04d2ce651fac14fe6ba13b377690f790cbbe91e6211b8fbec97ee08282e278875c74073a9b6243143a64e33d95eefb479e1dd4965664edc73b28b712100b36c
languageName: node
linkType: hard

"root-workspace-0b6124@workspace:.":
version: 0.0.0-use.local
resolution: "root-workspace-0b6124@workspace:."
dependencies:
resolve.exports: ^1.0.2
resolve.exports: ^1.1.0
languageName: unknown
linkType: soft
2 changes: 1 addition & 1 deletion packages/jest-runtime/package.json
Expand Up @@ -16,7 +16,6 @@
"dependencies": {
"@jest/console": "^27.2.5",
"@jest/environment": "^27.2.5",
"@jest/fake-timers": "^27.2.5",
"@jest/globals": "^27.2.5",
"@jest/source-map": "^27.0.6",
"@jest/test-result": "^27.2.5",
Expand All @@ -43,6 +42,7 @@
"yargs": "^16.2.0"
},
"devDependencies": {
"@jest/fake-timers": "^27.2.5",
"@jest/test-utils": "^27.2.5",
"@types/exit": "^0.1.30",
"@types/glob": "^7.1.1",
Expand Down
8 changes: 4 additions & 4 deletions packages/jest-runtime/src/index.ts
Expand Up @@ -30,7 +30,7 @@ import type {
Module,
ModuleWrapper,
} from '@jest/environment';
import {LegacyFakeTimers, ModernFakeTimers} from '@jest/fake-timers';
import type {LegacyFakeTimers, ModernFakeTimers} from '@jest/fake-timers';
import type * as JestGlobals from '@jest/globals';
import type {SourceMapRegistry} from '@jest/source-map';
import type {RuntimeTransformResult, V8CoverageResult} from '@jest/test-result';
Expand Down Expand Up @@ -1963,7 +1963,7 @@ export default class Runtime {
getRealSystemTime: () => {
const fakeTimers = _getFakeTimers();

if (fakeTimers instanceof ModernFakeTimers) {
if (fakeTimers === this._environment.fakeTimersModern) {
return fakeTimers.getRealSystemTime();
} else {
throw new TypeError(
Expand All @@ -1984,7 +1984,7 @@ export default class Runtime {
runAllImmediates: () => {
const fakeTimers = _getFakeTimers();

if (fakeTimers instanceof LegacyFakeTimers) {
if (fakeTimers === this._environment.fakeTimers) {
fakeTimers.runAllImmediates();
} else {
throw new TypeError(
Expand All @@ -2000,7 +2000,7 @@ export default class Runtime {
setSystemTime: (now?: number | Date) => {
const fakeTimers = _getFakeTimers();

if (fakeTimers instanceof ModernFakeTimers) {
if (fakeTimers === this._environment.fakeTimersModern) {
fakeTimers.setSystemTime(now);
} else {
throw new TypeError(
Expand Down
9 changes: 4 additions & 5 deletions website/versioned_docs/version-25.x/Puppeteer.md
Expand Up @@ -55,10 +55,9 @@ Here's an example of the GlobalSetup script

```js
// setup.js
const {writeFile} = require('fs').promises;
const {mkdir, writeFile} = require('fs').promises;
const os = require('os');
const path = require('path');
const mkdirp = require('mkdirp');
const puppeteer = require('puppeteer');

const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup');
Expand All @@ -70,7 +69,7 @@ module.exports = async function () {
global.__BROWSER_GLOBAL__ = browser;

// use the file system to expose the wsEndpoint for TestEnvironments
mkdirp.sync(DIR);
await mkdir(DIR, {recursive: true});
await writeFile(path.join(DIR, 'wsEndpoint'), browser.wsEndpoint());
};
```
Expand Down Expand Up @@ -122,17 +121,17 @@ Finally, we can close the puppeteer instance and clean-up the file

```js
// teardown.js
const fs = require('fs').promises;
const os = require('os');
const path = require('path');
const rimraf = require('rimraf');

const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup');
module.exports = async function () {
// close the browser instance
await global.__BROWSER_GLOBAL__.close();

// clean-up the wsEndpoint file
rimraf.sync(DIR);
await fs.rm(DIR, {recursive: true, force: true});
};
```

Expand Down
9 changes: 4 additions & 5 deletions website/versioned_docs/version-26.x/Puppeteer.md
Expand Up @@ -55,10 +55,9 @@ Here's an example of the GlobalSetup script

```js
// setup.js
const {writeFile} = require('fs').promises;
const {mkdir, writeFile} = require('fs').promises;
const os = require('os');
const path = require('path');
const mkdirp = require('mkdirp');
const puppeteer = require('puppeteer');

const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup');
Expand All @@ -70,7 +69,7 @@ module.exports = async function () {
global.__BROWSER_GLOBAL__ = browser;

// use the file system to expose the wsEndpoint for TestEnvironments
mkdirp.sync(DIR);
await mkdir(DIR, {recursive: true});
await writeFile(path.join(DIR, 'wsEndpoint'), browser.wsEndpoint());
};
```
Expand Down Expand Up @@ -122,17 +121,17 @@ Finally, we can close the puppeteer instance and clean-up the file

```js
// teardown.js
const fs = require('fs').promises;
const os = require('os');
const path = require('path');
const rimraf = require('rimraf');

const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup');
module.exports = async function () {
// close the browser instance
await global.__BROWSER_GLOBAL__.close();

// clean-up the wsEndpoint file
rimraf.sync(DIR);
await fs.rm(DIR, {recursive: true, force: true});
};
```

Expand Down
9 changes: 4 additions & 5 deletions website/versioned_docs/version-27.0/Puppeteer.md
Expand Up @@ -55,10 +55,9 @@ Here's an example of the GlobalSetup script

```js
// setup.js
const {writeFile} = require('fs').promises;
const {mkdir, writeFile} = require('fs').promises;
const os = require('os');
const path = require('path');
const mkdirp = require('mkdirp');
const puppeteer = require('puppeteer');

const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup');
Expand All @@ -70,7 +69,7 @@ module.exports = async function () {
global.__BROWSER_GLOBAL__ = browser;

// use the file system to expose the wsEndpoint for TestEnvironments
mkdirp.sync(DIR);
await mkdir(DIR, {recursive: true});
await writeFile(path.join(DIR, 'wsEndpoint'), browser.wsEndpoint());
};
```
Expand Down Expand Up @@ -122,17 +121,17 @@ Finally, we can close the puppeteer instance and clean-up the file

```js
// teardown.js
const fs = require('fs').promises;
const os = require('os');
const path = require('path');
const rimraf = require('rimraf');

const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup');
module.exports = async function () {
// close the browser instance
await global.__BROWSER_GLOBAL__.close();

// clean-up the wsEndpoint file
rimraf.sync(DIR);
await fs.rm(DIR, {recursive: true, force: true});
};
```

Expand Down
9 changes: 4 additions & 5 deletions website/versioned_docs/version-27.1/Puppeteer.md
Expand Up @@ -55,10 +55,9 @@ Here's an example of the GlobalSetup script

```js
// setup.js
const {writeFile} = require('fs').promises;
const {mkdir, writeFile} = require('fs').promises;
const os = require('os');
const path = require('path');
const mkdirp = require('mkdirp');
const puppeteer = require('puppeteer');

const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup');
Expand All @@ -70,7 +69,7 @@ module.exports = async function () {
global.__BROWSER_GLOBAL__ = browser;

// use the file system to expose the wsEndpoint for TestEnvironments
mkdirp.sync(DIR);
await mkdir(DIR, {recursive: true});
await writeFile(path.join(DIR, 'wsEndpoint'), browser.wsEndpoint());
};
```
Expand Down Expand Up @@ -122,17 +121,17 @@ Finally, we can close the puppeteer instance and clean-up the file

```js
// teardown.js
const fs = require('fs').promises;
const os = require('os');
const path = require('path');
const rimraf = require('rimraf');

const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup');
module.exports = async function () {
// close the browser instance
await global.__BROWSER_GLOBAL__.close();

// clean-up the wsEndpoint file
rimraf.sync(DIR);
await fs.rm(DIR, {recursive: true, force: true});
};
```

Expand Down
9 changes: 4 additions & 5 deletions website/versioned_docs/version-27.2/Puppeteer.md
Expand Up @@ -55,10 +55,9 @@ Here's an example of the GlobalSetup script

```js
// setup.js
const {writeFile} = require('fs').promises;
const {mkdir, writeFile} = require('fs').promises;
const os = require('os');
const path = require('path');
const mkdirp = require('mkdirp');
const puppeteer = require('puppeteer');

const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup');
Expand All @@ -70,7 +69,7 @@ module.exports = async function () {
global.__BROWSER_GLOBAL__ = browser;

// use the file system to expose the wsEndpoint for TestEnvironments
mkdirp.sync(DIR);
await mkdir(DIR, {recursive: true});
await writeFile(path.join(DIR, 'wsEndpoint'), browser.wsEndpoint());
};
```
Expand Down Expand Up @@ -122,17 +121,17 @@ Finally, we can close the puppeteer instance and clean-up the file

```js
// teardown.js
const fs = require('fs').promises;
const os = require('os');
const path = require('path');
const rimraf = require('rimraf');

const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup');
module.exports = async function () {
// close the browser instance
await global.__BROWSER_GLOBAL__.close();

// clean-up the wsEndpoint file
rimraf.sync(DIR);
await fs.rm(DIR, {recursive: true, force: true});
};
```

Expand Down

0 comments on commit 9e9454c

Please sign in to comment.