Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Fix deprecations and warnings #51

Merged
merged 2 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ beforeEach(() => {
});

test("fails with no inputs", async () => {
jest.spyOn(core, "getInput").mockImplementation((name, options?) => {
jest.spyOn(core, "getInput").mockImplementation((_name, _options?) => {
return "";
});

Expand All @@ -33,7 +33,7 @@ test("fails with no inputs", async () => {
});

test("installs packages into profile", async () => {
jest.spyOn(core, "getInput").mockImplementation((name, options?) => {
jest.spyOn(core, "getInput").mockImplementation((name, _options?) => {
switch (name) {
case "packages":
return "nixpkgs#package1,nixpkgs#package2,github:yaxitech/ragenix";
Expand All @@ -44,14 +44,14 @@ test("installs packages into profile", async () => {

jest.spyOn(nix, "maybeAddNixpkgs").mockImplementation(async (pkg) => pkg);

jest.spyOn(nix, "runNix").mockImplementation(async (args, options?) => {
jest.spyOn(nix, "runNix").mockImplementation(async (_args, _options?) => {
return Promise.resolve({} as exec.ExecOutput);
});

await main();

const nixProfileDir = await getAndDeleteCreatedProfileDir();
expect(nix.runNix).toBeCalledWith(
expect(nix.runNix).toHaveBeenCalledWith(
[
"profile",
"install",
Expand All @@ -74,7 +74,7 @@ test("installs packages into profile", async () => {
});

test("installs expr into profile without inputs-from", async () => {
jest.spyOn(core, "getInput").mockImplementation((name, options?) => {
jest.spyOn(core, "getInput").mockImplementation((name, _options?) => {
switch (name) {
case "expr":
return "pkgs.wurzelpfropf";
Expand Down Expand Up @@ -104,7 +104,7 @@ test("installs expr into profile without inputs-from", async () => {
await main();

const nixProfileDir = await getAndDeleteCreatedProfileDir();
expect(nix.runNix).toBeCalledWith(
expect(nix.runNix).toHaveBeenCalledWith(
[
"profile",
"install",
Expand Down Expand Up @@ -132,7 +132,7 @@ test("installs expr into profile without inputs-from", async () => {
});

test("installs packages and expr into profile with inputs-from", async () => {
jest.spyOn(core, "getInput").mockImplementation((name, options?) => {
jest.spyOn(core, "getInput").mockImplementation((name, _options?) => {
switch (name) {
case "expr":
return "pkgs.wurzelpfropf";
Expand Down Expand Up @@ -180,7 +180,7 @@ test("installs packages and expr into profile with inputs-from", async () => {
await main();

const nixProfileDir = await getAndDeleteCreatedProfileDir();
expect(nix.runNix).toBeCalledWith(
expect(nix.runNix).toHaveBeenCalledWith(
[
"profile",
"install",
Expand All @@ -198,7 +198,7 @@ test("installs packages and expr into profile with inputs-from", async () => {
expect(nix.getRepoLockedUrl).toHaveBeenCalledTimes(1);
expect(nix.getNixpkgs).toHaveBeenCalledTimes(1);

expect(nix.runNix).toBeCalledWith(
expect(nix.runNix).toHaveBeenCalledWith(
[
"profile",
"install",
Expand Down Expand Up @@ -232,8 +232,8 @@ async function getAndDeleteCreatedProfileDir(): Promise<string> {

await post();

expect(io.rmRF).toBeCalledTimes(1);
expect(io.rmRF).toBeCalledWith(tmpDir);
expect(io.rmRF).toHaveBeenCalledTimes(1);
expect(io.rmRF).toHaveBeenCalledWith(tmpDir);
expect(process.env.STATE_NIX_PROFILE_TMPDIR).toBe("");

return path.join(tmpDir as string, ".nix-profile");
Expand Down
10 changes: 5 additions & 5 deletions __tests__/nix.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ExecOutput, getExecOutput } from "@actions/exec";
import { ExecOutput } from "@actions/exec";
import * as nix from "../src/nix";

// The online tests run quite slowly on GitHub Actions
Expand Down Expand Up @@ -54,23 +54,23 @@ test("getRepoLockedUrl works", async () => {

const res = await nix.getRepoLockedUrl(".");
expect(res).toMatch(/^file:\/\/\/nix\/store\/.*?\?narHash\=.*$/);
expect(nix.getRepoLockedUrl).toBeCalledTimes(1);
expect(nix.getRepoLockedUrl).toHaveBeenCalledTimes(1);
});

test("getRepoLockedUrl does not fail for invalid flake", async () => {
jest.spyOn(nix, "getRepoLockedUrl");

const res = await nix.getRepoLockedUrl("/");
expect(res).toBe("");
expect(nix.getRepoLockedUrl).toBeCalledTimes(1);
expect(nix.getRepoLockedUrl).toHaveBeenCalledTimes(1);
});

test("getFlakeLockedUrl works", async () => {
jest.spyOn(nix, "getFlakeLockedUrl");

const res = await nix.getFlakeLockedUrl(".");
expect(res).toMatch(/^file:\/\/\/nix\/store\/.*?\?narHash\=.*$/);
expect(nix.getFlakeLockedUrl).toBeCalledTimes(1);
expect(nix.getFlakeLockedUrl).toHaveBeenCalledTimes(1);
});

test("getFlakeLockedUrl fails for invalid flake", async () => {
Expand All @@ -79,7 +79,7 @@ test("getFlakeLockedUrl fails for invalid flake", async () => {
await expect(() => nix.getFlakeLockedUrl("doesnotexist")).rejects.toThrow(
/The process '\/.*?\/nix' failed with exit code 1/,
);
expect(nix.getFlakeLockedUrl).toBeCalledTimes(1);
expect(nix.getFlakeLockedUrl).toHaveBeenCalledTimes(1);
});

test("getNixpkgs with inputs-from works", async () => {
Expand Down