convert @babel/helper-transform-fixture-test-runner to typescript (#12923)
* babel-helper-transform-fixture-test-runner flowts rename * babel-helper-transform-fixture-test-runner flowts convert * babel-helper-transform-fixture-test-runner * babel-helper-transform-fixture-test-runner eslint fixes * babel-helper-transform-fixture-test-runner type fix * babel-helper-transform-fixture-test-runner * yarn install
This commit is contained in:
parent
b97a627964
commit
ff8e9f74d8
@ -24,5 +24,8 @@
|
|||||||
"quick-lru": "5.1.0",
|
"quick-lru": "5.1.0",
|
||||||
"regenerator-runtime": "^0.13.7",
|
"regenerator-runtime": "^0.13.7",
|
||||||
"source-map": "^0.5.0"
|
"source-map": "^0.5.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/jest": "^25.2.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,6 +14,7 @@ import fs from "fs";
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import vm from "vm";
|
import vm from "vm";
|
||||||
import QuickLRU from "quick-lru";
|
import QuickLRU from "quick-lru";
|
||||||
|
// @ts-ignore
|
||||||
import escapeRegExp from "./escape-regexp.cjs";
|
import escapeRegExp from "./escape-regexp.cjs";
|
||||||
import { fileURLToPath } from "url";
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
@ -69,10 +70,12 @@ function createContext() {
|
|||||||
function runCacheableScriptInTestContext(
|
function runCacheableScriptInTestContext(
|
||||||
filename: string,
|
filename: string,
|
||||||
srcFn: () => string,
|
srcFn: () => string,
|
||||||
context: Context,
|
// todo(flow->ts) was Context type, but it is missing
|
||||||
moduleCache: Object,
|
context: any,
|
||||||
|
moduleCache: any,
|
||||||
) {
|
) {
|
||||||
let cached = cachedScripts.get(filename);
|
// todo(flow->ts) improve types
|
||||||
|
let cached: any = cachedScripts.get(filename);
|
||||||
if (!cached) {
|
if (!cached) {
|
||||||
const code = `(function (exports, require, module, __filename, __dirname) {\n${srcFn()}\n});`;
|
const code = `(function (exports, require, module, __filename, __dirname) {\n${srcFn()}\n});`;
|
||||||
cached = {
|
cached = {
|
||||||
@ -90,7 +93,9 @@ function runCacheableScriptInTestContext(
|
|||||||
produceCachedData: true,
|
produceCachedData: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// @ts-expect-error todo(flow->ts) improve types
|
||||||
if (script.cachedDataProduced) {
|
if (script.cachedDataProduced) {
|
||||||
|
// @ts-expect-error todo(flow->ts) improve types
|
||||||
cached.cachedData = script.cachedData;
|
cached.cachedData = script.cachedData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,8 +120,9 @@ function runCacheableScriptInTestContext(
|
|||||||
function runModuleInTestContext(
|
function runModuleInTestContext(
|
||||||
id: string,
|
id: string,
|
||||||
relativeFilename: string,
|
relativeFilename: string,
|
||||||
context: Context,
|
// todo(flow->ts) was Context type, but it is missing
|
||||||
moduleCache: Object,
|
context: any,
|
||||||
|
moduleCache: any,
|
||||||
) {
|
) {
|
||||||
const filename = require.resolve(id, {
|
const filename = require.resolve(id, {
|
||||||
paths: [path.dirname(relativeFilename)],
|
paths: [path.dirname(relativeFilename)],
|
||||||
@ -148,7 +154,9 @@ function runModuleInTestContext(
|
|||||||
*/
|
*/
|
||||||
export function runCodeInTestContext(
|
export function runCodeInTestContext(
|
||||||
code: string,
|
code: string,
|
||||||
opts: { filename: string },
|
opts: {
|
||||||
|
filename: string;
|
||||||
|
},
|
||||||
context = sharedTestContext,
|
context = sharedTestContext,
|
||||||
) {
|
) {
|
||||||
const filename = opts.filename;
|
const filename = opts.filename;
|
||||||
@ -192,7 +200,8 @@ function run(task) {
|
|||||||
stderr,
|
stderr,
|
||||||
} = task;
|
} = task;
|
||||||
|
|
||||||
function getOpts(self) {
|
// todo(flow->ts) add proper return type (added any, because empty object is inferred)
|
||||||
|
function getOpts(self): any {
|
||||||
const newOpts = merge(
|
const newOpts = merge(
|
||||||
{
|
{
|
||||||
ast: true,
|
ast: true,
|
||||||
@ -226,7 +235,7 @@ function run(task) {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Pass empty location to include the whole file in the output.
|
// Pass empty location to include the whole file in the output.
|
||||||
err.message =
|
err.message =
|
||||||
`${exec.loc}: ${err.message}\n` + codeFrameColumns(execCode, {});
|
`${exec.loc}: ${err.message}\n` + codeFrameColumns(execCode, {} as any);
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -336,7 +345,7 @@ function validateFile(actualCode, expectedLoc, expectedCode) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizeOutput(code, normalizePathSeparator) {
|
function normalizeOutput(code, normalizePathSeparator?) {
|
||||||
const projectRoot = path.resolve(
|
const projectRoot = path.resolve(
|
||||||
path.dirname(fileURLToPath(import.meta.url)),
|
path.dirname(fileURLToPath(import.meta.url)),
|
||||||
"../../../",
|
"../../../",
|
||||||
@ -391,11 +400,21 @@ expect.extend({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
// eslint-disable-next-line no-redeclare,@typescript-eslint/no-unused-vars
|
||||||
|
namespace jest {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
interface Matchers<R> {
|
||||||
|
toEqualFile({ filename, code }): jest.CustomMatcherResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default function (
|
export default function (
|
||||||
fixturesLoc: string,
|
fixturesLoc: string,
|
||||||
name: string,
|
name: string,
|
||||||
suiteOpts = {},
|
suiteOpts: any = {},
|
||||||
taskOpts = {},
|
taskOpts: any = {},
|
||||||
dynamicOpts?: Function,
|
dynamicOpts?: Function,
|
||||||
) {
|
) {
|
||||||
const suites = getFixtures(fixturesLoc);
|
const suites = getFixtures(fixturesLoc);
|
||||||
@ -432,6 +451,7 @@ export default function (
|
|||||||
|
|
||||||
if (dynamicOpts) dynamicOpts(task.options, task);
|
if (dynamicOpts) dynamicOpts(task.options, task);
|
||||||
|
|
||||||
|
// @ts-expect-error todo(flow->ts) missing property
|
||||||
if (task.externalHelpers) {
|
if (task.externalHelpers) {
|
||||||
(task.options.plugins ??= []).push([
|
(task.options.plugins ??= []).push([
|
||||||
"external-helpers",
|
"external-helpers",
|
||||||
88
yarn.lock
88
yarn.lock
@ -821,6 +821,7 @@ __metadata:
|
|||||||
"@babel/code-frame": "workspace:^7.12.13"
|
"@babel/code-frame": "workspace:^7.12.13"
|
||||||
"@babel/core": "workspace:^7.13.10"
|
"@babel/core": "workspace:^7.13.10"
|
||||||
"@babel/helper-fixtures": "workspace:^7.13.10"
|
"@babel/helper-fixtures": "workspace:^7.13.10"
|
||||||
|
"@types/jest": ^25.2.2
|
||||||
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 : "
|
||||||
lodash: ^4.17.19
|
lodash: ^4.17.19
|
||||||
@ -3713,6 +3714,18 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"@jest/types@npm:^25.5.0":
|
||||||
|
version: 25.5.0
|
||||||
|
resolution: "@jest/types@npm:25.5.0"
|
||||||
|
dependencies:
|
||||||
|
"@types/istanbul-lib-coverage": ^2.0.0
|
||||||
|
"@types/istanbul-reports": ^1.1.1
|
||||||
|
"@types/yargs": ^15.0.0
|
||||||
|
chalk: ^3.0.0
|
||||||
|
checksum: 33ad68320efb297c4bd98975105130e1b4096d631decfc5a093691e24f27fce0410b4a7c5a87b736873271ebc003e48e853529587e584b3152efca572139a4a3
|
||||||
|
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"
|
||||||
@ -4041,6 +4054,16 @@ __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"
|
||||||
@ -4050,6 +4073,16 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"@types/jest@npm:^25.2.2":
|
||||||
|
version: 25.2.3
|
||||||
|
resolution: "@types/jest@npm:25.2.3"
|
||||||
|
dependencies:
|
||||||
|
jest-diff: ^25.2.1
|
||||||
|
pretty-format: ^25.2.1
|
||||||
|
checksum: fe92624fd7b3b5358ffba8e59108b484de1d01df08dfc66bb597d59d09900db1950717adb8d42ce5f81ba615fa0b8de55fd5446808d92f75b45e08fcbe4cec6e
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"@types/jsesc@npm:^2.5.0":
|
"@types/jsesc@npm:^2.5.0":
|
||||||
version: 2.5.1
|
version: 2.5.1
|
||||||
resolution: "@types/jsesc@npm:2.5.1"
|
resolution: "@types/jsesc@npm:2.5.1"
|
||||||
@ -6102,6 +6135,16 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"chalk@npm:^3.0.0":
|
||||||
|
version: 3.0.0
|
||||||
|
resolution: "chalk@npm:3.0.0"
|
||||||
|
dependencies:
|
||||||
|
ansi-styles: ^4.1.0
|
||||||
|
supports-color: ^7.1.0
|
||||||
|
checksum: 4018b0c812880da595d0d7b8159939527b72f58d3370e2fdc1a24d9abd460bab851695d7eca014082f110d5702d1221b05493fec430ccce375de907d50cc48c1
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"char-regex@npm:^1.0.2":
|
"char-regex@npm:^1.0.2":
|
||||||
version: 1.0.2
|
version: 1.0.2
|
||||||
resolution: "char-regex@npm:1.0.2"
|
resolution: "char-regex@npm:1.0.2"
|
||||||
@ -6975,6 +7018,13 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"diff-sequences@npm:^25.2.6":
|
||||||
|
version: 25.2.6
|
||||||
|
resolution: "diff-sequences@npm:25.2.6"
|
||||||
|
checksum: 332484fc00f6beca726d8dbc13095f6006527002bef936a07b4e6bbec681fbaac484e1a7ea4e9ab0d53e375d1cde9e642c8cce31dfe6329cfdf8f01f26b17505
|
||||||
|
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"
|
||||||
@ -9821,6 +9871,18 @@ fsevents@^1.2.7:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"jest-diff@npm:^25.2.1":
|
||||||
|
version: 25.5.0
|
||||||
|
resolution: "jest-diff@npm:25.5.0"
|
||||||
|
dependencies:
|
||||||
|
chalk: ^3.0.0
|
||||||
|
diff-sequences: ^25.2.6
|
||||||
|
jest-get-type: ^25.2.6
|
||||||
|
pretty-format: ^25.5.0
|
||||||
|
checksum: 14a2634ecb159a9a2f061239db1cea0c889e7a72ab05bd1fa799db30efca2ce79291372823f5e3468d9bc856f404f312e44e89c171eea8132b5835d12f71d0b3
|
||||||
|
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"
|
||||||
@ -9884,6 +9946,13 @@ fsevents@^1.2.7:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"jest-get-type@npm:^25.2.6":
|
||||||
|
version: 25.2.6
|
||||||
|
resolution: "jest-get-type@npm:25.2.6"
|
||||||
|
checksum: 6051fcb75cdaa8fad66fd5a1e91d2c1597e9ccc54eecd5cd489fd73a00e322d28cb5859b656a8224a41eddab0ecfb875df9ec62f545a76afa1a55d3ba97fba6d
|
||||||
|
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"
|
||||||
@ -12243,6 +12312,18 @@ fsevents@^1.2.7:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"pretty-format@npm:^25.2.1, pretty-format@npm:^25.5.0":
|
||||||
|
version: 25.5.0
|
||||||
|
resolution: "pretty-format@npm:25.5.0"
|
||||||
|
dependencies:
|
||||||
|
"@jest/types": ^25.5.0
|
||||||
|
ansi-regex: ^5.0.0
|
||||||
|
ansi-styles: ^4.0.0
|
||||||
|
react-is: ^16.12.0
|
||||||
|
checksum: f7cc631d51e22c809d429d20facfd886ba0b212d419d153467872f68688256c2c55563bf70e943b7347ec9180b41a1d19c4235dc171850f9d5382a52959c0245
|
||||||
|
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"
|
||||||
@ -12441,6 +12522,13 @@ fsevents@^1.2.7:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"react-is@npm:^16.12.0":
|
||||||
|
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