diff --git a/templates/basic-js/index.js b/templates/basic-js/index.js index bc42c8f9dd..33209b3633 100644 --- a/templates/basic-js/index.js +++ b/templates/basic-js/index.js @@ -2,7 +2,7 @@ * This is the main entrypoint to your Probot app * @param {import('probot').Probot} app */ -module.exports = (app) => { +export default (app) => { // Your code here app.log.info("Yay, the app was loaded!"); diff --git a/templates/basic-js/package.json b/templates/basic-js/package.json index 7fa8c0920a..224f73b059 100644 --- a/templates/basic-js/package.json +++ b/templates/basic-js/package.json @@ -13,20 +13,17 @@ ], "scripts": { "start": "probot run ./index.js", - "test": "jest" + "test": "node --test" }, "dependencies": { "probot": "^13.0.1" }, "devDependencies": { - "jest": "^29.0.0", "nock": "^14.0.0-beta.5", "smee-client": "^2.0.0" }, "engines": { "node": ">= 18" }, - "jest": { - "testEnvironment": "node" - } + "type": "module" } diff --git a/templates/basic-js/test/index.test.js b/templates/basic-js/test/index.test.js index 9c930200d3..a07ae4f433 100644 --- a/templates/basic-js/test/index.test.js +++ b/templates/basic-js/test/index.test.js @@ -1,18 +1,28 @@ -const nock = require("nock"); +import nock from "nock"; // Requiring our app implementation -const myProbotApp = require(".."); -const { Probot, ProbotOctokit } = require("probot"); +import myProbotApp from "../index.js"; +import { Probot, ProbotOctokit } from "probot"; // Requiring our fixtures -const payload = require("./fixtures/issues.opened"); +//import payload from "./fixtures/issues.opened.json" with { type: "json" }; const issueCreatedBody = { body: "Thanks for opening this issue!" }; -const fs = require("fs"); -const path = require("path"); +import fs from "fs"; +import path from "path"; +import { fileURLToPath } from "url"; + +import { describe, beforeEach, afterEach, test } from "node:test"; +import assert from "node:assert"; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); const privateKey = fs.readFileSync( path.join(__dirname, "fixtures/mock-cert.pem"), "utf-8", ); +const payload = JSON.parse( + fs.readFileSync(path.join(__dirname, "fixtures/issues.opened.json"), "utf-8"), +); + describe("My Probot app", () => { let probot; @@ -44,7 +54,7 @@ describe("My Probot app", () => { // Test that a comment is posted .post("/repos/hiimbex/testing-things/issues/1/comments", (body) => { - expect(body).toMatchObject(issueCreatedBody); + assert.deepEqual(body, issueCreatedBody); return true; }) .reply(200); @@ -52,7 +62,7 @@ describe("My Probot app", () => { // Receive a webhook event await probot.receive({ name: "issues", payload }); - expect(mock.pendingMocks()).toStrictEqual([]); + assert.deepStrictEqual(mock.pendingMocks(), []); }); afterEach(() => { diff --git a/templates/basic-ts/jest.config.js b/templates/basic-ts/jest.config.js deleted file mode 100755 index 9ee81b0f34..0000000000 --- a/templates/basic-ts/jest.config.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports = { - roots: ["/src/", "/test/"], - transform: { - "^.+\\.tsx?$": "ts-jest", - }, - testRegex: "(/__tests__/.*|\\.(test|spec))\\.[tj]sx?$", - moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"], - testEnvironment: "node", -}; diff --git a/templates/basic-ts/package.json b/templates/basic-ts/package.json index 3d372f15f4..fd41804f57 100644 --- a/templates/basic-ts/package.json +++ b/templates/basic-ts/package.json @@ -14,21 +14,20 @@ "scripts": { "build": "tsc", "start": "probot run ./lib/index.js", - "test": "jest" + "test": "vitest" }, "dependencies": { "probot": "^13.0.1" }, "devDependencies": { - "@types/jest": "^29.0.0", "@types/node": "^20.0.0", - "jest": "^29.0.0", "nock": "^14.0.0-beta.5", "smee-client": "^2.0.0", - "ts-jest": "^29.0.0", + "vitest": "^1.3.1", "typescript": "^5.3.3" }, "engines": { "node": ">= 18" - } + }, + "type": "module" } diff --git a/templates/basic-ts/src/index.ts b/templates/basic-ts/src/index.ts index 8eeafa1265..0a68622485 100644 --- a/templates/basic-ts/src/index.ts +++ b/templates/basic-ts/src/index.ts @@ -1,6 +1,6 @@ import { Probot } from "probot"; -export = (app: Probot) => { +export default (app: Probot) => { app.on("issues.opened", async (context) => { const issueComment = context.issue({ body: "Thanks for opening this issue!", diff --git a/templates/basic-ts/test/index.test.ts b/templates/basic-ts/test/index.test.ts index b8326cb7b4..0eeaef19d6 100644 --- a/templates/basic-ts/test/index.test.ts +++ b/templates/basic-ts/test/index.test.ts @@ -3,19 +3,28 @@ import nock from "nock"; // Requiring our app implementation -import myProbotApp from "../src"; +import myProbotApp from "../src/index.js"; import { Probot, ProbotOctokit } from "probot"; // Requiring our fixtures -import payload from "./fixtures/issues.opened.json"; +//import payload from "./fixtures/issues.opened.json" with { "type": "json"}; +import fs from "fs"; +import path from "path"; +import { fileURLToPath } from "url"; +import { describe, beforeEach, afterEach, test, expect } from "vitest"; + const issueCreatedBody = { body: "Thanks for opening this issue!" }; -const fs = require("fs"); -const path = require("path"); + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); const privateKey = fs.readFileSync( path.join(__dirname, "fixtures/mock-cert.pem"), "utf-8", ); +const payload = JSON.parse( + fs.readFileSync(path.join(__dirname, "fixtures/issues.opened.json"), "utf-8"), +); + describe("My Probot app", () => { let probot: any; diff --git a/templates/basic-ts/tsconfig.json b/templates/basic-ts/tsconfig.json index a39a6f5362..37aaa7c205 100755 --- a/templates/basic-ts/tsconfig.json +++ b/templates/basic-ts/tsconfig.json @@ -1,73 +1,24 @@ { "compilerOptions": { - /* Basic Options */ - "incremental": true /* Enable incremental compilation */, - "target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */, - "module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */, - "lib": [ - "es2015", - "es2017" - ] /* Specify library files to be included in the compilation. */, - "allowJs": true /* Allow javascript files to be compiled. */, - "checkJs": true /* Report errors in .js files. */, - // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ - "declaration": true /* Generates corresponding '.d.ts' file. */, - // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ - "sourceMap": true /* Generates corresponding '.map' file. */, - // "outFile": "./", /* Concatenate and emit output to single file. */ - "outDir": "./lib" /* Redirect output structure to the directory. */, - // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ - // "composite": true, /* Enable project compilation */ - // "tsBuildInfoFile": "./" /* Specify file to store incremental compilation information */, - // "removeComments": true, /* Do not emit comments to output. */ - // "noEmit": true, /* Do not emit outputs. */ - // "importHelpers": true, /* Import emit helpers from 'tslib'. */ - // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ - // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + "incremental": true, + "target": "es2022", + "module": "Node16", + "declaration": true, + "sourceMap": true, + "outDir": "./lib", /* Strict Type-Checking Options */ - "strict": true /* Enable all strict type-checking options. */, - // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ - // "strictNullChecks": true, /* Enable strict null checks. */ - // "strictFunctionTypes": true, /* Enable strict checking of function types. */ - // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ - // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ - // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ - // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + "strict": true, /* Additional Checks */ - "noUnusedLocals": true /* Report errors on unused locals. */, - "noUnusedParameters": true /* Report errors on unused parameters. */, - "noImplicitReturns": true /* Report error when not all code paths in function return a value. */, - "noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, - /* Module Resolution Options */ - "moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */, - // "baseUrl": "./src" /* Base directory to resolve non-absolute module names. */, - // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ - // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ - // "typeRoots": [], /* List of folders to include type definitions from. */ - // "types": [], /* Type declaration files to be included in compilation. */ - // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just type checking. */ - "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, - // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ - // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ - - /* Source Map Options */ - // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ - // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ - // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ - // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ - - /* Experimental Options */ - // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ - // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ - - /* Advanced Options */ - "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */, - "resolveJsonModule": true, - "pretty": false, - "skipLibCheck": true + "moduleResolution": "Node16", + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true }, "include": ["src/"], "compileOnSave": false diff --git a/templates/basic-ts/vitest.config.ts b/templates/basic-ts/vitest.config.ts new file mode 100644 index 0000000000..94cb752256 --- /dev/null +++ b/templates/basic-ts/vitest.config.ts @@ -0,0 +1,10 @@ +import { defineConfig } from "vitest/config"; + +export default defineConfig({ + test: { + include: ["test/**/*.test.ts"], + coverage: { + provider: "v8", + }, + }, +}); diff --git a/templates/checks-js/index.js b/templates/checks-js/index.js index 9cc11abc75..9c075a9d89 100644 --- a/templates/checks-js/index.js +++ b/templates/checks-js/index.js @@ -5,7 +5,7 @@ * This is the main entrypoint to your Probot app * @param {import('probot').Probot} app */ -module.exports = (app) => { +export default (app) => { app.on(["check_suite.requested", "check_run.rerequested"], check); async function check(context) { diff --git a/templates/checks-js/package.json b/templates/checks-js/package.json index 7fa8c0920a..224f73b059 100644 --- a/templates/checks-js/package.json +++ b/templates/checks-js/package.json @@ -13,20 +13,17 @@ ], "scripts": { "start": "probot run ./index.js", - "test": "jest" + "test": "node --test" }, "dependencies": { "probot": "^13.0.1" }, "devDependencies": { - "jest": "^29.0.0", "nock": "^14.0.0-beta.5", "smee-client": "^2.0.0" }, "engines": { "node": ">= 18" }, - "jest": { - "testEnvironment": "node" - } + "type": "module" } diff --git a/templates/checks-js/test/index.test.js b/templates/checks-js/test/index.test.js index d9bd956d98..f1c8c16d0a 100644 --- a/templates/checks-js/test/index.test.js +++ b/templates/checks-js/test/index.test.js @@ -1,21 +1,40 @@ -const nock = require("nock"); +import nock from "nock"; // Requiring our app implementation -const myProbotApp = require(".."); -const { Probot, ProbotOctokit } = require("probot"); +import myProbotApp from "../index.js"; +import { Probot, ProbotOctokit } from "probot"; // Requiring our fixtures -const checkSuitePayload = require("./fixtures/check_suite.requested"); -const checkRunSuccess = require("./fixtures/check_run.created"); -const fs = require("fs"); -const path = require("path"); +//import checkSuitePayload from "./fixtures/check_suite.requested" with { type: "json" }; +//import checkRunSuccess from "./fixtures/check_run.created" with { type: "json" }; +import fs from "fs"; +import path from "path"; +import { fileURLToPath } from "url"; + +import { describe, beforeEach, afterEach, test } from "node:test"; +import assert from "node:assert"; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); const privateKey = fs.readFileSync( path.join(__dirname, "fixtures/mock-cert.pem"), "utf-8", ); +const checkSuitePayload = JSON.parse( + fs.readFileSync( + path.join(__dirname, "fixtures/check_suite.requested.json"), + "utf-8", + ), +); + +const checkRunSuccess = JSON.parse( + fs.readFileSync( + path.join(__dirname, "fixtures/check_run.created.json"), + "utf-8", + ), +); + describe("My Probot app", () => { let probot; - let mockCert; beforeEach(() => { nock.disableNetConnect(); @@ -45,7 +64,7 @@ describe("My Probot app", () => { .post("/repos/hiimbex/testing-things/check-runs", (body) => { body.started_at = "2018-10-05T17:35:21.594Z"; body.completed_at = "2018-10-05T17:35:53.683Z"; - expect(body).toMatchObject(checkRunSuccess); + assert.deepStrictEqual(body, checkRunSuccess); return true; }) .reply(200); @@ -53,7 +72,7 @@ describe("My Probot app", () => { // Receive a webhook event await probot.receive({ name: "check_suite", payload: checkSuitePayload }); - expect(mock.pendingMocks()).toStrictEqual([]); + assert.deepStrictEqual(mock.pendingMocks(), []); }); afterEach(() => { diff --git a/templates/deploy-js/index.js b/templates/deploy-js/index.js index dfdd33f7b5..9c7d556ee9 100644 --- a/templates/deploy-js/index.js +++ b/templates/deploy-js/index.js @@ -5,7 +5,7 @@ * This is the main entrypoint to your Probot app * @param {import('probot').Probot} app */ -module.exports = (app) => { +export default (app) => { // Your code here app.log.info("Yay, the app was loaded!"); app.on( diff --git a/templates/deploy-js/package.json b/templates/deploy-js/package.json index 7fa8c0920a..224f73b059 100644 --- a/templates/deploy-js/package.json +++ b/templates/deploy-js/package.json @@ -13,20 +13,17 @@ ], "scripts": { "start": "probot run ./index.js", - "test": "jest" + "test": "node --test" }, "dependencies": { "probot": "^13.0.1" }, "devDependencies": { - "jest": "^29.0.0", "nock": "^14.0.0-beta.5", "smee-client": "^2.0.0" }, "engines": { "node": ">= 18" }, - "jest": { - "testEnvironment": "node" - } + "type": "module" } diff --git a/templates/deploy-js/test/index.test.js b/templates/deploy-js/test/index.test.js index bfe5ab496b..9e7a25fa78 100644 --- a/templates/deploy-js/test/index.test.js +++ b/templates/deploy-js/test/index.test.js @@ -1,11 +1,23 @@ -const nock = require("nock"); +import nock from "nock"; // Requiring our app implementation -const myProbotApp = require(".."); -const { Probot, ProbotOctokit } = require("probot"); +import myProbotApp from "../index.js"; +import { Probot, ProbotOctokit } from "probot"; // Requiring our fixtures -const payload = require("./fixtures/pull_request.opened"); -const fs = require("fs"); -const path = require("path"); +//import payload from "./fixtures/pull_request.opened" with { type: "json" }; +import fs from "fs"; +import path from "path"; +import { fileURLToPath } from "url"; +import { describe, beforeEach, afterEach, test } from "node:test"; +import assert from "node:assert"; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); + +const payload = JSON.parse( + fs.readFileSync( + path.join(__dirname, "fixtures/pull_request.opened.json"), + "utf-8", + ), +); const deployment = { ref: "hiimbex-patch-1", @@ -66,7 +78,7 @@ describe("My Probot app", () => { // Test that a deployment is created .post("/repos/hiimbex/testing-things/deployments", (body) => { - expect(body).toMatchObject(deployment); + assert.deepStrictEqual(body, deployment); return true; }) .reply(200, { id: 123 }) @@ -75,7 +87,7 @@ describe("My Probot app", () => { .post( "/repos/hiimbex/testing-things/deployments/123/statuses", (body) => { - expect(body).toMatchObject(deploymentStatus); + assert.deepStrictEqual(body, deploymentStatus); return true; }, ) @@ -84,7 +96,7 @@ describe("My Probot app", () => { // Receive a webhook event await probot.receive({ name: "pull_request", payload }); - expect(mock.pendingMocks()).toStrictEqual([]); + assert.deepStrictEqual(mock.pendingMocks(), []); }); afterEach(() => {