1
1
const nock = require ( "nock" ) ;
2
- const { Probot } = require ( "probot" ) ;
2
+ const { Probot, ProbotOctokit } = require ( "probot" ) ;
3
3
const outdent = require ( "outdent" ) ;
4
+ const pino = require ( "pino" ) ;
5
+ const Stream = require ( "stream" ) ;
4
6
5
7
const changesetBot = require ( "." ) ;
6
8
@@ -10,27 +12,65 @@ const releasePullRequestOpen = require("./test/fixtures/release_pull_request.ope
10
12
11
13
nock . disableNetConnect ( ) ;
12
14
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
+
13
23
/*
14
24
Oh god none of these tests work - we should really do something about having this tested
15
25
*/
16
- describe . skip ( "changeset-bot" , ( ) => {
26
+ describe ( "changeset-bot" , ( ) => {
17
27
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
+ } ) ;
18
41
19
- beforeEach ( ( ) => {
20
- probot = new Probot ( { } ) ;
21
- const app = probot . load ( changesetBot ) ;
42
+
43
+ app = changesetBot . default ( probot )
22
44
23
45
// just return a test token
24
46
app . app = ( ) => "test.ts" ;
25
47
} ) ;
26
48
27
49
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
+
28
68
nock ( "https://api.github.com" )
29
69
. get ( "/repos/pyu/testing-things/issues/1/comments" )
30
70
. reply ( 200 , [ ] ) ;
31
71
32
72
nock ( "https://api.github.com" )
33
- . get ( "/repos/pyu/testing-things /pulls/1 /files" )
73
+ . get ( "/repos/changesets/bot /pulls/2 /files" )
34
74
. reply ( 200 , [
35
75
{ filename : ".changeset/something/changes.md" , status : "added" }
36
76
] ) ;
@@ -40,13 +80,13 @@ describe.skip("changeset-bot", () => {
40
80
. reply ( 200 , [ { sha : "ABCDE" } ] ) ;
41
81
42
82
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 ( )
45
85
return true ;
46
86
} )
47
87
. reply ( 200 ) ;
48
88
49
- await probot . receive ( {
89
+ await app . receive ( {
50
90
name : "pull_request" ,
51
91
payload : pullRequestOpen
52
92
} ) ;
0 commit comments