Move typscript test copy script to scripts folder and run once (#6749)
This commit is contained in:
parent
cc66495a95
commit
7dbed2170e
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
Copies tests from babylon's TypeScript test suite to @babel/generator.
|
||||||
|
*/
|
||||||
|
const {
|
||||||
|
copySync,
|
||||||
|
emptyDirSync,
|
||||||
|
existsSync,
|
||||||
|
readdirSync,
|
||||||
|
readFileSync,
|
||||||
|
} = require("fs-extra");
|
||||||
|
const { join } = require("path");
|
||||||
|
|
||||||
|
const testsFrom = join(__dirname, "../../babylon/test/fixtures/typescript");
|
||||||
|
const testsTo = join(__dirname, "../test/fixtures/typescript");
|
||||||
|
|
||||||
|
emptyDirSync(testsTo);
|
||||||
|
|
||||||
|
copySync(join(testsFrom, "options.json"), join(testsTo, "options.json"));
|
||||||
|
|
||||||
|
for (const groupName of readdirSync(testsFrom)) {
|
||||||
|
if (groupName === "options.json") continue;
|
||||||
|
|
||||||
|
const groupFromDir = join(testsFrom, groupName);
|
||||||
|
const testNames = readdirSync(groupFromDir);
|
||||||
|
const groupHasOptions = testNames.includes("options.json");
|
||||||
|
|
||||||
|
for (const testName of testNames) {
|
||||||
|
if (testName === "options.json") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const testFromDir = join(groupFromDir, testName);
|
||||||
|
const testToDir = join(testsTo, `${groupName}-${testName}`);
|
||||||
|
|
||||||
|
let optionsJsonFrom;
|
||||||
|
const ownOptions = join(testFromDir, "options.json");
|
||||||
|
if (existsSync(ownOptions)) {
|
||||||
|
const options = JSON.parse(readFileSync(ownOptions));
|
||||||
|
// Don't include a test that doesn't parse or does not provide babel AST
|
||||||
|
if (options.throws || options.plugins.indexOf("estree") >= 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
optionsJsonFrom = ownOptions;
|
||||||
|
} else if (groupHasOptions) {
|
||||||
|
// Copy group options to each individual one, since we don't have groups here.
|
||||||
|
optionsJsonFrom = join(groupFromDir, "options.json");
|
||||||
|
}
|
||||||
|
|
||||||
|
emptyDirSync(testToDir);
|
||||||
|
if (optionsJsonFrom) {
|
||||||
|
copySync(optionsJsonFrom, join(testToDir, "options.json"));
|
||||||
|
}
|
||||||
|
copySync(join(testFromDir, "actual.js"), join(testToDir, "actual.js"));
|
||||||
|
}
|
||||||
|
}
|
||||||
4
packages/babel-generator/test/fixtures/typescript/class-abstract/options.json
vendored
Normal file
4
packages/babel-generator/test/fixtures/typescript/class-abstract/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"sourceType": "module",
|
||||||
|
"plugins": ["typescript", "classProperties"]
|
||||||
|
}
|
||||||
4
packages/babel-generator/test/fixtures/typescript/class-constructor/options.json
vendored
Normal file
4
packages/babel-generator/test/fixtures/typescript/class-constructor/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"sourceType": "module",
|
||||||
|
"plugins": ["typescript", "classProperties"]
|
||||||
|
}
|
||||||
4
packages/babel-generator/test/fixtures/typescript/class-declare/options.json
vendored
Normal file
4
packages/babel-generator/test/fixtures/typescript/class-declare/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"sourceType": "module",
|
||||||
|
"plugins": ["typescript", "classProperties"]
|
||||||
|
}
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"sourceType": "module",
|
||||||
|
"plugins": ["typescript", "classProperties"]
|
||||||
|
}
|
||||||
4
packages/babel-generator/test/fixtures/typescript/class-expression-extends/options.json
vendored
Normal file
4
packages/babel-generator/test/fixtures/typescript/class-expression-extends/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"sourceType": "module",
|
||||||
|
"plugins": ["typescript", "classProperties"]
|
||||||
|
}
|
||||||
4
packages/babel-generator/test/fixtures/typescript/class-expression-generic/options.json
vendored
Normal file
4
packages/babel-generator/test/fixtures/typescript/class-expression-generic/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"sourceType": "module",
|
||||||
|
"plugins": ["typescript", "classProperties"]
|
||||||
|
}
|
||||||
4
packages/babel-generator/test/fixtures/typescript/class-expression-implements/options.json
vendored
Normal file
4
packages/babel-generator/test/fixtures/typescript/class-expression-implements/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"sourceType": "module",
|
||||||
|
"plugins": ["typescript", "classProperties"]
|
||||||
|
}
|
||||||
4
packages/babel-generator/test/fixtures/typescript/class-extends-implements/options.json
vendored
Normal file
4
packages/babel-generator/test/fixtures/typescript/class-extends-implements/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"sourceType": "module",
|
||||||
|
"plugins": ["typescript", "classProperties"]
|
||||||
|
}
|
||||||
4
packages/babel-generator/test/fixtures/typescript/class-extends/options.json
vendored
Normal file
4
packages/babel-generator/test/fixtures/typescript/class-extends/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"sourceType": "module",
|
||||||
|
"plugins": ["typescript", "classProperties"]
|
||||||
|
}
|
||||||
4
packages/babel-generator/test/fixtures/typescript/class-generic/options.json
vendored
Normal file
4
packages/babel-generator/test/fixtures/typescript/class-generic/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"sourceType": "module",
|
||||||
|
"plugins": ["typescript", "classProperties"]
|
||||||
|
}
|
||||||
4
packages/babel-generator/test/fixtures/typescript/class-get-generic/options.json
vendored
Normal file
4
packages/babel-generator/test/fixtures/typescript/class-get-generic/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"sourceType": "module",
|
||||||
|
"plugins": ["typescript", "classProperties"]
|
||||||
|
}
|
||||||
4
packages/babel-generator/test/fixtures/typescript/class-implements/options.json
vendored
Normal file
4
packages/babel-generator/test/fixtures/typescript/class-implements/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"sourceType": "module",
|
||||||
|
"plugins": ["typescript", "classProperties"]
|
||||||
|
}
|
||||||
4
packages/babel-generator/test/fixtures/typescript/class-index-signature/options.json
vendored
Normal file
4
packages/babel-generator/test/fixtures/typescript/class-index-signature/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"sourceType": "module",
|
||||||
|
"plugins": ["typescript", "classProperties"]
|
||||||
|
}
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"sourceType": "module",
|
||||||
|
"plugins": ["typescript", "classProperties"]
|
||||||
|
}
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"sourceType": "module",
|
||||||
|
"plugins": ["typescript", "classProperties"]
|
||||||
|
}
|
||||||
4
packages/babel-generator/test/fixtures/typescript/class-method-computed/options.json
vendored
Normal file
4
packages/babel-generator/test/fixtures/typescript/class-method-computed/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"sourceType": "module",
|
||||||
|
"plugins": ["typescript", "classProperties"]
|
||||||
|
}
|
||||||
4
packages/babel-generator/test/fixtures/typescript/class-method-generic/options.json
vendored
Normal file
4
packages/babel-generator/test/fixtures/typescript/class-method-generic/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"sourceType": "module",
|
||||||
|
"plugins": ["typescript", "classProperties"]
|
||||||
|
}
|
||||||
4
packages/babel-generator/test/fixtures/typescript/class-method-no-body/options.json
vendored
Normal file
4
packages/babel-generator/test/fixtures/typescript/class-method-no-body/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"sourceType": "module",
|
||||||
|
"plugins": ["typescript", "classProperties"]
|
||||||
|
}
|
||||||
4
packages/babel-generator/test/fixtures/typescript/class-method-optional/options.json
vendored
Normal file
4
packages/babel-generator/test/fixtures/typescript/class-method-optional/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"sourceType": "module",
|
||||||
|
"plugins": ["typescript", "classProperties"]
|
||||||
|
}
|
||||||
4
packages/babel-generator/test/fixtures/typescript/class-method-return-type/options.json
vendored
Normal file
4
packages/babel-generator/test/fixtures/typescript/class-method-return-type/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"sourceType": "module",
|
||||||
|
"plugins": ["typescript", "classProperties"]
|
||||||
|
}
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"sourceType": "module",
|
||||||
|
"plugins": ["typescript", "classProperties"]
|
||||||
|
}
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"sourceType": "module",
|
||||||
|
"plugins": ["typescript", "classProperties"]
|
||||||
|
}
|
||||||
4
packages/babel-generator/test/fixtures/typescript/class-modifiers-accessors/options.json
vendored
Normal file
4
packages/babel-generator/test/fixtures/typescript/class-modifiers-accessors/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"sourceType": "module",
|
||||||
|
"plugins": ["typescript", "classProperties"]
|
||||||
|
}
|
||||||
4
packages/babel-generator/test/fixtures/typescript/class-modifiers-methods-async/options.json
vendored
Normal file
4
packages/babel-generator/test/fixtures/typescript/class-modifiers-methods-async/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"sourceType": "module",
|
||||||
|
"plugins": ["typescript", "classProperties"]
|
||||||
|
}
|
||||||
4
packages/babel-generator/test/fixtures/typescript/class-modifiers-properties/options.json
vendored
Normal file
4
packages/babel-generator/test/fixtures/typescript/class-modifiers-properties/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"sourceType": "module",
|
||||||
|
"plugins": ["typescript", "classProperties"]
|
||||||
|
}
|
||||||
4
packages/babel-generator/test/fixtures/typescript/class-parameter-properties/options.json
vendored
Normal file
4
packages/babel-generator/test/fixtures/typescript/class-parameter-properties/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"sourceType": "module",
|
||||||
|
"plugins": ["typescript", "classProperties"]
|
||||||
|
}
|
||||||
4
packages/babel-generator/test/fixtures/typescript/class-properties/options.json
vendored
Normal file
4
packages/babel-generator/test/fixtures/typescript/class-properties/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"sourceType": "module",
|
||||||
|
"plugins": ["typescript", "classProperties"]
|
||||||
|
}
|
||||||
4
packages/babel-generator/test/fixtures/typescript/class-property-computed/options.json
vendored
Normal file
4
packages/babel-generator/test/fixtures/typescript/class-property-computed/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"sourceType": "module",
|
||||||
|
"plugins": ["typescript", "classProperties"]
|
||||||
|
}
|
||||||
4
packages/babel-generator/test/fixtures/typescript/class-static/options.json
vendored
Normal file
4
packages/babel-generator/test/fixtures/typescript/class-static/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"sourceType": "module",
|
||||||
|
"plugins": ["typescript", "classProperties"]
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"sourceType": "module",
|
"sourceType": "module",
|
||||||
"plugins": ["typescript", "classProperties"]
|
"plugins": ["typescript"]
|
||||||
}
|
}
|
||||||
|
|||||||
3
packages/babel-generator/test/fixtures/typescript/regression-is-default-export/actual.js
vendored
Normal file
3
packages/babel-generator/test/fixtures/typescript/regression-is-default-export/actual.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export type T = number;
|
||||||
|
export enum E {}
|
||||||
|
export interface I {}
|
||||||
3
packages/babel-generator/test/fixtures/typescript/regression-is-default-export/expected.js
vendored
Normal file
3
packages/babel-generator/test/fixtures/typescript/regression-is-default-export/expected.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export type T = number;
|
||||||
|
export enum E {}
|
||||||
|
export interface I {}
|
||||||
3
packages/babel-generator/test/fixtures/typescript/regression-is-default-export/options.json
vendored
Normal file
3
packages/babel-generator/test/fixtures/typescript/regression-is-default-export/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["exportExtensions", "typescript"]
|
||||||
|
}
|
||||||
1
packages/babel-generator/test/fixtures/typescript/type-arguments-whitespace/actual.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/typescript/type-arguments-whitespace/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
function f< T >() {}
|
||||||
1
packages/babel-generator/test/fixtures/typescript/type-arguments-whitespace/expected.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/typescript/type-arguments-whitespace/expected.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
function f<T>() {}
|
||||||
@ -1,69 +0,0 @@
|
|||||||
/*
|
|
||||||
Copies tests from babylon's TypeScript test suite to @babel/generator.
|
|
||||||
This script assumes that the "babylon" repository is adjacent to "babel".
|
|
||||||
*/
|
|
||||||
|
|
||||||
const {
|
|
||||||
copySync,
|
|
||||||
emptyDirSync,
|
|
||||||
existsSync,
|
|
||||||
readdirSync,
|
|
||||||
readFileSync,
|
|
||||||
} = require("fs-extra");
|
|
||||||
const { join } = require("path");
|
|
||||||
|
|
||||||
if (!module.parent) {
|
|
||||||
const testsFrom = join(
|
|
||||||
__dirname,
|
|
||||||
"..",
|
|
||||||
"..",
|
|
||||||
"..",
|
|
||||||
"..",
|
|
||||||
"babylon",
|
|
||||||
"test",
|
|
||||||
"fixtures",
|
|
||||||
"typescript",
|
|
||||||
);
|
|
||||||
const testsTo = join(__dirname, "fixtures", "typescript");
|
|
||||||
|
|
||||||
emptyDirSync(testsTo);
|
|
||||||
|
|
||||||
copySync(join(testsFrom, "options.json"), join(testsTo, "options.json"));
|
|
||||||
|
|
||||||
for (const groupName of readdirSync(testsFrom)) {
|
|
||||||
if (groupName === "options.json") continue;
|
|
||||||
|
|
||||||
const groupFromDir = join(testsFrom, groupName);
|
|
||||||
const testNames = readdirSync(groupFromDir);
|
|
||||||
const groupHasOptions = testNames.includes("options.json");
|
|
||||||
|
|
||||||
for (const testName of testNames) {
|
|
||||||
if (testName === "options.json") {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const testFromDir = join(groupFromDir, testName);
|
|
||||||
const testToDir = join(testsTo, `${groupName}-${testName}`);
|
|
||||||
|
|
||||||
let optionsJsonFrom;
|
|
||||||
const ownOptions = join(testFromDir, "options.json");
|
|
||||||
if (existsSync(ownOptions)) {
|
|
||||||
const options = JSON.parse(readFileSync(ownOptions));
|
|
||||||
// Don't include a test that doesn't parse.
|
|
||||||
if (options.throws) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
optionsJsonFrom = ownOptions;
|
|
||||||
} else if (groupHasOptions) {
|
|
||||||
// Copy group options to each individual one, since we don't have groups here.
|
|
||||||
optionsJsonFrom = join(groupFromDir, "options.json");
|
|
||||||
}
|
|
||||||
|
|
||||||
emptyDirSync(testToDir);
|
|
||||||
if (optionsJsonFrom) {
|
|
||||||
copySync(optionsJsonFrom, join(testToDir, "options.json"));
|
|
||||||
}
|
|
||||||
copySync(join(testFromDir, "actual.js"), join(testToDir, "actual.js"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user