Skip to content

Commit

Permalink
Move @babel/node tests (#13037)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Mar 23, 2021
1 parent 4f72713 commit afef4f8
Show file tree
Hide file tree
Showing 60 changed files with 42 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import { createRequire } from "module";
const require = createRequire(import.meta.url);

const dirname = path.dirname(fileURLToPath(import.meta.url));
const fixtureLoc = path.join(dirname, "fixtures");
const fixtureLoc = path.join(dirname, "fixtures", "cli");
const tmpLoc = path.join(dirname, "tmp");
const binLoc = path.join(dirname, "../lib/babel-node");

const fileFilter = function (x) {
return x !== ".DS_Store";
Expand Down Expand Up @@ -93,9 +94,7 @@ const assertTest = function (stdout, stderr, opts) {
}
};

const buildTest = function (binName, testName, opts) {
const binLoc = path.join(dirname, "../lib", binName);

const buildTest = function (testName, opts) {
return function (callback) {
saveInFiles(opts.inFiles);
let args = [binLoc];
Expand Down Expand Up @@ -139,62 +138,57 @@ const buildTest = function (binName, testName, opts) {
};
};

fs.readdirSync(fixtureLoc).forEach(function (binName) {
if (binName[0] === ".") return;

const suiteLoc = path.join(fixtureLoc, binName);
describe("bin/" + binName, function () {
let cwd;
describe("bin/babel-node", function () {
let cwd;

beforeEach(() => {
cwd = process.cwd();
beforeEach(() => {
cwd = process.cwd();

if (fs.existsSync(tmpLoc)) {
for (const child of fs.readdirSync(tmpLoc)) {
rimraf.sync(path.join(tmpLoc, child));
}
} else {
fs.mkdirSync(tmpLoc);
if (fs.existsSync(tmpLoc)) {
for (const child of fs.readdirSync(tmpLoc)) {
rimraf.sync(path.join(tmpLoc, child));
}
} else {
fs.mkdirSync(tmpLoc);
}

process.chdir(tmpLoc);
});
process.chdir(tmpLoc);
});

afterEach(() => {
process.chdir(cwd);
});
afterEach(() => {
process.chdir(cwd);
});

fs.readdirSync(suiteLoc).forEach(function (testName) {
if (testName[0] === ".") return;
fs.readdirSync(fixtureLoc).forEach(function (testName) {
if (testName[0] === ".") return;

const testLoc = path.join(suiteLoc, testName);
const testLoc = path.join(fixtureLoc, testName);

const opts = {
args: [],
};
const opts = {
args: [],
};

const optionsLoc = path.join(testLoc, "options.json");
if (fs.existsSync(optionsLoc)) Object.assign(opts, require(optionsLoc));
const optionsLoc = path.join(testLoc, "options.json");
if (fs.existsSync(optionsLoc)) Object.assign(opts, require(optionsLoc));

["stdout", "stdin", "stderr"].forEach(function (key) {
const loc = path.join(testLoc, key + ".txt");
if (fs.existsSync(loc)) {
opts[key] = helper.readFile(loc);
} else {
opts[key] = opts[key] || "";
}
});
["stdout", "stdin", "stderr"].forEach(function (key) {
const loc = path.join(testLoc, key + ".txt");
if (fs.existsSync(loc)) {
opts[key] = helper.readFile(loc);
} else {
opts[key] = opts[key] || "";
}
});

opts.outFiles = readDir(path.join(testLoc, "out-files"), fileFilter);
opts.inFiles = readDir(path.join(testLoc, "in-files"), fileFilter);
opts.outFiles = readDir(path.join(testLoc, "out-files"), fileFilter);
opts.inFiles = readDir(path.join(testLoc, "in-files"), fileFilter);

const babelrcLoc = path.join(testLoc, ".babelrc");
if (fs.existsSync(babelrcLoc)) {
// copy .babelrc file to tmp directory
opts.inFiles[".babelrc"] = helper.readFile(babelrcLoc);
}
const babelrcLoc = path.join(testLoc, ".babelrc");
if (fs.existsSync(babelrcLoc)) {
// copy .babelrc file to tmp directory
opts.inFiles[".babelrc"] = helper.readFile(babelrcLoc);
}

it(testName, buildTest(binName, testName, opts), 20000);
});
it(testName, buildTest(testName, opts), 20000);
});
});

0 comments on commit afef4f8

Please sign in to comment.