Skip to content

Commit

Permalink
[tests] Fallback for fs.promises on node 6
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Oct 24, 2019
1 parent c98dca5 commit cc8aa30
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions packages/babel-core/test/config-chain.js
Expand Up @@ -4,6 +4,20 @@ import path from "path";
import escapeRegExp from "lodash/escapeRegExp";
import { loadOptions as loadOptionsOrig } from "../lib";

// TODO: In Babel 8, we can directly uses fs.promises which is supported by
// node 8+
const pfs =
fs.promises ??
new Proxy(fs, {
get: (target, name) => (...args) =>
new Promise((resolve, reject) =>
target[name](...args, (error, result) => {
if (error) reject(error);
else resolve(result);
}),
),
});

function fixture(...args) {
return path.join(__dirname, "fixtures", "config", ...args);
}
Expand All @@ -26,10 +40,10 @@ function pairs(items) {
}

async function getTemp(name) {
const cwd = await fs.promises.mkdtemp(os.tmpdir() + path.sep + name);
const cwd = await pfs.mkdtemp(os.tmpdir() + path.sep + name);
const tmp = name => path.join(cwd, name);
const config = name =>
fs.promises.copyFile(fixture("config-files-templates", name), tmp(name));
pfs.copyFile(fixture("config-files-templates", name), tmp(name));
return { cwd, tmp, config };
}

Expand Down

0 comments on commit cc8aa30

Please sign in to comment.