test: add console warn spy on babel-register tests (#11780)
* test: add console warn spy on register tests * address review comments
This commit is contained in:
parent
ae1e40a678
commit
1a65ba76f0
@ -31,6 +31,7 @@ function resetCache() {
|
|||||||
describe("@babel/register - caching", () => {
|
describe("@babel/register - caching", () => {
|
||||||
describe("cache", () => {
|
describe("cache", () => {
|
||||||
let load, get, save;
|
let load, get, save;
|
||||||
|
let consoleWarnSpy;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// Since lib/cache is a singleton we need to fully reload it
|
// Since lib/cache is a singleton we need to fully reload it
|
||||||
@ -40,9 +41,14 @@ describe("@babel/register - caching", () => {
|
|||||||
load = cache.load;
|
load = cache.load;
|
||||||
get = cache.get;
|
get = cache.get;
|
||||||
save = cache.save;
|
save = cache.save;
|
||||||
|
|
||||||
|
consoleWarnSpy = jest.spyOn(console, "warn").mockImplementation(() => {});
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(cleanCache);
|
afterEach(() => {
|
||||||
|
cleanCache();
|
||||||
|
consoleWarnSpy.mockRestore();
|
||||||
|
});
|
||||||
afterAll(resetCache);
|
afterAll(resetCache);
|
||||||
|
|
||||||
it("should load and get cached data", () => {
|
it("should load and get cached data", () => {
|
||||||
@ -88,10 +94,12 @@ describe("@babel/register - caching", () => {
|
|||||||
if (process.platform !== "win32") {
|
if (process.platform !== "win32") {
|
||||||
it("should be disabled when CACHE_PATH is not allowed to read", () => {
|
it("should be disabled when CACHE_PATH is not allowed to read", () => {
|
||||||
writeCache({ foo: "bar" }, 0o266);
|
writeCache({ foo: "bar" }, 0o266);
|
||||||
|
|
||||||
load();
|
load();
|
||||||
|
|
||||||
expect(get()).toEqual({});
|
expect(get()).toEqual({});
|
||||||
|
expect(consoleWarnSpy.mock.calls[0][0]).toContain(
|
||||||
|
"Babel could not read cache file",
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,6 +112,9 @@ describe("@babel/register - caching", () => {
|
|||||||
process.nextTick(() => {
|
process.nextTick(() => {
|
||||||
load();
|
load();
|
||||||
expect(get()).toEqual({});
|
expect(get()).toEqual({});
|
||||||
|
expect(consoleWarnSpy.mock.calls[0][0]).toContain(
|
||||||
|
"Babel could not write cache to file",
|
||||||
|
);
|
||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user