Skip to content
Draft
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
5 changes: 4 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = {
parser: "@typescript-eslint/parser",
parserOptions: {
tsconfigRootDir: __dirname,
project: ["./tsconfig.json"],
project: ["./tsconfig.json", "./tsconfig.test.json"],
},
plugins: ["@typescript-eslint"],
extends: [
Expand All @@ -13,4 +13,7 @@ module.exports = {
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"prettier",
],
env: {
node: true
}
};
15 changes: 11 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
// [...]
transform: {
'^.+\\.ts$': [
'ts-jest',
{
tsconfig: 'tsconfig.test.json',
},
],
},
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@actions/github": "5.1.1"
},
"devDependencies": {
"@jest/globals": "29.7.0",
"@types/node": "18.18.4",
"@typescript-eslint/eslint-plugin": "6.7.4",
"@typescript-eslint/parser": "6.7.4",
Expand Down
34 changes: 34 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { beforeEach, describe, expect, it, jest } from "@jest/globals";

describe("index", () => {
beforeEach(() => {
jest.resetModules();
});

it("calls run when imported", () => {
jest.doMock("./main", () => ({
run: jest.fn(() => Promise.resolve()),
}));

const { run } = require("./main"); // Import after setting up the mock
require("./index");

expect(run).toHaveBeenCalled();
});

it("sets action failed when there is an error", async () => {
jest.doMock("@actions/core", () => ({
setFailed: jest.fn(),
}));

const mockError = new Error("An error occurred");
jest.doMock("./main", () => ({
run: jest.fn(() => Promise.reject(mockError)),
}));

const { setFailed } = require("@actions/core"); // Import after setting up the mock
await require("./index");

expect(setFailed).toHaveBeenCalledWith(mockError)
});
});
5 changes: 5 additions & 0 deletions tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "dist"],
"include": ["**/*.test.ts"]
}
Loading