Skip to content

Commit 455fd80

Browse files
feat: Port examples to ESM (#841)
Co-authored-by: wolfy1339 <[email protected]>
1 parent 06c5b47 commit 455fd80

File tree

15 files changed

+119
-127
lines changed

15 files changed

+119
-127
lines changed

templates/basic-js/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* This is the main entrypoint to your Probot app
33
* @param {import('probot').Probot} app
44
*/
5-
module.exports = (app) => {
5+
export default (app) => {
66
// Your code here
77
app.log.info("Yay, the app was loaded!");
88

templates/basic-js/package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,17 @@
1313
],
1414
"scripts": {
1515
"start": "probot run ./index.js",
16-
"test": "jest"
16+
"test": "node --test"
1717
},
1818
"dependencies": {
1919
"probot": "^13.0.1"
2020
},
2121
"devDependencies": {
22-
"jest": "^29.0.0",
2322
"nock": "^14.0.0-beta.5",
2423
"smee-client": "^2.0.0"
2524
},
2625
"engines": {
2726
"node": ">= 18"
2827
},
29-
"jest": {
30-
"testEnvironment": "node"
31-
}
28+
"type": "module"
3229
}

templates/basic-js/test/index.test.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
1-
const nock = require("nock");
1+
import nock from "nock";
22
// Requiring our app implementation
3-
const myProbotApp = require("..");
4-
const { Probot, ProbotOctokit } = require("probot");
3+
import myProbotApp from "../index.js";
4+
import { Probot, ProbotOctokit } from "probot";
55
// Requiring our fixtures
6-
const payload = require("./fixtures/issues.opened");
6+
//import payload from "./fixtures/issues.opened.json" with { type: "json" };
77
const issueCreatedBody = { body: "Thanks for opening this issue!" };
8-
const fs = require("fs");
9-
const path = require("path");
8+
import fs from "fs";
9+
import path from "path";
10+
import { fileURLToPath } from "url";
11+
12+
import { describe, beforeEach, afterEach, test } from "node:test";
13+
import assert from "node:assert";
14+
15+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
1016

1117
const privateKey = fs.readFileSync(
1218
path.join(__dirname, "fixtures/mock-cert.pem"),
1319
"utf-8",
1420
);
1521

22+
const payload = JSON.parse(
23+
fs.readFileSync(path.join(__dirname, "fixtures/issues.opened.json"), "utf-8"),
24+
);
25+
1626
describe("My Probot app", () => {
1727
let probot;
1828

@@ -44,15 +54,15 @@ describe("My Probot app", () => {
4454

4555
// Test that a comment is posted
4656
.post("/repos/hiimbex/testing-things/issues/1/comments", (body) => {
47-
expect(body).toMatchObject(issueCreatedBody);
57+
assert.deepEqual(body, issueCreatedBody);
4858
return true;
4959
})
5060
.reply(200);
5161

5262
// Receive a webhook event
5363
await probot.receive({ name: "issues", payload });
5464

55-
expect(mock.pendingMocks()).toStrictEqual([]);
65+
assert.deepStrictEqual(mock.pendingMocks(), []);
5666
});
5767

5868
afterEach(() => {

templates/basic-ts/jest.config.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

templates/basic-ts/package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,20 @@
1414
"scripts": {
1515
"build": "tsc",
1616
"start": "probot run ./lib/index.js",
17-
"test": "jest"
17+
"test": "vitest"
1818
},
1919
"dependencies": {
2020
"probot": "^13.0.1"
2121
},
2222
"devDependencies": {
23-
"@types/jest": "^29.0.0",
2423
"@types/node": "^20.0.0",
25-
"jest": "^29.0.0",
2624
"nock": "^14.0.0-beta.5",
2725
"smee-client": "^2.0.0",
28-
"ts-jest": "^29.0.0",
26+
"vitest": "^1.3.1",
2927
"typescript": "^5.3.3"
3028
},
3129
"engines": {
3230
"node": ">= 18"
33-
}
31+
},
32+
"type": "module"
3433
}

templates/basic-ts/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Probot } from "probot";
22

3-
export = (app: Probot) => {
3+
export default (app: Probot) => {
44
app.on("issues.opened", async (context) => {
55
const issueComment = context.issue({
66
body: "Thanks for opening this issue!",

templates/basic-ts/test/index.test.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,28 @@
33

44
import nock from "nock";
55
// Requiring our app implementation
6-
import myProbotApp from "../src";
6+
import myProbotApp from "../src/index.js";
77
import { Probot, ProbotOctokit } from "probot";
88
// Requiring our fixtures
9-
import payload from "./fixtures/issues.opened.json";
9+
//import payload from "./fixtures/issues.opened.json" with { "type": "json"};
10+
import fs from "fs";
11+
import path from "path";
12+
import { fileURLToPath } from "url";
13+
import { describe, beforeEach, afterEach, test, expect } from "vitest";
14+
1015
const issueCreatedBody = { body: "Thanks for opening this issue!" };
11-
const fs = require("fs");
12-
const path = require("path");
16+
17+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
1318

1419
const privateKey = fs.readFileSync(
1520
path.join(__dirname, "fixtures/mock-cert.pem"),
1621
"utf-8",
1722
);
1823

24+
const payload = JSON.parse(
25+
fs.readFileSync(path.join(__dirname, "fixtures/issues.opened.json"), "utf-8"),
26+
);
27+
1928
describe("My Probot app", () => {
2029
let probot: any;
2130

templates/basic-ts/tsconfig.json

Lines changed: 14 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,24 @@
11
{
22
"compilerOptions": {
3-
/* Basic Options */
4-
"incremental": true /* Enable incremental compilation */,
5-
"target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
6-
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
7-
"lib": [
8-
"es2015",
9-
"es2017"
10-
] /* Specify library files to be included in the compilation. */,
11-
"allowJs": true /* Allow javascript files to be compiled. */,
12-
"checkJs": true /* Report errors in .js files. */,
13-
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
14-
"declaration": true /* Generates corresponding '.d.ts' file. */,
15-
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
16-
"sourceMap": true /* Generates corresponding '.map' file. */,
17-
// "outFile": "./", /* Concatenate and emit output to single file. */
18-
"outDir": "./lib" /* Redirect output structure to the directory. */,
19-
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
20-
// "composite": true, /* Enable project compilation */
21-
// "tsBuildInfoFile": "./" /* Specify file to store incremental compilation information */,
22-
// "removeComments": true, /* Do not emit comments to output. */
23-
// "noEmit": true, /* Do not emit outputs. */
24-
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
25-
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
26-
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
3+
"incremental": true,
4+
"target": "es2022",
5+
"module": "Node16",
6+
"declaration": true,
7+
"sourceMap": true,
8+
"outDir": "./lib",
279

2810
/* Strict Type-Checking Options */
29-
"strict": true /* Enable all strict type-checking options. */,
30-
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
31-
// "strictNullChecks": true, /* Enable strict null checks. */
32-
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
33-
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
34-
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
35-
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
36-
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
11+
"strict": true,
3712

3813
/* Additional Checks */
39-
"noUnusedLocals": true /* Report errors on unused locals. */,
40-
"noUnusedParameters": true /* Report errors on unused parameters. */,
41-
"noImplicitReturns": true /* Report error when not all code paths in function return a value. */,
42-
"noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */,
14+
"noUnusedLocals": true,
15+
"noUnusedParameters": true,
16+
"noImplicitReturns": true,
17+
"noFallthroughCasesInSwitch": true,
4318

44-
/* Module Resolution Options */
45-
"moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
46-
// "baseUrl": "./src" /* Base directory to resolve non-absolute module names. */,
47-
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
48-
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
49-
// "typeRoots": [], /* List of folders to include type definitions from. */
50-
// "types": [], /* Type declaration files to be included in compilation. */
51-
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just type checking. */
52-
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
53-
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
54-
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
55-
56-
/* Source Map Options */
57-
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
58-
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
59-
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
60-
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
61-
62-
/* Experimental Options */
63-
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
64-
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
65-
66-
/* Advanced Options */
67-
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */,
68-
"resolveJsonModule": true,
69-
"pretty": false,
70-
"skipLibCheck": true
19+
"moduleResolution": "Node16",
20+
"esModuleInterop": true,
21+
"forceConsistentCasingInFileNames": true
7122
},
7223
"include": ["src/"],
7324
"compileOnSave": false

templates/basic-ts/vitest.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { defineConfig } from "vitest/config";
2+
3+
export default defineConfig({
4+
test: {
5+
include: ["test/**/*.test.ts"],
6+
coverage: {
7+
provider: "v8",
8+
},
9+
},
10+
});

templates/checks-js/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* This is the main entrypoint to your Probot app
66
* @param {import('probot').Probot} app
77
*/
8-
module.exports = (app) => {
8+
export default (app) => {
99
app.on(["check_suite.requested", "check_run.rerequested"], check);
1010

1111
async function check(context) {

0 commit comments

Comments
 (0)