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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add test verifying PnP works #11513

Merged
merged 8 commits into from Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
2 changes: 2 additions & 0 deletions .github/workflows/nodejs.yml
Expand Up @@ -74,6 +74,8 @@ jobs:
run: yarn test-types
- name: verify TypeScript@3.8 compatibility
run: yarn verify-old-ts
- name: verify Yarn PnP compatibility
run: yarn verify-pnp
- name: run eslint
run: yarn lint
- name: run prettier
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -107,6 +107,7 @@
"test-leak": "yarn jest -i --detectLeaks jest-mock jest-diff jest-repl pretty-format",
"test": "yarn lint && yarn jest",
"verify-old-ts": "node ./scripts/verifyOldTs.js",
"verify-pnp": "node ./scripts/verifyPnP.js",
"watch": "yarn build:js && node ./scripts/watch.js",
"watch:ts": "yarn build:ts --watch"
},
Expand Down
72 changes: 72 additions & 0 deletions scripts/verifyPnP.js
@@ -0,0 +1,72 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

const fs = require('fs');
const path = require('path');
const chalk = require('chalk');
const execa = require('execa');
const glob = require('glob');
const rimraf = require('rimraf');
const tempy = require('tempy');

const packagesDirectory = path.resolve(__dirname, '../packages');
const jestDirectory = path.resolve(packagesDirectory, './jest');

const cwd = tempy.directory();

try {
fs.writeFileSync(
path.join(cwd, '.yarnrc.yml'),
`
enableGlobalCache: true

yarnPath: ${require.resolve('../.yarn/releases/yarn-2.4.1.cjs')}
`,
);
fs.writeFileSync(
path.join(cwd, 'package.json'),
JSON.stringify(
{
dependencies: {
jest: `link:${jestDirectory}`,
},
name: 'test-pnp',
// resolutions: Object.fromEntries(
// glob
// .sync(packagesDirectory + '/*')
// .map(pkgDir => [
// require(path.join(pkgDir, 'package.json')).name,
// `portal:${pkgDir}`,
// ])
// .sort(([l], [r]) => l.localeCompare(r)),
// ),
},
null,
2,
),
);
fs.writeFileSync(
path.join(cwd, 'test.js'),
`
/*
* @jest-environment jsdom
*/

test('dummy', () => {
expect(window).toBeDefined();
});
`,
);
execa.sync('yarn', [], {cwd, stdio: 'inherit'});
execa.sync('yarn', ['jest'], {cwd, stdio: 'inherit'});

console.log(chalk.inverse.green(` Successfully ran Jest with PnP linker `));
} finally {
rimraf.sync(cwd);
}
SimenB marked this conversation as resolved.
Show resolved Hide resolved