Skip to content

Commit 74f796b

Browse files
committed
First test working
1 parent 492290b commit 74f796b

File tree

4 files changed

+1571
-2725
lines changed

4 files changed

+1571
-2725
lines changed

index.test.js

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const nock = require("nock");
2-
const { Probot } = require("probot");
2+
const { Probot, ProbotOctokit } = require("probot");
33
const outdent = require("outdent");
4+
const pino = require("pino");
5+
const Stream = require("stream");
46

57
const changesetBot = require(".");
68

@@ -10,27 +12,65 @@ const releasePullRequestOpen = require("./test/fixtures/release_pull_request.ope
1012

1113
nock.disableNetConnect();
1214

15+
const output = []
16+
17+
const streamLogsToOutput = new Stream.Writable({ objectMode: true });
18+
streamLogsToOutput._write = (object, encoding, done) => {
19+
output.push(JSON.parse(object));
20+
done();
21+
};
22+
1323
/*
1424
Oh god none of these tests work - we should really do something about having this tested
1525
*/
16-
describe.skip("changeset-bot", () => {
26+
describe("changeset-bot", () => {
1727
let probot;
28+
let app
29+
30+
beforeEach(async() => {
31+
probot = new Probot({
32+
githubToken: "test",
33+
appId: 123,
34+
privateKey: 123,
35+
log: pino(streamLogsToOutput),
36+
Octokit: ProbotOctokit.defaults({
37+
retry: { enabled: false },
38+
throttle: { enabled: false },
39+
}),
40+
});
1841

19-
beforeEach(() => {
20-
probot = new Probot({});
21-
const app = probot.load(changesetBot);
42+
43+
app = changesetBot.default(probot)
2244

2345
// just return a test token
2446
app.app = () => "test.ts";
2547
});
2648

2749
it("should add a comment when there is no comment", async () => {
50+
nock("https://raw.githubusercontent.com")
51+
.get("/changesets/bot/test/package.json")
52+
.reply(200, {})
53+
54+
nock("https://raw.githubusercontent.com")
55+
.get("/changesets/bot/test/.changeset/config.json")
56+
.reply(200, {})
57+
58+
nock("https://api.github.com")
59+
.get("/repos/changesets/bot/git/trees/test?recursive=1")
60+
.reply(200, {
61+
tree: [],
62+
})
63+
64+
nock("https://api.github.com")
65+
.post("/app/installations/2462428/access_tokens")
66+
.reply(200, [])
67+
2868
nock("https://api.github.com")
2969
.get("/repos/pyu/testing-things/issues/1/comments")
3070
.reply(200, []);
3171

3272
nock("https://api.github.com")
33-
.get("/repos/pyu/testing-things/pulls/1/files")
73+
.get("/repos/changesets/bot/pulls/2/files")
3474
.reply(200, [
3575
{ filename: ".changeset/something/changes.md", status: "added" }
3676
]);
@@ -40,13 +80,13 @@ describe.skip("changeset-bot", () => {
4080
.reply(200, [{ sha: "ABCDE" }]);
4181

4282
nock("https://api.github.com")
43-
.post("/repos/pyu/testing-things/issues/1/comments", body => {
44-
expect(body.comment_id).toBeNull();
83+
.post("/repos/changesets/bot/issues/2/comments", body => {
84+
expect(body.comment_id).toBeUndefined()
4585
return true;
4686
})
4787
.reply(200);
4888

49-
await probot.receive({
89+
await app.receive({
5090
name: "pull_request",
5191
payload: pullRequestOpen
5292
});

index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,6 @@ export default (app: Probot) => {
234234
}
235235
}
236236
);
237+
238+
return app
237239
};

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
"private": true,
66
"repository": "https://github.com/changesets/bot",
77
"homepage": "https://github.com/apps/changeset-bot",
8+
"scripts": {
9+
"test": "jest"
10+
},
811
"dependencies": {
912
"@changesets/assemble-release-plan": "^5.1.3",
1013
"@changesets/config": "^2.0.0",
@@ -32,11 +35,14 @@
3235
"typescript": "^4.7.4"
3336
},
3437
"devDependencies": {
35-
"jest": "^24.1.0",
38+
"@types/jest": "^29.5.2",
39+
"jest": "^29.1.0",
3640
"nock": "^10.0.0",
37-
"outdent": "^0.7.0"
41+
"outdent": "^0.7.0",
42+
"ts-jest": "^29.1.0"
3843
},
3944
"jest": {
45+
"preset": "ts-jest",
4046
"testEnvironment": "node"
4147
}
4248
}

0 commit comments

Comments
 (0)