Skip to content

Commit

Permalink
test: add console warn spy on babel-register tests (#11780)
Browse files Browse the repository at this point in the history
* test: add console warn spy on register tests

* address review comments
  • Loading branch information
JLHwung committed Jul 2, 2020
1 parent ae1e40a commit 1a65ba7
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/babel-register/test/cache.js
Expand Up @@ -31,6 +31,7 @@ function resetCache() {
describe("@babel/register - caching", () => {
describe("cache", () => {
let load, get, save;
let consoleWarnSpy;

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

consoleWarnSpy = jest.spyOn(console, "warn").mockImplementation(() => {});
});

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

it("should load and get cached data", () => {
Expand Down Expand Up @@ -88,10 +94,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 +112,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

0 comments on commit 1a65ba7

Please sign in to comment.