Move typscript test copy script to scripts folder and run once (#6749)

This commit is contained in:
Daniel Tschinder 2017-11-06 16:46:49 +01:00 committed by Brian Ng
parent cc66495a95
commit 7dbed2170e
37 changed files with 183 additions and 70 deletions

View File

@ -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"));
}
}

View File

@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["typescript", "classProperties"]
}

View File

@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["typescript", "classProperties"]
}

View File

@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["typescript", "classProperties"]
}

View File

@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["typescript", "classProperties"]
}

View File

@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["typescript", "classProperties"]
}

View File

@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["typescript", "classProperties"]
}

View File

@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["typescript", "classProperties"]
}

View File

@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["typescript", "classProperties"]
}

View File

@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["typescript", "classProperties"]
}

View File

@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["typescript", "classProperties"]
}

View File

@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["typescript", "classProperties"]
}

View File

@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["typescript", "classProperties"]
}

View File

@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["typescript", "classProperties"]
}

View File

@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["typescript", "classProperties"]
}

View File

@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["typescript", "classProperties"]
}

View File

@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["typescript", "classProperties"]
}

View File

@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["typescript", "classProperties"]
}

View File

@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["typescript", "classProperties"]
}

View File

@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["typescript", "classProperties"]
}

View File

@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["typescript", "classProperties"]
}

View File

@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["typescript", "classProperties"]
}

View File

@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["typescript", "classProperties"]
}

View File

@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["typescript", "classProperties"]
}

View File

@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["typescript", "classProperties"]
}

View File

@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["typescript", "classProperties"]
}

View File

@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["typescript", "classProperties"]
}

View File

@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["typescript", "classProperties"]
}

View File

@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["typescript", "classProperties"]
}

View File

@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["typescript", "classProperties"]
}

View File

@ -1,4 +1,4 @@
{ {
"sourceType": "module", "sourceType": "module",
"plugins": ["typescript", "classProperties"] "plugins": ["typescript"]
} }

View File

@ -0,0 +1,3 @@
export type T = number;
export enum E {}
export interface I {}

View File

@ -0,0 +1,3 @@
export type T = number;
export enum E {}
export interface I {}

View File

@ -0,0 +1,3 @@
{
"plugins": ["exportExtensions", "typescript"]
}

View File

@ -0,0 +1 @@
function f< T >() {}

View File

@ -0,0 +1 @@
function f<T>() {}

View File

@ -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"));
}
}
}