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

test: add console warn spy on babel-register tests #11780

Merged
merged 2 commits into from Jul 2, 2020
Merged
Changes from 1 commit
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
18 changes: 16 additions & 2 deletions packages/babel-register/test/cache.js
Expand Up @@ -31,6 +31,8 @@ function resetCache() {
describe("@babel/register - caching", () => {
describe("cache", () => {
let load, get, save;
let stderr = "";
let consoleWarnSpy;

beforeEach(() => {
// Since lib/cache is a singleton we need to fully reload it
Expand All @@ -40,9 +42,16 @@ describe("@babel/register - caching", () => {
load = cache.load;
get = cache.get;
save = cache.save;

consoleWarnSpy = jest
.spyOn(console, "warn")
.mockImplementation(err => (stderr += err));
JLHwung marked this conversation as resolved.
Show resolved Hide resolved
});

afterEach(cleanCache);
afterEach(() => {
cleanCache();
consoleWarnSpy.mockRestore();
});
afterAll(resetCache);

it("should load and get cached data", () => {
Expand Down Expand Up @@ -88,10 +97,12 @@ describe("@babel/register - caching", () => {
if (process.platform !== "win32") {
it("should be disabled when CACHE_PATH is not allowed to read", () => {
writeCache({ foo: "bar" }, 0o266);

load();

expect(get()).toEqual({});
expect(consoleWarnSpy.mock.calls[0][0]).toContain(
"Babel could not read cache file",
);
});
}

Expand All @@ -104,6 +115,9 @@ describe("@babel/register - caching", () => {
process.nextTick(() => {
load();
expect(get()).toEqual({});
expect(consoleWarnSpy.mock.calls[0][0]).toContain(
"Babel could not write cache to file",
);
cb();
});
});
Expand Down