Skip to content

Commit

Permalink
chore: mock the github actions warning to avoid leaking annotations (#96
Browse files Browse the repository at this point in the history
)
  • Loading branch information
byCedric authored Jun 17, 2021
1 parent 79ebfbc commit a11a47a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/cache.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os from 'os';
import { join } from 'path';
import * as remoteCache from '@actions/cache';
import * as core from '@actions/core';
import * as toolCache from '@actions/tool-cache';

import * as cache from '../src/cache';
Expand Down Expand Up @@ -34,6 +35,7 @@ describe('fromRemoteCache', () => {
beforeEach(() => {
spy = {
restore: jest.spyOn(remoteCache, 'restoreCache').mockImplementation(),
warning: jest.spyOn(core, 'warning').mockImplementation(),
};
});

Expand All @@ -44,6 +46,7 @@ describe('fromRemoteCache', () => {
afterAll(() => {
utils.restoreEnv();
spy.restore.mockRestore();
spy.warning.mockRestore();
});

it('restores remote cache with default key', async () => {
Expand Down Expand Up @@ -80,6 +83,7 @@ describe('fromRemoteCache', () => {
const error = new Error('Cache Service Url not found, unable to restore cache.');
spy.restore.mockRejectedValueOnce(error);
await expect(cache.fromRemoteCache('3.20.1', 'yarn')).resolves.toBeUndefined();
expect(spy.warning).toHaveBeenCalledWith(expect.stringContaining('Skipping remote cache'));
});
});

Expand All @@ -89,11 +93,13 @@ describe('toRemoteCache', () => {
beforeEach(() => {
spy = {
save: jest.spyOn(remoteCache, 'saveCache').mockImplementation(),
warning: jest.spyOn(core, 'warning').mockImplementation(),
};
});

afterAll(() => {
spy.save.mockRestore();
spy.warning.mockRestore();
});

it('saves remote cache with default key', async () => {
Expand All @@ -120,5 +126,6 @@ describe('toRemoteCache', () => {
const error = new Error('Cache Service Url not found, unable to restore cache.');
spy.save.mockRejectedValueOnce(error);
await expect(cache.toRemoteCache(join('local', 'path'), '3.20.1', 'yarn')).resolves.toBeUndefined();
expect(spy.warning).toHaveBeenCalledWith(expect.stringContaining('Skipping remote cache'));
});
});

0 comments on commit a11a47a

Please sign in to comment.