From 511f7fa71969173918d6fef3a449064a875c2012 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Wed, 1 Jul 2020 23:07:07 -0400 Subject: [PATCH 1/2] test: add console warn spy on register tests --- packages/babel-register/test/cache.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/babel-register/test/cache.js b/packages/babel-register/test/cache.js index f4fb2de2e8ec..70953ce2639e 100644 --- a/packages/babel-register/test/cache.js +++ b/packages/babel-register/test/cache.js @@ -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 @@ -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)); }); - afterEach(cleanCache); + afterEach(() => { + cleanCache(); + consoleWarnSpy.mockRestore(); + }); afterAll(resetCache); it("should load and get cached data", () => { @@ -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", + ); }); } @@ -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(); }); }); From c0f00581786046e37eb660ce9e4d8d6c9ebe8652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Thu, 2 Jul 2020 10:13:17 -0400 Subject: [PATCH 2/2] address review comments --- packages/babel-register/test/cache.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/babel-register/test/cache.js b/packages/babel-register/test/cache.js index 70953ce2639e..ee939729dbf8 100644 --- a/packages/babel-register/test/cache.js +++ b/packages/babel-register/test/cache.js @@ -31,7 +31,6 @@ function resetCache() { describe("@babel/register - caching", () => { describe("cache", () => { let load, get, save; - let stderr = ""; let consoleWarnSpy; beforeEach(() => { @@ -43,9 +42,7 @@ describe("@babel/register - caching", () => { get = cache.get; save = cache.save; - consoleWarnSpy = jest - .spyOn(console, "warn") - .mockImplementation(err => (stderr += err)); + consoleWarnSpy = jest.spyOn(console, "warn").mockImplementation(() => {}); }); afterEach(() => {