Skip to content

Commit

Permalink
fix: allow to execute util scripts (#12670)
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
armano2 committed Jan 21, 2021
1 parent 10978bb commit 6783308
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 19 deletions.
54 changes: 37 additions & 17 deletions packages/babel-generator/scripts/generate-typescript-tests.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
/*
Copies tests from the @babel/parser's TypeScript test suite to @babel/generator.
*/
const {
copySync,
emptyDirSync,
existsSync,
readdirSync,
readFileSync,
} = require("fs-extra");
const fs = require("fs");
const { join } = require("path");

const testsFrom = join(
Expand All @@ -16,15 +10,16 @@ const testsFrom = join(
);
const testsTo = join(__dirname, "../test/fixtures/typescript");

emptyDirSync(testsTo);
fs.rmdirSync(testsTo, { recursive: true });
fs.mkdirSync(testsTo);

copySync(join(testsFrom, "options.json"), join(testsTo, "options.json"));
fs.copyFileSync(join(testsFrom, "options.json"), join(testsTo, "options.json"));

for (const groupName of readdirSync(testsFrom)) {
for (const groupName of fs.readdirSync(testsFrom)) {
if (groupName === "options.json") continue;

const groupFromDir = join(testsFrom, groupName);
const testNames = readdirSync(groupFromDir);
const testNames = fs.readdirSync(groupFromDir);
const groupHasOptions = testNames.includes("options.json");

for (const testName of testNames) {
Expand All @@ -37,10 +32,14 @@ for (const groupName of readdirSync(testsFrom)) {

let optionsJsonFrom;
const ownOptions = join(testFromDir, "options.json");
if (existsSync(ownOptions)) {
const options = JSON.parse(readFileSync(ownOptions));
if (fs.existsSync(ownOptions)) {
const options = JSON.parse(fs.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) {
if (
options.throws ||
!options.plugins ||
options.plugins.indexOf("estree") >= 0
) {
continue;
}
optionsJsonFrom = ownOptions;
Expand All @@ -49,10 +48,31 @@ for (const groupName of readdirSync(testsFrom)) {
optionsJsonFrom = join(groupFromDir, "options.json");
}

emptyDirSync(testToDir);
fs.rmdirSync(testToDir, { recursive: true });
fs.mkdirSync(testToDir);
if (optionsJsonFrom) {
copySync(optionsJsonFrom, join(testToDir, "options.json"));
fs.copyFileSync(optionsJsonFrom, join(testToDir, "options.json"));
}
if (fs.existsSync(join(testFromDir, "input.js"))) {
fs.copyFileSync(
join(testFromDir, "input.js"),
join(testToDir, "input.js")
);
} else if (fs.existsSync(join(testFromDir, "input.tsx"))) {
fs.copyFileSync(
join(testFromDir, "input.tsx"),
join(testToDir, "input.tsx")
);
} else if (fs.existsSync(join(testFromDir, "input.jsx"))) {
fs.copyFileSync(
join(testFromDir, "input.jsx"),
join(testToDir, "input.jsx")
);
} else if (fs.existsSync(join(testFromDir, "input.ts"))) {
fs.copyFileSync(
join(testFromDir, "input.ts"),
join(testToDir, "input.ts")
);
}
copySync(join(testFromDir, "actual.js"), join(testToDir, "actual.js"));
}
}
4 changes: 2 additions & 2 deletions packages/babel-preset-env/scripts/smoke-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const fs = require("fs-extra");
const fs = require("fs");
const execSync = require("child_process").execSync;
const path = require("path");
const pkg = require("../package.json");
Expand All @@ -14,7 +14,7 @@ try {

console.log("Setting up smoke test dependencies");

fs.ensureDirSync(tempFolderPath);
fs.mkdirSync(tempFolderPath);
process.chdir(tempFolderPath);

const babelCliVersion = pkg.devDependencies["babel-cli"];
Expand Down

0 comments on commit 6783308

Please sign in to comment.