Skip to content

Commit

Permalink
chore: add test verifying PnP works (#11513)
Browse files Browse the repository at this point in the history
Co-authored-by: Kristoffer K. <[email protected]>
  • Loading branch information
SimenB and merceyz authored Jun 3, 2021
1 parent 1fea2a5 commit b931b3c
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ jobs:
run: yarn test-types
- name: verify [email protected] 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
Original file line number Diff line number Diff line change
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
65 changes: 65 additions & 0 deletions scripts/verifyPnP.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* 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 dedent = require('dedent');
const execa = require('execa');
const rimraf = require('rimraf');
const tempy = require('tempy');

const rootDirectory = path.resolve(__dirname, '..');

const cwd = tempy.directory();

try {
fs.writeFileSync(
path.join(cwd, '.yarnrc.yml'),
dedent`
enableGlobalCache: true
yarnPath: ${require.resolve('../.yarn/releases/yarn-2.4.2.cjs')}
`,
);
fs.writeFileSync(
path.join(cwd, 'package.json'),
JSON.stringify(
{
dependencies: {
jest: `*`,
},
name: 'test-pnp',
},
null,
2,
),
);
fs.writeFileSync(
path.join(cwd, 'test.js'),
dedent`
/*
* @jest-environment jsdom
*/
test('dummy', () => {
expect(window).toBeDefined();
});
`,
);
execa.sync('yarn', ['link', '--private', '--all', rootDirectory], {
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);
}

0 comments on commit b931b3c

Please sign in to comment.