Minor refactor to expect().toEqualFile assertion (#12830)
This commit is contained in:
parent
1387d66e6c
commit
7757a2850c
@ -20,7 +20,6 @@
|
|||||||
"@babel/helper-fixtures": "workspace:^7.12.13",
|
"@babel/helper-fixtures": "workspace:^7.12.13",
|
||||||
"babel-check-duplicated-nodes": "^1.0.0",
|
"babel-check-duplicated-nodes": "^1.0.0",
|
||||||
"escape-string-regexp": "condition:BABEL_8_BREAKING ? ^4.0.0 : ",
|
"escape-string-regexp": "condition:BABEL_8_BREAKING ? ^4.0.0 : ",
|
||||||
"jest-diff": "^24.8.0",
|
|
||||||
"lodash": "^4.17.19",
|
"lodash": "^4.17.19",
|
||||||
"quick-lru": "5.1.0",
|
"quick-lru": "5.1.0",
|
||||||
"regenerator-runtime": "^0.13.7",
|
"regenerator-runtime": "^0.13.7",
|
||||||
|
|||||||
@ -15,7 +15,6 @@ import path from "path";
|
|||||||
import vm from "vm";
|
import vm from "vm";
|
||||||
import checkDuplicatedNodes from "babel-check-duplicated-nodes";
|
import checkDuplicatedNodes from "babel-check-duplicated-nodes";
|
||||||
import QuickLRU from "quick-lru";
|
import QuickLRU from "quick-lru";
|
||||||
import diff from "jest-diff";
|
|
||||||
import escapeRegExp from "./escape-regexp";
|
import escapeRegExp from "./escape-regexp";
|
||||||
|
|
||||||
const cachedScripts = new QuickLRU({ maxSize: 10 });
|
const cachedScripts = new QuickLRU({ maxSize: 10 });
|
||||||
@ -342,26 +341,28 @@ function normalizeOutput(code) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
const toEqualFile = (actual, { filename, code }) => {
|
expect.extend({
|
||||||
const pass = actual === code;
|
toEqualFile(actual, { filename, code }) {
|
||||||
return {
|
if (this.isNot) {
|
||||||
pass,
|
throw new Error(".toEqualFile does not support negation");
|
||||||
message: pass
|
}
|
||||||
? () => {
|
|
||||||
throw new Error(".toEqualFile does not support negation");
|
const pass = actual === code;
|
||||||
}
|
return {
|
||||||
: () => {
|
pass,
|
||||||
const diffString = diff(code, actual, {
|
message: () => {
|
||||||
expand: false,
|
const diffString = this.utils.diff(code, actual, {
|
||||||
});
|
expand: false,
|
||||||
return (
|
});
|
||||||
`Expected ${filename} to match transform output.\n` +
|
return (
|
||||||
`To autogenerate a passing version of this file, delete the file and re-run the tests.\n\n` +
|
`Expected ${filename} to match transform output.\n` +
|
||||||
`Diff:\n\n${diffString}`
|
`To autogenerate a passing version of this file, delete the file and re-run the tests.\n\n` +
|
||||||
);
|
`Diff:\n\n${diffString}`
|
||||||
},
|
);
|
||||||
};
|
},
|
||||||
};
|
};
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
export default function (
|
export default function (
|
||||||
fixturesLoc: string,
|
fixturesLoc: string,
|
||||||
@ -376,10 +377,6 @@ export default function (
|
|||||||
if (suiteOpts.ignoreSuites?.includes(testSuite.title)) continue;
|
if (suiteOpts.ignoreSuites?.includes(testSuite.title)) continue;
|
||||||
|
|
||||||
describe(name + "/" + testSuite.title, function () {
|
describe(name + "/" + testSuite.title, function () {
|
||||||
expect.extend({
|
|
||||||
toEqualFile,
|
|
||||||
});
|
|
||||||
|
|
||||||
for (const task of testSuite.tests) {
|
for (const task of testSuite.tests) {
|
||||||
if (
|
if (
|
||||||
suiteOpts.ignoreTasks?.includes(task.title) ||
|
suiteOpts.ignoreTasks?.includes(task.title) ||
|
||||||
|
|||||||
80
yarn.lock
80
yarn.lock
@ -766,7 +766,6 @@ __metadata:
|
|||||||
"@babel/helper-fixtures": "workspace:^7.12.13"
|
"@babel/helper-fixtures": "workspace:^7.12.13"
|
||||||
babel-check-duplicated-nodes: ^1.0.0
|
babel-check-duplicated-nodes: ^1.0.0
|
||||||
escape-string-regexp: "condition:BABEL_8_BREAKING ? ^4.0.0 : "
|
escape-string-regexp: "condition:BABEL_8_BREAKING ? ^4.0.0 : "
|
||||||
jest-diff: ^24.8.0
|
|
||||||
lodash: ^4.17.19
|
lodash: ^4.17.19
|
||||||
quick-lru: 5.1.0
|
quick-lru: 5.1.0
|
||||||
regenerator-runtime: ^0.13.7
|
regenerator-runtime: ^0.13.7
|
||||||
@ -3615,17 +3614,6 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"@jest/types@npm:^24.9.0":
|
|
||||||
version: 24.9.0
|
|
||||||
resolution: "@jest/types@npm:24.9.0"
|
|
||||||
dependencies:
|
|
||||||
"@types/istanbul-lib-coverage": ^2.0.0
|
|
||||||
"@types/istanbul-reports": ^1.1.1
|
|
||||||
"@types/yargs": ^13.0.0
|
|
||||||
checksum: 7cd388ad9d3a6de7e0ca29cbaf34dd9da9f6485d26747fc2ef6732bf06dc98d79519b7f3684b7287bd6d5168c394d8f806dc1343bd3c1b3cdc3e85486a518c63
|
|
||||||
languageName: node
|
|
||||||
linkType: hard
|
|
||||||
|
|
||||||
"@jest/types@npm:^26.6.1":
|
"@jest/types@npm:^26.6.1":
|
||||||
version: 26.6.1
|
version: 26.6.1
|
||||||
resolution: "@jest/types@npm:26.6.1"
|
resolution: "@jest/types@npm:26.6.1"
|
||||||
@ -3892,16 +3880,6 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"@types/istanbul-reports@npm:^1.1.1":
|
|
||||||
version: 1.1.2
|
|
||||||
resolution: "@types/istanbul-reports@npm:1.1.2"
|
|
||||||
dependencies:
|
|
||||||
"@types/istanbul-lib-coverage": "*"
|
|
||||||
"@types/istanbul-lib-report": "*"
|
|
||||||
checksum: 92bd1f76a4ce16f5390c80b6b0e657171faf0003b0ff370b3c37739087c825d664493c9debf442c0871d864f1be15c88460f2399ae748186d1a944f16958aea4
|
|
||||||
languageName: node
|
|
||||||
linkType: hard
|
|
||||||
|
|
||||||
"@types/istanbul-reports@npm:^3.0.0":
|
"@types/istanbul-reports@npm:^3.0.0":
|
||||||
version: 3.0.0
|
version: 3.0.0
|
||||||
resolution: "@types/istanbul-reports@npm:3.0.0"
|
resolution: "@types/istanbul-reports@npm:3.0.0"
|
||||||
@ -3997,15 +3975,6 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"@types/yargs@npm:^13.0.0":
|
|
||||||
version: 13.0.11
|
|
||||||
resolution: "@types/yargs@npm:13.0.11"
|
|
||||||
dependencies:
|
|
||||||
"@types/yargs-parser": "*"
|
|
||||||
checksum: 8592d76c18ae57c25e9eeff29a63c2e0885527014ebd6d76244440d5dc1c6e0cf70753d256d77c09f516b082241e6124c1a83a72c061ee83cf5722d5d52f452f
|
|
||||||
languageName: node
|
|
||||||
linkType: hard
|
|
||||||
|
|
||||||
"@types/yargs@npm:^15.0.0":
|
"@types/yargs@npm:^15.0.0":
|
||||||
version: 15.0.8
|
version: 15.0.8
|
||||||
resolution: "@types/yargs@npm:15.0.8"
|
resolution: "@types/yargs@npm:15.0.8"
|
||||||
@ -4315,7 +4284,7 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"ansi-regex@npm:^4.0.0, ansi-regex@npm:^4.1.0":
|
"ansi-regex@npm:^4.1.0":
|
||||||
version: 4.1.0
|
version: 4.1.0
|
||||||
resolution: "ansi-regex@npm:4.1.0"
|
resolution: "ansi-regex@npm:4.1.0"
|
||||||
checksum: 53b6fe447cf92ee59739379de637af6f86b3b8a9537fbfe36a66f946f1d9d34afc3efe664ac31bcc7c3af042d43eabcfcfd3f790316d474bbc7b19a4b1d132dd
|
checksum: 53b6fe447cf92ee59739379de637af6f86b3b8a9537fbfe36a66f946f1d9d34afc3efe664ac31bcc7c3af042d43eabcfcfd3f790316d474bbc7b19a4b1d132dd
|
||||||
@ -5394,7 +5363,7 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"chalk@npm:^2.0.0, chalk@npm:^2.0.1, chalk@npm:^2.4.1, chalk@npm:^2.4.2":
|
"chalk@npm:^2.0.0, chalk@npm:^2.4.1, chalk@npm:^2.4.2":
|
||||||
version: 2.4.2
|
version: 2.4.2
|
||||||
resolution: "chalk@npm:2.4.2"
|
resolution: "chalk@npm:2.4.2"
|
||||||
dependencies:
|
dependencies:
|
||||||
@ -6194,13 +6163,6 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"diff-sequences@npm:^24.9.0":
|
|
||||||
version: 24.9.0
|
|
||||||
resolution: "diff-sequences@npm:24.9.0"
|
|
||||||
checksum: 049107ba804c3a332fe7edefd1cec8df33a18a99c6af77f88b3b9d22b5ee2e1940dbde23b97f97b0d7250a98f8c488c3ba552ebab54dc75c9542c1e90232d009
|
|
||||||
languageName: node
|
|
||||||
linkType: hard
|
|
||||||
|
|
||||||
"diff-sequences@npm:^26.5.0":
|
"diff-sequences@npm:^26.5.0":
|
||||||
version: 26.5.0
|
version: 26.5.0
|
||||||
resolution: "diff-sequences@npm:26.5.0"
|
resolution: "diff-sequences@npm:26.5.0"
|
||||||
@ -8754,18 +8716,6 @@ fsevents@^1.2.7:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"jest-diff@npm:^24.8.0":
|
|
||||||
version: 24.9.0
|
|
||||||
resolution: "jest-diff@npm:24.9.0"
|
|
||||||
dependencies:
|
|
||||||
chalk: ^2.0.1
|
|
||||||
diff-sequences: ^24.9.0
|
|
||||||
jest-get-type: ^24.9.0
|
|
||||||
pretty-format: ^24.9.0
|
|
||||||
checksum: ba4aa10e5712ad365700921c90362dae8c2ab5b2c599b6f64fc4f3013f6208d760cb2980d491010e602e4a36b28a5c18fceba251f7602929d93300ae03ae931c
|
|
||||||
languageName: node
|
|
||||||
linkType: hard
|
|
||||||
|
|
||||||
"jest-diff@npm:^26.6.1":
|
"jest-diff@npm:^26.6.1":
|
||||||
version: 26.6.1
|
version: 26.6.1
|
||||||
resolution: "jest-diff@npm:26.6.1"
|
resolution: "jest-diff@npm:26.6.1"
|
||||||
@ -8829,13 +8779,6 @@ fsevents@^1.2.7:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"jest-get-type@npm:^24.9.0":
|
|
||||||
version: 24.9.0
|
|
||||||
resolution: "jest-get-type@npm:24.9.0"
|
|
||||||
checksum: 0e6164dff23f8cd664a46642d2167b743e67349c57ff908259b56e3f5c81f8d2a13de2dd473a1a3d7682adcfe85888d14b0496ba51c5c8095eb52bf7526c3918
|
|
||||||
languageName: node
|
|
||||||
linkType: hard
|
|
||||||
|
|
||||||
"jest-get-type@npm:^26.3.0":
|
"jest-get-type@npm:^26.3.0":
|
||||||
version: 26.3.0
|
version: 26.3.0
|
||||||
resolution: "jest-get-type@npm:26.3.0"
|
resolution: "jest-get-type@npm:26.3.0"
|
||||||
@ -10991,18 +10934,6 @@ fsevents@^1.2.7:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"pretty-format@npm:^24.9.0":
|
|
||||||
version: 24.9.0
|
|
||||||
resolution: "pretty-format@npm:24.9.0"
|
|
||||||
dependencies:
|
|
||||||
"@jest/types": ^24.9.0
|
|
||||||
ansi-regex: ^4.0.0
|
|
||||||
ansi-styles: ^3.2.0
|
|
||||||
react-is: ^16.8.4
|
|
||||||
checksum: a61c5c21a638239ebdc9bfe259746dc1aca29555f8da997318031ebee3ea36662f60f329132365c0cace2a0d122a1f7f9550261b3f04aaa18029d16efc5b45fe
|
|
||||||
languageName: node
|
|
||||||
linkType: hard
|
|
||||||
|
|
||||||
"pretty-format@npm:^26.6.1":
|
"pretty-format@npm:^26.6.1":
|
||||||
version: 26.6.1
|
version: 26.6.1
|
||||||
resolution: "pretty-format@npm:26.6.1"
|
resolution: "pretty-format@npm:26.6.1"
|
||||||
@ -11180,13 +11111,6 @@ fsevents@^1.2.7:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"react-is@npm:^16.8.4":
|
|
||||||
version: 16.13.1
|
|
||||||
resolution: "react-is@npm:16.13.1"
|
|
||||||
checksum: 11bcf1267a314a522615f626f3ce3727a3a24cdbf61c4d452add3550a7875326669631326cfb1ba3e92b6f72244c32ffecf93ad21c0cad8455d3e169d0e3f060
|
|
||||||
languageName: node
|
|
||||||
linkType: hard
|
|
||||||
|
|
||||||
"react-is@npm:^17.0.1":
|
"react-is@npm:^17.0.1":
|
||||||
version: 17.0.1
|
version: 17.0.1
|
||||||
resolution: "react-is@npm:17.0.1"
|
resolution: "react-is@npm:17.0.1"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user