Skip to content

Commit

Permalink
chore: remove babel-register generated test artifacts (#11776)
Browse files Browse the repository at this point in the history
* chore: use customized cache path in babel-register path

* chore: remove node_modules cache after tests
  • Loading branch information
JLHwung committed Jul 1, 2020
1 parent d67629b commit ae1e40a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -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), \
Expand Down
3 changes: 2 additions & 1 deletion packages/babel-register/test/fixtures/browserify/register.js
@@ -1,3 +1,4 @@
process.env.BABEL_DISABLE_CACHE = "true";
require("@babel/register").default({
ignore: false
ignore: false,
});
19 changes: 19 additions & 0 deletions packages/babel-register/test/index.js
Expand Up @@ -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");
Expand Down Expand Up @@ -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,
Expand All @@ -60,6 +74,7 @@ describe("@babel/register", function () {
delete require.cache[registerFile];
babelRegister = null;
}
cleanCache();
}

afterEach(() => {
Expand All @@ -70,6 +85,10 @@ describe("@babel/register", function () {
jest.resetModules();
});

afterAll(() => {
resetCache();
});

test("registers hook correctly", () => {
setupRegister();

Expand Down

0 comments on commit ae1e40a

Please sign in to comment.