Skip to content

Commit aa64b4e

Browse files
authoredJun 20, 2024··
feat: Support Probot v13 (#128)
BREAKING CHANGE: drop support for no longer maintained Node.js versions (14 and 16). Node 18+ is required now
1 parent 1eb30a0 commit aa64b4e

File tree

4 files changed

+1375
-2103
lines changed

4 files changed

+1375
-2103
lines changed
 

‎.github/workflows/test.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ jobs:
1212
strategy:
1313
matrix:
1414
node_version:
15-
- 14
16-
- 16
1715
- 18
16+
- 20
1817
steps:
1918
- uses: actions/checkout@v3
2019
- name: Use Node.js ${{ matrix.node_version }}

‎package-lock.json

+1,298-2,042
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@
1414
},
1515
"repository": "github:probot/adapter-aws-lambda-serverless",
1616
"dependencies": {
17-
"@probot/get-private-key": "^1.1.0",
1817
"@types/aws-lambda": "^8.10.85",
19-
"probot": "^12.1.1",
20-
"lowercase-keys": "^2.0.0"
18+
"lowercase-keys": "^2.0.0",
19+
"probot": "^13.3.0"
2120
},
2221
"devDependencies": {
2322
"@types/jest": "^29.0.0",
2423
"jest": "^29.0.0",
25-
"nock": "^13.2.0",
24+
"fetch-mock": "^10.0.5",
2625
"prettier": "^2.4.1"
2726
},
2827
"keywords": [

‎test/index.test.js

+73-55
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
const nock = require("nock");
21
const path = require("path");
2+
const fetchMock = require("fetch-mock");
33

44
const { createLambdaFunction, Probot, ProbotOctokit } = require("../index");
55
const app = require("./fixtures/app");
66

7-
nock.disableNetConnect();
8-
97
describe("@probot/adapter-aws-lambda-serverless", () => {
108
let probot;
119

@@ -21,21 +19,22 @@ describe("@probot/adapter-aws-lambda-serverless", () => {
2119
});
2220
});
2321

22+
afterEach(() => {
23+
fetchMock.restore();
24+
});
25+
2426
test("happy path", async () => {
2527
const fn = createLambdaFunction(app, { probot });
2628

27-
const mock = nock("https://api.github.com")
28-
.post(
29-
"/repos/probot/adapter-adapter-aws-lambda-serverless/commits/headcommitsha123/comments",
30-
(requestBody) => {
31-
expect(requestBody).toStrictEqual({
32-
body: `Hello from test${path.sep}fixtures${path.sep}app.js`,
33-
});
34-
35-
return true;
36-
}
37-
)
38-
.reply(201, {});
29+
const mock = fetchMock.postOnce(
30+
{
31+
url: "https://api.github.com/repos/probot/adapter-adapter-aws-lambda-serverless/commits/headcommitsha123/comments",
32+
},
33+
{
34+
body: {},
35+
status: 201,
36+
}
37+
);
3938

4039
const context = {};
4140
const payload = JSON.stringify(require("./fixtures/push.json"));
@@ -51,24 +50,28 @@ describe("@probot/adapter-aws-lambda-serverless", () => {
5150

5251
await fn(event, context);
5352

54-
expect(mock.activeMocks()).toStrictEqual([]);
53+
expect(
54+
mock.called((_url, options) => {
55+
return (
56+
JSON.parse(options.body).body ===
57+
`Hello from test${path.sep}fixtures${path.sep}app.js`
58+
);
59+
})
60+
).toBe(true);
5561
});
5662

5763
test("lowercase request headers", async () => {
5864
const fn = createLambdaFunction(app, { probot });
5965

60-
const mock = nock("https://api.github.com")
61-
.post(
62-
"/repos/probot/adapter-adapter-aws-lambda-serverless/commits/headcommitsha123/comments",
63-
(requestBody) => {
64-
expect(requestBody).toStrictEqual({
65-
body: `Hello from test${path.sep}fixtures${path.sep}app.js`,
66-
});
67-
68-
return true;
69-
}
70-
)
71-
.reply(201, {});
66+
const mock = fetchMock.postOnce(
67+
{
68+
url: "https://api.github.com/repos/probot/adapter-adapter-aws-lambda-serverless/commits/headcommitsha123/comments",
69+
},
70+
{
71+
body: {},
72+
status: 201,
73+
}
74+
);
7275

7376
const context = {};
7477
const payload = JSON.stringify(require("./fixtures/push.json"));
@@ -84,24 +87,28 @@ describe("@probot/adapter-aws-lambda-serverless", () => {
8487

8588
await fn(event, context);
8689

87-
expect(mock.activeMocks()).toStrictEqual([]);
90+
expect(
91+
mock.called((_url, options) => {
92+
return (
93+
JSON.parse(options.body).body ===
94+
`Hello from test${path.sep}fixtures${path.sep}app.js`
95+
);
96+
})
97+
).toBe(true);
8898
});
8999

90100
test("GitHub request headers", async () => {
91101
const fn = createLambdaFunction(app, { probot });
92102

93-
const mock = nock("https://api.github.com")
94-
.post(
95-
"/repos/probot/adapter-adapter-aws-lambda-serverless/commits/headcommitsha123/comments",
96-
(requestBody) => {
97-
expect(requestBody).toStrictEqual({
98-
body: `Hello from test${path.sep}fixtures${path.sep}app.js`,
99-
});
100-
101-
return true;
102-
}
103-
)
104-
.reply(201, {});
103+
const mock = fetchMock.postOnce(
104+
{
105+
url: "https://api.github.com/repos/probot/adapter-adapter-aws-lambda-serverless/commits/headcommitsha123/comments",
106+
},
107+
{
108+
body: {},
109+
status: 201,
110+
}
111+
);
105112

106113
const context = {};
107114
const payload = JSON.stringify(require("./fixtures/push.json"));
@@ -117,24 +124,28 @@ describe("@probot/adapter-aws-lambda-serverless", () => {
117124

118125
await fn(event, context);
119126

120-
expect(mock.activeMocks()).toStrictEqual([]);
127+
expect(
128+
mock.called((_url, options) => {
129+
return (
130+
JSON.parse(options.body).body ===
131+
`Hello from test${path.sep}fixtures${path.sep}app.js`
132+
);
133+
})
134+
).toBe(true);
121135
});
122136

123137
test("camelcase request headers (#62)", async () => {
124138
const fn = createLambdaFunction(app, { probot });
125139

126-
const mock = nock("https://api.github.com")
127-
.post(
128-
"/repos/probot/adapter-adapter-aws-lambda-serverless/commits/headcommitsha123/comments",
129-
(requestBody) => {
130-
expect(requestBody).toStrictEqual({
131-
body: `Hello from test${path.sep}fixtures${path.sep}app.js`,
132-
});
133-
134-
return true;
135-
}
136-
)
137-
.reply(201, {});
140+
const mock = fetchMock.postOnce(
141+
{
142+
url: "https://api.github.com/repos/probot/adapter-adapter-aws-lambda-serverless/commits/headcommitsha123/comments",
143+
},
144+
{
145+
body: {},
146+
status: 201,
147+
}
148+
);
138149

139150
const context = {};
140151
const payload = JSON.stringify(require("./fixtures/push.json"));
@@ -150,6 +161,13 @@ describe("@probot/adapter-aws-lambda-serverless", () => {
150161

151162
await fn(event, context);
152163

153-
expect(mock.activeMocks()).toStrictEqual([]);
164+
expect(
165+
mock.called((_url, options) => {
166+
return (
167+
JSON.parse(options.body).body ===
168+
`Hello from test${path.sep}fixtures${path.sep}app.js`
169+
);
170+
})
171+
).toBe(true);
154172
});
155173
});

0 commit comments

Comments
 (0)
Please sign in to comment.