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

Diverse improvements #23

Merged
merged 8 commits into from
Nov 10, 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
5 changes: 4 additions & 1 deletion .github/knip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ const config: KnipConfig = {
ignore: ["**/__mocks__/**", "**/__fixtures__/**"],
ignoreExportsUsedInFile: true,
// eslint can also be safely ignored as per the docs: https://knip.dev/guides/handling-issues#eslint--jest
ignoreDependencies: ["eslint-config-prettier", "eslint-plugin-prettier", "@types/jest", "@mswjs/data", "tsx", "simple-git"],
// ts-node is used by jest
ignoreDependencies: ["eslint-config-prettier", "eslint-plugin-prettier", "@types/jest", "@mswjs/data", "simple-git", "ts-node"],
eslint: true,
// Knip doesn't recognize 'bun publish'
ignoreBinaries: ["publish"],
};

export default config;
2 changes: 1 addition & 1 deletion .github/workflows/jest-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
fetch-depth: 0

- name: Jest With Coverage
run: yarn install --immutable --immutable-cache --check-cache && yarn test
run: bun install --frozen-lockfile && bun run jest:test

- name: Add Jest Report to Summary
if: always()
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/no-empty-strings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ jobs:
with:
node-version: "20.10.0"
- name: Get GitHub App token
if: ${{ env.APP_ID && env.APP_PRIVATE_KEY }}
uses: tibdex/[email protected]
id: get_installation_token
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
env:
APP_ID: ${{ secrets.APP_ID }}
APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }}
- uses: oven-sh/setup-bun@v2
- name: Install Dependencies
run: |
Expand All @@ -27,7 +31,7 @@ jobs:
run: |
bun .github/empty-string-checker.ts
env:
GITHUB_TOKEN: ${{ steps.get_installation_token.outputs.token }}
GITHUB_TOKEN: ${{ steps.get_installation_token.outputs.token || secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
GITHUB_BASE_REF: ${{ github.base_ref }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ static/dist
coverage
junit.xml
cypress/screenshots
dist
dist
test-dashboard.md
Binary file modified bun.lockb
Binary file not shown.
10 changes: 0 additions & 10 deletions jest.config.json

This file was deleted.

27 changes: 27 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { Config } from "jest";

const cfg: Config = {
transform: {
"^.+\\.tsx?$": [
"ts-jest",
{
useESM: true,
},
],
},
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
coveragePathIgnorePatterns: ["node_modules", "mocks"],
collectCoverage: true,
coverageReporters: ["json", "lcov", "text", "clover", "json-summary"],
reporters: ["default", "jest-junit", "jest-md-dashboard"],
coverageDirectory: "coverage",
testTimeout: 20000,
roots: ["<rootDir>", "tests"],
extensionsToTreatAsEsm: [".ts"],
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
},
setupFilesAfterEnv: ["dotenv/config"],
};

export default cfg;
18 changes: 11 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"engines": {
"node": ">=20.10.0"
},
"type": "module",
"module": "dist/index.mjs",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down Expand Up @@ -50,7 +51,7 @@
"knip": "knip --config .github/knip.ts",
"knip-ci": "knip --no-exit-code --reporter json --config .github/knip.ts",
"prepare": "node .husky/install.mjs",
"test": "jest --setupFiles dotenv/config --coverage"
"jest:test": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest --setupFiles dotenv/config --coverage"
},
"keywords": [
"typescript",
Expand Down Expand Up @@ -83,24 +84,27 @@
"@cspell/dict-software-terms": "^3.3.18",
"@cspell/dict-typescript": "^3.1.2",
"@eslint/js": "^9.14.0",
"@jest/globals": "29.7.0",
"@jest/globals": "^29.7.0",
"@mswjs/data": "0.16.1",
"@types/jest": "29.5.12",
"@types/node": "^20.11.19",
"cross-env": "^7.0.3",
"cspell": "^8.4.0",
"eslint": "^9.14.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-check-file": "^2.8.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-sonarjs": "^2.0.4",
"husky": "^9.0.11",
"jest": "29.7.0",
"jest-junit": "16.0.0",
"jest-md-dashboard": "0.8.0",
"jest": "^29.7.0",
"jest-junit": "^16.0.0",
"jest-md-dashboard": "^0.8.0",
"knip": "^5.0.1",
"lint-staged": "^15.2.2",
"npm-run-all": "^4.1.5",
"prettier": "^3.3.3",
"ts-jest": "29.1.2",
"simple-git": "^3.27.0",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"tsup": "8.1.0",
"typescript": "^5.5.4",
"typescript-eslint": "^8.13.0"
Expand Down
49 changes: 24 additions & 25 deletions tests/sdk.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { afterAll, afterEach, beforeAll, describe, expect, it, jest } from "@jest/globals";
import { EmitterWebhookEventName } from "@octokit/webhooks";
import * as crypto from "crypto";
import { http, HttpResponse } from "msw";
import { Context } from "../src/context";
import { createPlugin } from "../src/server";
import { server } from "./__mocks__/node";
Expand All @@ -23,7 +24,7 @@ const issueCommentedEvent = {
eventPayload: issueCommented.eventPayload,
};

const sdkOctokitImportPath = "../src/sdk/octokit";
const sdkOctokitImportPath = "../src/octokit";
const githubActionImportPath = "@actions/github";
const githubCoreImportPath = "@actions/core";

Expand Down Expand Up @@ -54,8 +55,8 @@ async function getWorkerInputs(stateId: string, eventName: string, eventPayload:
const inputs = {
stateId,
eventName,
eventPayload: JSON.stringify(eventPayload),
settings: JSON.stringify(settings),
eventPayload,
settings,
authToken,
ref,
};
Expand Down Expand Up @@ -128,19 +129,17 @@ describe("SDK worker tests", () => {
});
it("Should handle thrown errors", async () => {
const createComment = jest.fn();
jest.mock(sdkOctokitImportPath, () => ({
customOctokit: class MockOctokit {
constructor() {
return {
rest: {
issues: {
createComment,
},
},
};
}
},
}));
server.use(
http.post(
"https://api.github.com/repos/:owner/:repo/issues/:issue_number/comments",
async ({ params, request }) => {
const body = (await request.json()) as { body: string };
createComment({ ...params, issue_number: Number(params.issue_number), body: body?.body });
return new HttpResponse();
},
{ once: true }
)
);

const { createPlugin } = await import("../src/server");
const app = createPlugin(
Expand Down Expand Up @@ -177,7 +176,7 @@ describe("SDK worker tests", () => {

<!-- Ubiquity - undefined - - undefined
{
"caller": "error"
"caller": "handler"
}
-->
`,
Expand Down Expand Up @@ -209,7 +208,7 @@ describe("SDK actions tests", () => {
it("Should accept correct request", async () => {
const inputs = getWorkerInputs("stateId", issueCommentedEvent.eventName, issueCommentedEvent.eventPayload, {}, "test_token", "");
const githubInputs = await inputs;
jest.mock(githubActionImportPath, () => ({
jest.unstable_mockModule(githubActionImportPath, () => ({
context: {
runId: "1",
payload: {
Expand All @@ -220,12 +219,12 @@ describe("SDK actions tests", () => {
}));
const setOutput = jest.fn();
const setFailed = jest.fn();
jest.mock(githubCoreImportPath, () => ({
jest.unstable_mockModule(githubCoreImportPath, () => ({
setOutput,
setFailed,
}));
const createDispatchEvent = jest.fn();
jest.mock("../src/sdk/octokit", () => ({
jest.unstable_mockModule(sdkOctokitImportPath, () => ({
customOctokit: class MockOctokit {
constructor() {
return {
Expand Down Expand Up @@ -266,7 +265,7 @@ describe("SDK actions tests", () => {
const inputs = getWorkerInputs("stateId", issueCommentedEvent.eventName, issueCommentedEvent.eventPayload, {}, "test_token", "");
const githubInputs = await inputs;

jest.mock("@actions/github", () => ({
jest.unstable_mockModule("@actions/github", () => ({
context: {
runId: "1",
payload: {
Expand All @@ -280,7 +279,7 @@ describe("SDK actions tests", () => {
}));
const setOutput = jest.fn();
const setFailed = jest.fn();
jest.mock(githubCoreImportPath, () => ({
jest.unstable_mockModule(githubCoreImportPath, () => ({
setOutput,
setFailed,
}));
Expand All @@ -303,7 +302,7 @@ describe("SDK actions tests", () => {
const inputs = getWorkerInputs("stateId", issueCommentedEvent.eventName, issueCommentedEvent.eventPayload, {}, "test_token", "");
const githubInputs = await inputs;

jest.mock(githubActionImportPath, () => ({
jest.unstable_mockModule(githubActionImportPath, () => ({
context: {
runId: "1",
payload: {
Expand All @@ -323,12 +322,12 @@ describe("SDK actions tests", () => {
}));
const setOutput = jest.fn();
const setFailed = jest.fn();
jest.mock(githubCoreImportPath, () => ({
jest.unstable_mockModule(githubCoreImportPath, () => ({
setOutput,
setFailed,
}));
const createDispatchEventFn = jest.fn();
jest.mock(sdkOctokitImportPath, () => ({
jest.unstable_mockModule(sdkOctokitImportPath, () => ({
customOctokit: class MockOctokit {
constructor() {
return {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */

/* Modules */
"module": "commonjs" /* Specify what module code is generated. */,
"module": "ESNext" /* Specify what module code is generated. */,
// "rootDir": "./", /* Specify the root folder within your source files. */
"moduleResolution": "Node" /* Specify how TypeScript looks up a file from a given module specifier. */,
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
Expand Down
Loading