generated from threeal/action-starter
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: reintroduce unit testing using Jest (#122)
* test: add test for `yarn.disableGlobalCache` function * test(eslint): add configuration for test files * ci(test): add `test-package` job * test: add test for `yarn.enable` function * test: add test for `yarn.install` function
- Loading branch information
Showing
6 changed files
with
2,587 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,12 @@ | |
"env": { | ||
"node": true | ||
} | ||
}, | ||
{ | ||
"files": ["**/*.test.*"], | ||
"env": { | ||
"jest": true | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"testMatch": ["**/*.test.*"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { jest } from "@jest/globals"; | ||
|
||
jest.unstable_mockModule("@actions/exec", () => ({ | ||
exec: jest.fn(), | ||
})); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it("should disable Yarn global cache", async () => { | ||
const { exec } = await import("@actions/exec"); | ||
const yarn = (await import("./yarn.mjs")).default; | ||
|
||
await yarn.disableGlobalCache(); | ||
|
||
expect(exec).toHaveBeenCalledTimes(1); | ||
expect(exec).toHaveBeenCalledWith("corepack", [ | ||
"yarn", | ||
"config", | ||
"set", | ||
"enableGlobalCache", | ||
"false", | ||
]); | ||
}); | ||
|
||
it("should enable Yarn", async () => { | ||
const { exec } = await import("@actions/exec"); | ||
const yarn = (await import("./yarn.mjs")).default; | ||
|
||
await yarn.enable(); | ||
|
||
expect(exec).toHaveBeenCalledTimes(1); | ||
expect(exec).toHaveBeenCalledWith("corepack", ["enable", "yarn"]); | ||
}); | ||
|
||
it("should install package using Yarn", async () => { | ||
const { exec } = await import("@actions/exec"); | ||
const yarn = (await import("./yarn.mjs")).default; | ||
|
||
await yarn.install(); | ||
|
||
expect(exec).toHaveBeenCalledTimes(1); | ||
expect(exec).toHaveBeenCalledWith("corepack", ["yarn", "install"], { | ||
env: { | ||
...process.env, | ||
GITHUB_ACTIONS: "", | ||
FORCE_COLOR: "true", | ||
CI: "", | ||
}, | ||
}); | ||
}); |
Oops, something went wrong.