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

feat: Move to ESM #841

Merged
merged 6 commits into from
Mar 12, 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
2 changes: 1 addition & 1 deletion templates/basic-js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!");

Expand Down
7 changes: 2 additions & 5 deletions templates/basic-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
26 changes: 18 additions & 8 deletions templates/basic-js/test/index.test.js
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -44,15 +54,15 @@ 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);

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

expect(mock.pendingMocks()).toStrictEqual([]);
assert.deepStrictEqual(mock.pendingMocks(), []);
});

afterEach(() => {
Expand Down
9 changes: 0 additions & 9 deletions templates/basic-ts/jest.config.js

This file was deleted.

9 changes: 4 additions & 5 deletions templates/basic-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
2 changes: 1 addition & 1 deletion templates/basic-ts/src/index.ts
Original file line number Diff line number Diff line change
@@ -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!",
Expand Down
17 changes: 13 additions & 4 deletions templates/basic-ts/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
77 changes: 14 additions & 63 deletions templates/basic-ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 10 additions & 0 deletions templates/basic-ts/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
include: ["test/**/*.test.ts"],
coverage: {
provider: "v8",
},
},
});
2 changes: 1 addition & 1 deletion templates/checks-js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 2 additions & 5 deletions templates/checks-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
39 changes: 29 additions & 10 deletions templates/checks-js/test/index.test.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -45,15 +64,15 @@ 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);

// Receive a webhook event
await probot.receive({ name: "check_suite", payload: checkSuitePayload });

expect(mock.pendingMocks()).toStrictEqual([]);
assert.deepStrictEqual(mock.pendingMocks(), []);
});

afterEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion templates/deploy-js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 2 additions & 5 deletions templates/deploy-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Loading