Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove babel-register generated test artifacts #11776

Merged
merged 2 commits into from Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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