mirror of
https://github.com/actions/cache.git
synced 2024-11-22 09:51:25 +01:00
Fix test
This commit is contained in:
parent
84e606dfac
commit
96e5a46c57
1 changed files with 5 additions and 11 deletions
|
@ -1,9 +1,10 @@
|
||||||
import * as exec from "@actions/exec";
|
import * as exec from "@actions/exec";
|
||||||
import * as io from "@actions/io";
|
import * as io from "@actions/io";
|
||||||
import * as fs from "fs";
|
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import * as tar from "../src/tar";
|
import * as tar from "../src/tar";
|
||||||
|
|
||||||
|
import fs = require("fs");
|
||||||
|
|
||||||
jest.mock("@actions/exec");
|
jest.mock("@actions/exec");
|
||||||
jest.mock("@actions/io");
|
jest.mock("@actions/io");
|
||||||
|
|
||||||
|
@ -42,25 +43,18 @@ test("extract BSD tar", async () => {
|
||||||
test("extract GNU tar", async () => {
|
test("extract GNU tar", async () => {
|
||||||
const IS_WINDOWS = process.platform === "win32";
|
const IS_WINDOWS = process.platform === "win32";
|
||||||
if (IS_WINDOWS) {
|
if (IS_WINDOWS) {
|
||||||
jest.mock("fs");
|
jest.spyOn(fs, "existsSync").mockReturnValueOnce(false);
|
||||||
|
jest.spyOn(tar, "isGnuTar").mockReturnValue(Promise.resolve(true));
|
||||||
|
|
||||||
const execMock = jest.spyOn(exec, "exec");
|
const execMock = jest.spyOn(exec, "exec");
|
||||||
const existsSyncMock = jest
|
|
||||||
.spyOn(fs, "existsSync")
|
|
||||||
.mockReturnValue(false);
|
|
||||||
const isGnuTarMock = jest
|
|
||||||
.spyOn(tar, "isGnuTar")
|
|
||||||
.mockReturnValue(Promise.resolve(true));
|
|
||||||
const archivePath = `${process.env["windir"]}\\fakepath\\cache.tar`;
|
const archivePath = `${process.env["windir"]}\\fakepath\\cache.tar`;
|
||||||
const targetDirectory = "~/.npm/cache";
|
const targetDirectory = "~/.npm/cache";
|
||||||
|
|
||||||
await tar.extractTar(archivePath, targetDirectory);
|
await tar.extractTar(archivePath, targetDirectory);
|
||||||
|
|
||||||
expect(existsSyncMock).toHaveBeenCalledTimes(1);
|
|
||||||
expect(isGnuTarMock).toHaveBeenCalledTimes(1);
|
|
||||||
expect(execMock).toHaveBeenCalledTimes(2);
|
expect(execMock).toHaveBeenCalledTimes(2);
|
||||||
expect(execMock).toHaveBeenLastCalledWith(
|
expect(execMock).toHaveBeenLastCalledWith(
|
||||||
"tar",
|
`"tar"`,
|
||||||
[
|
[
|
||||||
"-xz",
|
"-xz",
|
||||||
"-f",
|
"-f",
|
||||||
|
|
Loading…
Reference in a new issue