1
1
const nock = require ( "nock" ) ;
2
2
const { Probot, ProbotOctokit } = require ( "probot" ) ;
3
3
const outdent = require ( "outdent" ) ;
4
- const pino = require ( "pino" ) ;
5
- const Stream = require ( "stream" ) ;
6
4
7
5
const changesetBot = require ( "." ) ;
8
6
@@ -12,34 +10,19 @@ const releasePullRequestOpen = require("./test/fixtures/release_pull_request.ope
12
10
13
11
nock . disableNetConnect ( ) ;
14
12
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
-
23
13
describe ( "changeset-bot" , ( ) => {
24
14
let probot ;
25
- let app
26
15
27
16
beforeEach ( async ( ) => {
28
17
probot = new Probot ( {
29
18
githubToken : "test" ,
30
- appId : 123 ,
31
- privateKey : 123 ,
32
- log : pino ( streamLogsToOutput ) ,
33
19
Octokit : ProbotOctokit . defaults ( {
34
20
retry : { enabled : false } ,
35
21
throttle : { enabled : false } ,
36
22
} ) ,
37
23
} ) ;
38
24
39
- app = changesetBot . default ( probot )
40
-
41
- // just return a test token
42
- app . app = ( ) => "test.ts" ;
25
+ changesetBot . default ( probot )
43
26
} ) ;
44
27
45
28
beforeEach ( ( ) => {
@@ -60,7 +43,6 @@ describe("changeset-bot", () => {
60
43
nock ( "https://api.github.com" )
61
44
. post ( "/app/installations/2462428/access_tokens" )
62
45
. reply ( 200 , [ ] )
63
-
64
46
} )
65
47
66
48
it ( "should add a comment when there is no comment" , async ( ) => {
@@ -79,7 +61,7 @@ describe("changeset-bot", () => {
79
61
} )
80
62
. reply ( 200 ) ;
81
63
82
- await app . receive ( {
64
+ await probot . receive ( {
83
65
name : "pull_request" ,
84
66
payload : pullRequestOpen
85
67
} ) ;
@@ -89,10 +71,10 @@ describe("changeset-bot", () => {
89
71
const commentId = 123
90
72
91
73
nock ( "https://api.github.com" )
92
- . get ( "/repos/changesets/bot/pulls/2/files" )
93
- . reply ( 200 , [
94
- { filename : ".changeset/something/changes.md" , status : "added" }
95
- ] ) ;
74
+ . get ( "/repos/changesets/bot/pulls/2/files" )
75
+ . reply ( 200 , [
76
+ { filename : ".changeset/something/changes.md" , status : "added" }
77
+ ] ) ;
96
78
97
79
// get comments for an issue
98
80
nock ( "https://api.github.com" )
@@ -106,11 +88,11 @@ describe("changeset-bot", () => {
106
88
107
89
// update comments for an issue
108
90
nock ( "https://api.github.com" )
109
- . patch ( `/repos/changesets/bot/issues/comments/${ commentId } ` , body => {
110
- expect ( body . body ) . toContain ( "Changeset detected" )
111
- return true ;
112
- } )
113
- . reply ( 200 ) ;
91
+ . patch ( `/repos/changesets/bot/issues/comments/${ commentId } ` , body => {
92
+ expect ( body . body ) . toContain ( "Changeset detected" )
93
+ return true ;
94
+ } )
95
+ . reply ( 200 ) ;
114
96
115
97
await probot . receive ( {
116
98
name : "pull_request" ,
@@ -162,14 +144,24 @@ describe("changeset-bot", () => {
162
144
. get ( "/repos/changesets/bot/pulls/2/files" )
163
145
. reply ( 200 , [ { filename : "index.js" , status : "added" } ] ) ;
164
146
165
- nock ( "https://api.github.com" )
166
- . get ( "/repos/changesets/bot/pulls/2/commits" )
167
- . reply ( 200 , [ { sha : "ABCDE" } ] ) ;
168
-
169
147
nock ( "https://api.github.com" )
170
148
. post ( "/repos/changesets/bot/issues/2/comments" , ( { body } ) => {
171
- // todo better assertion
172
- expect ( body ) . toContain ( "Click here to learn what changesets are, and how to add one" ) ;
149
+ expect ( body ) . toContain ( outdent `
150
+ ### ⚠️ No Changeset found
151
+
152
+ Latest commit: c4d7edfd758bd44f7d4264fb55f6033f56d79540
153
+
154
+ Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. **If these changes should result in a version bump, you need to add a changeset.**
155
+
156
+ <details><summary>This PR includes no changesets</summary>
157
+
158
+ When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
159
+
160
+ </details>
161
+
162
+ [Click here to learn what changesets are, and how to add one](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md).
163
+ ` ) ;
164
+ expect ( body ) . toMatch ( / \[ C l i c k h e r e i f y o u ' r e a m a i n t a i n e r w h o w a n t s t o a d d a c h a n g e s e t t o t h i s P R ] \( h t t p s : \/ \/ g i t h u b \. c o m \/ c h a n g e s e t s \/ b o t \/ n e w \/ t e s t \? f i l e n a m e = \. c h a n g e s e t / )
173
165
return true ;
174
166
} )
175
167
. reply ( 200 ) ;
0 commit comments