1+ import fs from 'fs' ;
2+ import nock from 'nock' ;
13import { Inputs } from '../src/context' ;
24import { Labeler , LabelStatus } from '../src/labeler' ;
35
6+ process . env . GITHUB_REPOSITORY = 'crazy-max/ghaction-github-labeler' ;
7+
8+ function configFixture ( fileName : string ) {
9+ return fs . readFileSync ( `${ __dirname } /../${ fileName } ` ) ;
10+ }
11+
12+ function labelsFixture ( ) {
13+ const content = fs . readFileSync ( `${ __dirname } /../.res/labels.json` ) . toString ( ) ;
14+ return JSON . parse ( content ) ;
15+ }
16+
417const cases = [
518 [
619 'labels.update.yml' ,
720 {
8- githubToken : process . env . GITHUB_TOKEN || '' ,
21+ githubToken : process . env . GITHUB_TOKEN || 'test ' ,
922 yamlFile : '.res/labels.update.yml' ,
1023 skipDelete : true ,
1124 dryRun : true ,
@@ -24,7 +37,7 @@ const cases = [
2437 [
2538 'labels.exclude1.yml' ,
2639 {
27- githubToken : process . env . GITHUB_TOKEN || '' ,
40+ githubToken : process . env . GITHUB_TOKEN || 'test ' ,
2841 yamlFile : '.res/labels.exclude1.yml' ,
2942 skipDelete : true ,
3043 dryRun : true ,
@@ -43,7 +56,7 @@ const cases = [
4356 [
4457 'labels.exclude2.yml' ,
4558 {
46- githubToken : process . env . GITHUB_TOKEN || '' ,
59+ githubToken : process . env . GITHUB_TOKEN || 'test ' ,
4760 yamlFile : '.res/labels.exclude2.yml' ,
4861 skipDelete : true ,
4962 dryRun : true ,
@@ -62,8 +75,25 @@ const cases = [
6275] ;
6376
6477describe ( 'run' , ( ) => {
78+ beforeAll ( ( ) => {
79+ nock . disableNetConnect ( ) ;
80+ // nock.recorder.rec();
81+ } ) ;
82+ afterAll ( ( ) => {
83+ // nock.restore()
84+ nock . cleanAll ( ) ;
85+ nock . enableNetConnect ( ) ;
86+ } ) ;
6587 test . each ( cases ) ( 'given %p' , async ( name , inputs , expected ) => {
66- const labeler = new Labeler ( inputs as Inputs ) ;
88+ const input = inputs as Inputs ;
89+
90+ nock ( 'https://api.github.com' ) . get ( '/repos/crazy-max/ghaction-github-labeler/labels' ) . reply ( 200 , labelsFixture ( ) ) ;
91+
92+ nock ( 'https://api.github.com' )
93+ . get ( `/repos/crazy-max/ghaction-github-labeler/contents/${ encodeURIComponent ( input . yamlFile as string ) } ` )
94+ . reply ( 200 , configFixture ( input . yamlFile as string ) ) ;
95+
96+ const labeler = new Labeler ( input ) ;
6797 await labeler . printRepoLabels ( ) ;
6898 console . log (
6999 ( await labeler . labels ) . map ( label => {
0 commit comments