Move @babel/node tests (#13037)
This commit is contained in:
parent
4f727139ec
commit
afef4f85ff
@ -11,8 +11,9 @@ import { createRequire } from "module";
|
|||||||
const require = createRequire(import.meta.url);
|
const require = createRequire(import.meta.url);
|
||||||
|
|
||||||
const dirname = path.dirname(fileURLToPath(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 tmpLoc = path.join(dirname, "tmp");
|
||||||
|
const binLoc = path.join(dirname, "../lib/babel-node");
|
||||||
|
|
||||||
const fileFilter = function (x) {
|
const fileFilter = function (x) {
|
||||||
return x !== ".DS_Store";
|
return x !== ".DS_Store";
|
||||||
@ -93,9 +94,7 @@ const assertTest = function (stdout, stderr, opts) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const buildTest = function (binName, testName, opts) {
|
const buildTest = function (testName, opts) {
|
||||||
const binLoc = path.join(dirname, "../lib", binName);
|
|
||||||
|
|
||||||
return function (callback) {
|
return function (callback) {
|
||||||
saveInFiles(opts.inFiles);
|
saveInFiles(opts.inFiles);
|
||||||
let args = [binLoc];
|
let args = [binLoc];
|
||||||
@ -139,62 +138,57 @@ const buildTest = function (binName, testName, opts) {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
fs.readdirSync(fixtureLoc).forEach(function (binName) {
|
describe("bin/babel-node", function () {
|
||||||
if (binName[0] === ".") return;
|
let cwd;
|
||||||
|
|
||||||
const suiteLoc = path.join(fixtureLoc, binName);
|
beforeEach(() => {
|
||||||
describe("bin/" + binName, function () {
|
cwd = process.cwd();
|
||||||
let cwd;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
if (fs.existsSync(tmpLoc)) {
|
||||||
cwd = process.cwd();
|
for (const child of fs.readdirSync(tmpLoc)) {
|
||||||
|
rimraf.sync(path.join(tmpLoc, child));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fs.mkdirSync(tmpLoc);
|
||||||
|
}
|
||||||
|
|
||||||
if (fs.existsSync(tmpLoc)) {
|
process.chdir(tmpLoc);
|
||||||
for (const child of fs.readdirSync(tmpLoc)) {
|
});
|
||||||
rimraf.sync(path.join(tmpLoc, child));
|
|
||||||
}
|
afterEach(() => {
|
||||||
|
process.chdir(cwd);
|
||||||
|
});
|
||||||
|
|
||||||
|
fs.readdirSync(fixtureLoc).forEach(function (testName) {
|
||||||
|
if (testName[0] === ".") return;
|
||||||
|
|
||||||
|
const testLoc = path.join(fixtureLoc, testName);
|
||||||
|
|
||||||
|
const opts = {
|
||||||
|
args: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
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 {
|
} else {
|
||||||
fs.mkdirSync(tmpLoc);
|
opts[key] = opts[key] || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
process.chdir(tmpLoc);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
opts.outFiles = readDir(path.join(testLoc, "out-files"), fileFilter);
|
||||||
process.chdir(cwd);
|
opts.inFiles = readDir(path.join(testLoc, "in-files"), fileFilter);
|
||||||
});
|
|
||||||
|
|
||||||
fs.readdirSync(suiteLoc).forEach(function (testName) {
|
const babelrcLoc = path.join(testLoc, ".babelrc");
|
||||||
if (testName[0] === ".") return;
|
if (fs.existsSync(babelrcLoc)) {
|
||||||
|
// copy .babelrc file to tmp directory
|
||||||
|
opts.inFiles[".babelrc"] = helper.readFile(babelrcLoc);
|
||||||
|
}
|
||||||
|
|
||||||
const testLoc = path.join(suiteLoc, testName);
|
it(testName, buildTest(testName, opts), 20000);
|
||||||
|
|
||||||
const opts = {
|
|
||||||
args: [],
|
|
||||||
};
|
|
||||||
|
|
||||||
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] || "";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
it(testName, buildTest(binName, testName, opts), 20000);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
Loading…
x
Reference in New Issue
Block a user