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

fix(jest-resolve): disable jest-pnp-resolver for Yarn 2 #10847

Merged
merged 2 commits into from Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -20,6 +20,7 @@
- `[jest-transform]` Show enhanced `SyntaxError` message for all `SyntaxError`s ([#10749](https://github.com/facebook/jest/pull/10749))
- `[jest-transform]` [**BREAKING**] Refactor API to pass an options bag around rather than multiple boolean options ([#10753](https://github.com/facebook/jest/pull/10753))
- `[jest-transform]` [**BREAKING**] Refactor API of transformers to pass an options bag rather than separate `config` and other options
- `[jest-resolve]` Disable `jest-pnp-resolver` for Yarn 2 ([#10847](https://github.com/facebook/jest/pull/10847))

### Chore & Maintenance

Expand Down
18 changes: 9 additions & 9 deletions e2e/__tests__/pnp.test.ts
Expand Up @@ -12,21 +12,21 @@ import {json as runWithJson} from '../runJest';
const DIR = path.resolve(__dirname, '..', 'pnp');

beforeEach(() => {
runYarnInstall(DIR, {YARN_NODE_LINKER: 'pnp'});
runYarnInstall(DIR, {
YARN_ENABLE_GLOBAL_CACHE: 'false',
YARN_NODE_LINKER: 'pnp',
});
});

it('successfully runs the tests inside `pnp/`', () => {
// https://github.com/facebook/jest/pull/8094#issuecomment-471220694
merceyz marked this conversation as resolved.
Show resolved Hide resolved
if (process.platform === 'win32') {
console.warn('[SKIP] Does not work on Windows');

return;
}

const {json} = runWithJson(DIR, ['--no-cache', '--coverage'], {
env: {YARN_NODE_LINKER: 'pnp'},
env: {
YARN_ENABLE_GLOBAL_CACHE: 'false',
YARN_NODE_LINKER: 'pnp',
},
nodeOptions: `--require ${DIR}/.pnp.js`,
});

expect(json.success).toBe(true);
expect(json.numTotalTestSuites).toBe(2);
});
2 changes: 1 addition & 1 deletion e2e/pnp/__tests__/undeclared-dependency.test.js
Expand Up @@ -9,5 +9,5 @@
it('should surface pnp errors', () => {
expect(() => {
require('undeclared');
}).toThrow(expect.objectContaining({pnpCode: 'UNDECLARED_DEPENDENCY'}));
}).toThrow(expect.objectContaining({code: 'MODULE_NOT_FOUND'}));
});
4 changes: 2 additions & 2 deletions e2e/pnp/package.json
@@ -1,7 +1,7 @@
{
"dependencies": {
"foo": "link:./lib",
"undeclared": "link:./undeclared-dependency"
"foo": "portal:./lib",
"undeclared": "portal:./undeclared-dependency"
},
"installConfig": {
"pnp": true
Expand Down
12 changes: 6 additions & 6 deletions e2e/pnp/yarn.lock
Expand Up @@ -4,23 +4,23 @@
__metadata:
version: 4

"foo@link:./lib::locator=root-workspace-0b6124%40workspace%3A.":
"foo@portal:./lib::locator=root-workspace-0b6124%40workspace%3A.":
version: 0.0.0-use.local
resolution: "foo@link:./lib::locator=root-workspace-0b6124%40workspace%3A."
resolution: "foo@portal:./lib::locator=root-workspace-0b6124%40workspace%3A."
languageName: node
linkType: soft

"root-workspace-0b6124@workspace:.":
version: 0.0.0-use.local
resolution: "root-workspace-0b6124@workspace:."
dependencies:
foo: "link:./lib"
undeclared: "link:./undeclared-dependency"
foo: "portal:./lib"
undeclared: "portal:./undeclared-dependency"
languageName: unknown
linkType: soft

"undeclared@link:./undeclared-dependency::locator=root-workspace-0b6124%40workspace%3A.":
"undeclared@portal:./undeclared-dependency::locator=root-workspace-0b6124%40workspace%3A.":
version: 0.0.0-use.local
resolution: "undeclared@link:./undeclared-dependency::locator=root-workspace-0b6124%40workspace%3A."
resolution: "undeclared@portal:./undeclared-dependency::locator=root-workspace-0b6124%40workspace%3A."
languageName: node
linkType: soft
5 changes: 3 additions & 2 deletions packages/jest-resolve/src/defaultResolver.ts
Expand Up @@ -12,7 +12,6 @@ import type {Config} from '@jest/types';
import {tryRealpath} from 'jest-util';

type ResolverOptions = {
allowPnp?: boolean;
basedir: Config.Path;
browser?: boolean;
defaultResolver: typeof defaultResolver;
Expand All @@ -36,7 +35,9 @@ export default function defaultResolver(
path: Config.Path,
options: ResolverOptions,
): Config.Path {
if (process.versions.pnp && options.allowPnp !== false) {
// Yarn 2 adds support to `resolve` automatically so the pnpResolver is only
// needed for Yarn 1 which implements version 1 of the pnp spec
if (process.versions.pnp === '1') {
return pnpResolver(path, options);
}

Expand Down