11'use strict' ;
22
33const assert = require ( 'assert' ) ;
4+ const path = require ( 'path' ) ;
45
56const {
67 isCollaborator,
@@ -20,11 +21,6 @@ const assertThrowsAsync = require('../fixtures/assert_throws_async');
2021
2122describe ( 'collaborators' , function ( ) {
2223 const collaborator = collaborators . get ( 'bar' ) ;
23- let cli = null ;
24-
25- beforeEach ( ( ) => {
26- cli = new TestCLI ( ) ;
27- } ) ;
2824
2925 describe ( 'Collaborator' , ( ) => {
3026 describe ( 'isActor' , ( ) => {
@@ -83,64 +79,101 @@ describe('collaborators', function() {
8379 } ) ;
8480
8581 describe ( 'getCollaborators' , ( ) => {
82+ let cli = null ;
83+
84+ beforeEach ( ( ) => {
85+ cli = new TestCLI ( ) ;
86+ } ) ;
87+
88+ function mockRequest ( content , argv ) {
89+ const { owner, repo } = argv ;
90+ const expectedUrl =
91+ `https://raw.githubusercontent.com/${ owner } /${ repo } /master/README.md` ;
92+ return {
93+ async text ( url ) {
94+ assert . strictEqual ( url , expectedUrl ) ;
95+ return content ;
96+ }
97+ } ;
98+ }
99+
100+ it ( 'should use specified readme' , async function ( ) {
101+ const readmePath = path . resolve (
102+ __dirname , '..' , 'fixtures' , 'README' , 'README.md' ) ;
103+ const argv = { owner : 'nodejs' , repo : 'node' , readme : readmePath } ;
104+ const request = { async text ( ) { assert . fail ( 'should not call' ) ; } } ;
105+ const parsed = await getCollaborators ( cli , request , argv ) ;
106+ assert . deepStrictEqual ( parsed , collaborators ) ;
107+ } ) ;
108+
86109 it ( 'should return all collaborators' , async function ( ) {
87- const parsed = getCollaborators ( readme , cli , 'nodejs' , 'node' ) ;
110+ const argv = { owner : 'nodejs' , repo : 'node' } ;
111+ const request = mockRequest ( readme , argv ) ;
112+ const parsed = await getCollaborators ( cli , request , argv ) ;
88113 assert . deepStrictEqual ( parsed , collaborators ) ;
89114 } ) ;
90115
91- it (
92- 'should throw error if there is no TSC section in the README' ,
116+ it ( 'should throw error if there is no TSC section in the README' ,
93117 async ( ) => {
118+ const argv = { owner : 'nodejs' , repo : 'node' } ;
119+ const request = mockRequest ( readmeNoTsc , argv ) ;
94120 await assertThrowsAsync (
95- async ( ) => getCollaborators ( readmeNoTsc , cli , 'nodejs' , 'node' ) ,
121+ async ( ) => getCollaborators ( cli , request , argv ) ,
96122 Error ) ;
97123 } ) ;
98124
99125 it (
100126 'should throw error if there is no TSC Emeriti section in the README' ,
101127 async ( ) => {
128+ const argv = { owner : 'nodejs' , repo : 'node' } ;
129+ const request = mockRequest ( readmeNoTscE , argv ) ;
102130 await assertThrowsAsync (
103- async ( ) => getCollaborators ( readmeNoTscE , cli , 'nodejs' , 'node' ) ,
131+ async ( ) => getCollaborators ( cli , request , argv ) ,
104132 / E r r o r : C o u l d n ' t f i n d # # # T S C E m e r i t i i n t h e R E A D M E / ) ;
105133 } ) ;
106134
107135 it ( 'should throw error if there is no Collaborators section in the README' ,
108136 async ( ) => {
137+ const argv = { owner : 'nodejs' , repo : 'node' } ;
138+ const request = mockRequest ( readmeNoCollaborators , argv ) ;
109139 await assertThrowsAsync (
110- async ( ) => getCollaborators (
111- readmeNoCollaborators , cli , 'nodejs' , 'node' ) ,
140+ async ( ) => getCollaborators ( cli , request , argv ) ,
112141 / E r r o r : C o u l d n ' t f i n d # # # C o l l a b o r a t o r s i n t h e R E A D M E / ) ;
113142 } ) ;
114143
115144 it (
116145 'should throw error if there is no Collaborator' +
117146 'Emeriti section in the README' ,
118147 async ( ) => {
148+ const argv = { owner : 'nodejs' , repo : 'node' } ;
149+ const request = mockRequest ( readmeNoCollaboratorE , argv ) ;
119150 await assertThrowsAsync (
120- async ( ) => getCollaborators (
121- readmeNoCollaboratorE , cli , 'nodejs' , 'node' ) ,
151+ async ( ) => getCollaborators ( cli , request , argv ) ,
122152 / E r r o r : C o u l d n ' t f i n d # # # C o l l a b o r a t o r E m e r i t i i n t h e R E A D M E / ) ;
123153 } ) ;
124154
125155 it (
126156 'should WARN if the TSC and Collaborators' +
127157 'section are not ordered in the README' ,
128158 async ( ) => {
159+ const argv = { owner : 'nodejs' , repo : 'node' } ;
160+ const request = mockRequest ( readmeUnordered , argv ) ;
129161 await assertThrowsAsync (
130- async ( ) => getCollaborators (
131- readmeUnordered , cli , 'nodejs' , 'node' ) ,
162+ async ( ) => getCollaborators ( cli , request , argv ) ,
132163 / E r r o r / ) ;
133164 cli . assertCalledWith ( {
134165 warn : [ [
135166 'Contacts in the README is out of order, analysis could go wrong.' ,
136167 { newline : true }
137168 ] ]
138- } ) ;
169+ } , { ignore : [ 'updateSpinner' , 'stopSpinner' ] } ) ;
139170 } ) ;
140171
141172 it ( 'should throw error if there are no collaborators' , async ( ) => {
173+ const argv = { owner : 'nodejs' , repo : 'node' } ;
174+ const request = mockRequest ( readmeUnordered , argv ) ;
142175 await assertThrowsAsync (
143- async ( ) => getCollaborators ( readmeUnordered , cli , 'nodejs' , 'node' ) ,
176+ async ( ) => getCollaborators ( cli , request , argv ) ,
144177 / E r r o r : C o u l d n o t f i n d a n y c o l l a b o r a t o r s / ) ;
145178 } ) ;
146179 } ) ;
0 commit comments