chore: remove babel-register generated test artifacts (#11776)
* chore: use customized cache path in babel-register path * chore: remove node_modules cache after tests
This commit is contained in:
parent
d67629b114
commit
ae1e40a678
1
Makefile
1
Makefile
@ -135,6 +135,7 @@ clean: test-clean
|
||||
rm -rf packages/babel-polyfill/dist
|
||||
rm -rf coverage
|
||||
rm -rf packages/*/npm-debug*
|
||||
rm -rf node_modules/.cache
|
||||
|
||||
test-clean:
|
||||
$(foreach source, $(SOURCES), \
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
process.env.BABEL_DISABLE_CACHE = "true";
|
||||
require("@babel/register").default({
|
||||
ignore: false
|
||||
ignore: false,
|
||||
});
|
||||
|
||||
@ -7,6 +7,7 @@ let currentOptions;
|
||||
let sourceMapSupport = false;
|
||||
|
||||
const registerFile = require.resolve("../lib/node");
|
||||
const testCacheFilename = path.join(__dirname, ".babel");
|
||||
const testFile = require.resolve("./fixtures/babelrc/es2015");
|
||||
const testFileContent = fs.readFileSync(testFile);
|
||||
const sourceMapTestFile = require.resolve("./fixtures/source-map/index");
|
||||
@ -41,10 +42,23 @@ const defaultOptions = {
|
||||
ignoreNodeModules: false,
|
||||
};
|
||||
|
||||
function cleanCache() {
|
||||
try {
|
||||
fs.unlinkSync(testCacheFilename);
|
||||
} catch (e) {
|
||||
// It is convenient to always try to clear
|
||||
}
|
||||
}
|
||||
|
||||
function resetCache() {
|
||||
process.env.BABEL_CACHE_PATH = null;
|
||||
}
|
||||
|
||||
describe("@babel/register", function () {
|
||||
let babelRegister;
|
||||
|
||||
function setupRegister(config = { babelrc: false }) {
|
||||
process.env.BABEL_CACHE_PATH = testCacheFilename;
|
||||
config = {
|
||||
cwd: path.dirname(testFile),
|
||||
...config,
|
||||
@ -60,6 +74,7 @@ describe("@babel/register", function () {
|
||||
delete require.cache[registerFile];
|
||||
babelRegister = null;
|
||||
}
|
||||
cleanCache();
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
@ -70,6 +85,10 @@ describe("@babel/register", function () {
|
||||
jest.resetModules();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
resetCache();
|
||||
});
|
||||
|
||||
test("registers hook correctly", () => {
|
||||
setupRegister();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user