11const nock = require ( "nock" ) ;
22const { Probot, ProbotOctokit } = require ( "probot" ) ;
33const outdent = require ( "outdent" ) ;
4- const pino = require ( "pino" ) ;
5- const Stream = require ( "stream" ) ;
64
75const changesetBot = require ( "." ) ;
86
@@ -12,34 +10,19 @@ const releasePullRequestOpen = require("./test/fixtures/release_pull_request.ope
1210
1311nock . disableNetConnect ( ) ;
1412
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-
2313describe ( "changeset-bot" , ( ) => {
2414 let probot ;
25- let app
2615
2716 beforeEach ( async ( ) => {
2817 probot = new Probot ( {
2918 githubToken : "test" ,
30- appId : 123 ,
31- privateKey : 123 ,
32- log : pino ( streamLogsToOutput ) ,
3319 Octokit : ProbotOctokit . defaults ( {
3420 retry : { enabled : false } ,
3521 throttle : { enabled : false } ,
3622 } ) ,
3723 } ) ;
3824
39- app = changesetBot . default ( probot )
40-
41- // just return a test token
42- app . app = ( ) => "test.ts" ;
25+ changesetBot . default ( probot )
4326 } ) ;
4427
4528 beforeEach ( ( ) => {
@@ -60,7 +43,6 @@ describe("changeset-bot", () => {
6043 nock ( "https://api.github.com" )
6144 . post ( "/app/installations/2462428/access_tokens" )
6245 . reply ( 200 , [ ] )
63-
6446 } )
6547
6648 it ( "should add a comment when there is no comment" , async ( ) => {
@@ -79,7 +61,7 @@ describe("changeset-bot", () => {
7961 } )
8062 . reply ( 200 ) ;
8163
82- await app . receive ( {
64+ await probot . receive ( {
8365 name : "pull_request" ,
8466 payload : pullRequestOpen
8567 } ) ;
@@ -89,10 +71,10 @@ describe("changeset-bot", () => {
8971 const commentId = 123
9072
9173 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+ ] ) ;
9678
9779 // get comments for an issue
9880 nock ( "https://api.github.com" )
@@ -106,11 +88,11 @@ describe("changeset-bot", () => {
10688
10789 // update comments for an issue
10890 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 ) ;
11496
11597 await probot . receive ( {
11698 name : "pull_request" ,
@@ -162,14 +144,24 @@ describe("changeset-bot", () => {
162144 . get ( "/repos/changesets/bot/pulls/2/files" )
163145 . reply ( 200 , [ { filename : "index.js" , status : "added" } ] ) ;
164146
165- nock ( "https://api.github.com" )
166- . get ( "/repos/changesets/bot/pulls/2/commits" )
167- . reply ( 200 , [ { sha : "ABCDE" } ] ) ;
168-
169147 nock ( "https://api.github.com" )
170148 . 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 / )
173165 return true ;
174166 } )
175167 . reply ( 200 ) ;
0 commit comments