Skip to content

Commit

Permalink
fix: don't /// <reference types="jest" /> (#9875)
Browse files Browse the repository at this point in the history
  • Loading branch information
jablko authored and ghostd committed Apr 26, 2020
1 parent 6cbd3cb commit c2b0118
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,8 @@

### Fixes

- `[expect]` Prints the Symbol name into the error message with a custom asymmetric matcher ([#9888](https://github.com/facebook/jest/pull/9888))
- `[@jest/environment]` Make sure not to reference Jest types ([#9875](https://github.com/facebook/jest/pull/9875))
- `[jest-message-util]` Code frame printing should respect `--noStackTrace` flag ([#9866](https://github.com/facebook/jest/pull/9866))
- `[jest-runtime]` Support importing CJS from ESM using `import` statements ([#9850](https://github.com/facebook/jest/pull/9850))
- `[jest-runtime]` Support importing parallel dynamic `import`s ([#9858](https://github.com/facebook/jest/pull/9858))
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -48,6 +48,7 @@
"fast-check": "^1.13.0",
"find-process": "^1.4.1",
"glob": "^7.1.1",
"globby": "^10.0.2",
"graceful-fs": "^4.2.3",
"isbinaryfile": "^4.0.0",
"istanbul-lib-coverage": "^3.0.0",
Expand Down
12 changes: 12 additions & 0 deletions packages/expect/src/__tests__/__snapshots__/extend.test.js.snap
Expand Up @@ -53,3 +53,15 @@ exports[`is available globally when matcher is unary 1`] = `expected 15 to be di
exports[`is available globally when matcher is variadic 1`] = `expected 15 to be within range 1 - 3`;
exports[`is ok if there is no message specified 1`] = `<r>No message was specified for this matcher.</>`;
exports[`prints the Symbol into the error message 1`] = `
<d>expect(</><r>received</><d>).</>toEqual<d>(</><g>expected</><d>) // deep equality</>
<g>- Expected - 1</>
<r>+ Received + 1</>
<d> Object {</>
<g>- "a": toBeSymbol<Symbol(bar)>,</>
<r>+ "a": Symbol(foo),</>
<d> }</>
`;
17 changes: 17 additions & 0 deletions packages/expect/src/__tests__/extend.test.js
Expand Up @@ -23,6 +23,12 @@ jestExpect.extend({

return {message, pass};
},
toBeSymbol(actual, expected) {
const pass = actual === expected;
const message = () => `expected ${actual} to be Symbol ${expected}`;

return {message, pass};
},
toBeWithinRange(actual, floor, ceiling) {
const pass = actual >= floor && actual <= ceiling;
const message = pass
Expand Down Expand Up @@ -137,3 +143,14 @@ it('defines asymmetric variadic matchers that can be prefixed by not', () => {
}),
).not.toThrow();
});

it('prints the Symbol into the error message', () => {
const foo = Symbol('foo');
const bar = Symbol('bar');

expect(() =>
jestExpect({a: foo}).toEqual({
a: jestExpect.toBeSymbol(bar),
}),
).toThrowErrorMatchingSnapshot();
});
2 changes: 1 addition & 1 deletion packages/expect/src/jestMatchersObject.ts
Expand Up @@ -78,7 +78,7 @@ export const setMatchers = (
}

toAsymmetricMatcher() {
return `${this.toString()}<${this.sample.join(', ')}>`;
return `${this.toString()}<${this.sample.map(String).join(', ')}>`;
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/jest-environment/tsconfig.json
@@ -1,6 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
// we don't want `@types/jest` to be referenced
"types": ["node"],
"rootDir": "src",
"outDir": "build"
},
Expand Down
65 changes: 56 additions & 9 deletions scripts/buildTs.js
Expand Up @@ -11,13 +11,17 @@ const assert = require('assert');
const fs = require('fs');
const os = require('os');
const path = require('path');
const util = require('util');

const chalk = require('chalk');
const execa = require('execa');
const globby = require('globby');
const rimraf = require('rimraf');
const throat = require('throat');
const {getPackages} = require('./buildUtils');

const readFilePromise = util.promisify(fs.readFile);

const packages = getPackages();

const packagesWithTs = packages.filter(p =>
Expand Down Expand Up @@ -64,23 +68,66 @@ try {
return;
}

const downlevelArgs = ['--silent', 'downlevel-dts', 'build', 'build/ts3.4'];

console.log(chalk.inverse(' Downleveling TypeScript definition files '));

// we want to limit the number of processes we spawn
const cpus = Math.max(1, os.cpus().length - 1);

Promise.all(
packagesWithTs.map(
throat(cpus, pkgDir => {
// otherwise we get nested `ts3.4` directories
rimraf.sync(path.resolve(pkgDir, 'build/ts3.4'));

return execa('yarn', downlevelArgs, {cwd: pkgDir, stdio: 'inherit'});
throat(cpus, async pkgDir => {
const buildDir = path.resolve(pkgDir, 'build/**/*.d.ts');
const ts3dot4 = path.resolve(pkgDir, 'build/ts3.4');

const globbed = await globby([buildDir, `!${ts3dot4}`]);

const files = await Promise.all(
globbed.map(file => Promise.all([file, readFilePromise(file, 'utf8')])),
);

const filesWithReferences = files
.filter(([, content]) => content.includes('/// <reference types'))
.map(([name, content]) => [
name,
content
.split('\n')
.filter(line => line !== '/// <reference types="node" />')
.filter(line => line.includes('/// <reference types'))
.join('\n'),
])
.filter(([, content]) => content.length > 0)
.filter(hit => hit.length > 0)
.map(([file, references]) =>
chalk.red(
`${chalk.bold(
file,
)} has the following non-node type references:\n\n${references}\n`,
),
)
.join('\n\n');

if (filesWithReferences) {
console.error(filesWithReferences);

process.exit(1);
}
}),
),
)
.then(() => {
const downlevelArgs = ['--silent', 'downlevel-dts', 'build', 'build/ts3.4'];

console.log(chalk.inverse(' Downleveling TypeScript definition files '));

return Promise.all(
packagesWithTs.map(
throat(cpus, pkgDir => {
// otherwise we get nested `ts3.4` directories
rimraf.sync(path.resolve(pkgDir, 'build/ts3.4'));

return execa('yarn', downlevelArgs, {cwd: pkgDir, stdio: 'inherit'});
}),
),
);
})
.then(() => {
console.log(
chalk.inverse.green(
Expand Down
89 changes: 85 additions & 4 deletions yarn.lock
Expand Up @@ -1899,11 +1899,32 @@
call-me-maybe "^1.0.1"
glob-to-regexp "^0.3.0"

"@nodelib/fs.scandir@2.1.3":
version "2.1.3"
resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.3.tgz#3a582bdb53804c6ba6d146579c46e52130cf4a3b"
integrity sha512-eGmwYQn3gxo4r7jdQnkrrN6bY478C3P+a/y72IJukF8LjB6ZHeB3c+Ehacj3sYeSmUXGlnA67/PmbM9CVwL7Dw==
dependencies:
"@nodelib/fs.stat" "2.0.3"
run-parallel "^1.1.9"

"@nodelib/fs.stat@2.0.3", "@nodelib/fs.stat@^2.0.2":
version "2.0.3"
resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-2.0.3.tgz#34dc5f4cabbc720f4e60f75a747e7ecd6c175bd3"
integrity sha512-bQBFruR2TAwoevBEd/NWMoAAtNGzTRgdrqnYCc7dhzfoNvqPzLyqlEQnzZ3kVnNrSp25iyxE00/3h2fqGAGArA==

"@nodelib/fs.stat@^1.1.2":
version "1.1.3"
resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-1.1.3.tgz#2b5a3ab3f918cca48a8c754c08168e3f03eba61b"
integrity sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw==

"@nodelib/fs.walk@^1.2.3":
version "1.2.4"
resolved "https://registry.yarnpkg.com/@nodelib/fs.walk/-/fs.walk-1.2.4.tgz#011b9202a70a6366e436ca5c065844528ab04976"
integrity sha512-1V9XOY4rDW0rehzbrcqAmHnz8e7SKvX27gh8Gt2WgB0+pdzdiLV83p72kZPU+jvMbS1qU5mauP2iOvO8rhmurQ==
dependencies:
"@nodelib/fs.scandir" "2.1.3"
fastq "^1.6.0"

"@octokit/auth-token@^2.4.0":
version "2.4.0"
resolved "https://registry.yarnpkg.com/@octokit/auth-token/-/auth-token-2.4.0.tgz#b64178975218b99e4dfe948253f0673cbbb59d9f"
Expand Down Expand Up @@ -3228,6 +3249,11 @@ array-union@^1.0.1, array-union@^1.0.2:
dependencies:
array-uniq "^1.0.1"

array-union@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/array-union/-/array-union-2.1.0.tgz#b798420adbeb1de828d84acd8a2e23d3efe85e8d"
integrity sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==

array-uniq@^1.0.1:
version "1.0.3"
resolved "https://registry.yarnpkg.com/array-uniq/-/array-uniq-1.0.3.tgz#af6ac877a25cc7f74e058894753858dfdb24fdb6"
Expand Down Expand Up @@ -5484,6 +5510,13 @@ dir-glob@^2.2.2:
dependencies:
path-type "^3.0.0"

dir-glob@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/dir-glob/-/dir-glob-3.0.1.tgz#56dbf73d992a4a93ba1584f4534063fd2e41717f"
integrity sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==
dependencies:
path-type "^4.0.0"

discontinuous-range@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/discontinuous-range/-/discontinuous-range-1.0.0.tgz#e38331f0844bba49b9a9cb71c771585aab1bc65a"
Expand Down Expand Up @@ -6576,6 +6609,18 @@ fast-glob@^2.0.2, fast-glob@^2.2.6:
merge2 "^1.2.3"
micromatch "^3.1.10"

fast-glob@^3.0.3:
version "3.2.2"
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.2.tgz#ade1a9d91148965d4bf7c51f72e1ca662d32e63d"
integrity sha512-UDV82o4uQyljznxwMxyVRJgZZt3O5wENYojjzbaGEGZgeOxkLFf+V4cnUD+krzb2F72E18RhamkMZ7AdeggF7A==
dependencies:
"@nodelib/fs.stat" "^2.0.2"
"@nodelib/fs.walk" "^1.2.3"
glob-parent "^5.1.0"
merge2 "^1.3.0"
micromatch "^4.0.2"
picomatch "^2.2.1"

fast-json-stable-stringify@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz#874bf69c6f404c2b5d99c481341399fd55892633"
Expand All @@ -6586,6 +6631,13 @@ fast-levenshtein@~2.0.6:
resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917"
integrity sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=

fastq@^1.6.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/fastq/-/fastq-1.7.0.tgz#fcd79a08c5bd7ec5b55cd3f5c4720db551929801"
integrity sha512-YOadQRnHd5q6PogvAR/x62BGituF2ufiEA6s8aavQANw5YKHERI4AREboX6KotzP8oX2klxYF2wcV/7bn1clfQ==
dependencies:
reusify "^1.0.4"

faye-websocket@~0.10.0:
version "0.10.0"
resolved "https://registry.yarnpkg.com/faye-websocket/-/faye-websocket-0.10.0.tgz#4e492f8d04dfb6f89003507f6edbf2d501e7c6f4"
Expand Down Expand Up @@ -7263,7 +7315,7 @@ glob-parent@^3.1.0:
is-glob "^3.1.0"
path-dirname "^1.0.0"

glob-parent@^5.0.0, glob-parent@~5.1.0:
glob-parent@^5.0.0, glob-parent@^5.1.0, glob-parent@~5.1.0:
version "5.1.1"
resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.1.1.tgz#b6c1ef417c4e5663ea498f1c45afac6916bbc229"
integrity sha512-FnI+VGOpnlGHWZxthPGR+QhR78fuiK0sNLkHQv+bL9fQi57lNNdquIbna/WrfROrolq8GK5Ek6BiMwqL/voRYQ==
Expand Down Expand Up @@ -7340,6 +7392,20 @@ globby@8.0.2, globby@^8.0.1:
pify "^3.0.0"
slash "^1.0.0"

globby@^10.0.2:
version "10.0.2"
resolved "https://registry.yarnpkg.com/globby/-/globby-10.0.2.tgz#277593e745acaa4646c3ab411289ec47a0392543"
integrity sha512-7dUi7RvCoT/xast/o/dLN53oqND4yk0nsHkhRgn9w65C4PofCLOoJ39iSOg+qVDdWQPIEj+eszMHQ+aLVwwQSg==
dependencies:
"@types/glob" "^7.1.1"
array-union "^2.1.0"
dir-glob "^3.0.1"
fast-glob "^3.0.3"
glob "^7.1.3"
ignore "^5.1.1"
merge2 "^1.2.3"
slash "^3.0.0"

globby@^9.2.0:
version "9.2.0"
resolved "https://registry.yarnpkg.com/globby/-/globby-9.2.0.tgz#fd029a706c703d29bdd170f4b6db3a3f7a7cb63d"
Expand Down Expand Up @@ -7819,7 +7885,7 @@ ignore@^4.0.3, ignore@^4.0.6:
resolved "https://registry.yarnpkg.com/ignore/-/ignore-4.0.6.tgz#750e3db5862087b4737ebac8207ffd1ef27b25fc"
integrity sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==

ignore@^5.0.5:
ignore@^5.0.5, ignore@^5.1.1:
version "5.1.4"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.1.4.tgz#84b7b3dbe64552b6ef0eca99f6743dbec6d97adf"
integrity sha512-MzbUSahkTW1u7JpKKjY7LCARd1fU5W2rLdxlM4kdkayuCwZImjkpluF9CM1aLewYJguPDqewLam18Y6AU69A8A==
Expand Down Expand Up @@ -9772,7 +9838,7 @@ merge-stream@^2.0.0:
resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60"
integrity sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==

merge2@^1.2.3:
merge2@^1.2.3, merge2@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.3.0.tgz#5b366ee83b2f1582c48f87e47cf1a9352103ca81"
integrity sha512-2j4DAdlBOkiSZIsaXk4mTE3sRS02yBHAtfy127xRV3bQUFqXkjHCHLW6Scv7DwNRbIWNHH8zpnz9zMaKXIdvYw==
Expand Down Expand Up @@ -11314,6 +11380,11 @@ path-type@^3.0.0:
dependencies:
pify "^3.0.0"

path-type@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b"
integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==

pbkdf2@^3.0.3:
version "3.0.17"
resolved "https://registry.yarnpkg.com/pbkdf2/-/pbkdf2-3.0.17.tgz#976c206530617b14ebb32114239f7b09336e93a6"
Expand All @@ -11335,7 +11406,7 @@ performance-now@^2.1.0:
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
integrity sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=

picomatch@^2.0.4, picomatch@^2.0.5, picomatch@^2.0.7:
picomatch@^2.0.4, picomatch@^2.0.5, picomatch@^2.0.7, picomatch@^2.2.1:
version "2.2.2"
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.2.2.tgz#21f333e9b6b8eaff02468f5146ea406d345f4dad"
integrity sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg==
Expand Down Expand Up @@ -12705,6 +12776,11 @@ retry@^0.10.0:
resolved "https://registry.yarnpkg.com/retry/-/retry-0.10.1.tgz#e76388d217992c252750241d3d3956fed98d8ff4"
integrity sha1-52OI0heZLCUnUCQdPTlW/tmNj/Q=

reusify@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/reusify/-/reusify-1.0.4.tgz#90da382b1e126efc02146e90845a88db12925d76"
integrity sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==

rfdc@^1.1.4:
version "1.1.4"
resolved "https://registry.yarnpkg.com/rfdc/-/rfdc-1.1.4.tgz#ba72cc1367a0ccd9cf81a870b3b58bd3ad07f8c2"
Expand Down Expand Up @@ -12774,6 +12850,11 @@ run-async@^2.2.0, run-async@^2.4.0:
dependencies:
is-promise "^2.1.0"

run-parallel@^1.1.9:
version "1.1.9"
resolved "https://registry.yarnpkg.com/run-parallel/-/run-parallel-1.1.9.tgz#c9dd3a7cf9f4b2c4b6244e173a6ed866e61dd679"
integrity sha512-DEqnSRTDw/Tc3FXf49zedI638Z9onwUotBMiUFKmrO2sdFKIbXamXGQ3Axd4qgphxKB4kw/qP1w5kTxnfU1B9Q==

run-queue@^1.0.0, run-queue@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/run-queue/-/run-queue-1.0.3.tgz#e848396f057d223f24386924618e25694161ec47"
Expand Down

0 comments on commit c2b0118

Please sign in to comment.