@@ -4,30 +4,32 @@ import * as engine from './engine';
4
4
5
5
describe ( 'engine' , ( ) => {
6
6
describe ( 'prepareOptions' , ( ) => {
7
+ const logger = new NullLogger ( ) ;
8
+
7
9
beforeEach ( ( ) => {
8
10
process . env = { } ;
9
11
} ) ;
10
12
11
- it ( 'should replace the string GH_TOKEN in the repo url (for backwards compatibility)' , ( ) => {
13
+ it ( 'should replace the string GH_TOKEN in the repo url (for backwards compatibility)' , async ( ) => {
12
14
const options = {
13
15
repo :
'https://[email protected] /organisation/your-repo.git'
14
16
} ;
15
17
process . env . GH_TOKEN = 'XXX' ;
16
- const finalOptions = engine . prepareOptions ( options , new NullLogger ( ) ) ;
18
+ const finalOptions = await engine . prepareOptions ( options , logger ) ;
17
19
18
20
expect ( finalOptions . repo ) . toBe (
19
21
'https://[email protected] /organisation/your-repo.git'
20
22
) ;
21
23
} ) ;
22
24
23
25
// see https://github.com/EdricChan03/rss-reader/commit/837dc10c18bfa453c586bb564a662e7dad1e68ab#r36665276 as an example
24
- it ( 'should be possible to use GH_TOKEN in repo url as a workaround for other tokens (for backwards compatibility)' , ( ) => {
26
+ it ( 'should be possible to use GH_TOKEN in repo url as a workaround for other tokens (for backwards compatibility)' , async ( ) => {
25
27
const options = {
26
28
repo :
27
29
'https://x-access-token:[email protected] /organisation/your-repo.git'
28
30
} ;
29
31
process . env . GH_TOKEN = 'XXX' ;
30
- const finalOptions = engine . prepareOptions ( options , new NullLogger ( ) ) ;
32
+ const finalOptions = await engine . prepareOptions ( options , logger ) ;
31
33
32
34
expect ( finalOptions . repo ) . toBe (
33
35
'https://x-access-token:[email protected] /organisation/your-repo.git'
@@ -36,41 +38,65 @@ describe('engine', () => {
36
38
37
39
// ----
38
40
39
- it ( 'should also add a personal access token (GH_TOKEN) to the repo url' , ( ) => {
41
+ it ( 'should also add a personal access token (GH_TOKEN) to the repo url' , async ( ) => {
40
42
const options = {
41
43
repo : 'https://github.com/organisation/your-repo.git'
42
44
} ;
43
45
process . env . GH_TOKEN = 'XXX' ;
44
- const finalOptions = engine . prepareOptions ( options , new NullLogger ( ) ) ;
46
+ const finalOptions = await engine . prepareOptions ( options , logger ) ;
45
47
46
48
expect ( finalOptions . repo ) . toBe (
47
49
'https://x-access-token:[email protected] /organisation/your-repo.git'
48
50
) ;
49
51
} ) ;
50
52
51
- it ( 'should also add a personal access token (PERSONAL_TOKEN) to the repo url' , ( ) => {
53
+ it ( 'should also add a personal access token (PERSONAL_TOKEN) to the repo url' , async ( ) => {
52
54
const options = {
53
55
repo : 'https://github.com/organisation/your-repo.git'
54
56
} ;
55
57
process . env . PERSONAL_TOKEN = 'XXX' ;
56
- const finalOptions = engine . prepareOptions ( options , new NullLogger ( ) ) ;
58
+ const finalOptions = await engine . prepareOptions ( options , logger ) ;
57
59
58
60
expect ( finalOptions . repo ) . toBe (
59
61
'https://x-access-token:[email protected] /organisation/your-repo.git'
60
62
) ;
61
63
} ) ;
62
64
63
- it ( 'should also add a installation access token (GITHUB_TOKEN) to the repo url' , ( ) => {
64
- debugger ;
65
+ it ( 'should also add a installation access token (GITHUB_TOKEN) to the repo url' , async ( ) => {
65
66
const options = {
66
67
repo : 'https://github.com/organisation/your-repo.git'
67
68
} ;
68
69
process . env . GITHUB_TOKEN = 'XXX' ;
69
- const finalOptions = engine . prepareOptions ( options , new NullLogger ( ) ) ;
70
+ const finalOptions = await engine . prepareOptions ( options , logger ) ;
70
71
71
72
expect ( finalOptions . repo ) . toBe (
72
73
'https://x-access-token:[email protected] /organisation/your-repo.git'
73
74
) ;
74
75
} ) ;
76
+
77
+ // NEW in 0.6.2: always discover remote URL (if not set)
78
+ // this allows us to inject tokens from environment even if --repo is not set manually
79
+ // it uses gh-pages lib directly for this
80
+ it ( 'should discover the remote url, if no --repo is set' , async ( ) => {
81
+ const options = { } ;
82
+ const finalOptions = await engine . prepareOptions ( options , logger ) ;
83
+
84
+ expect ( finalOptions . repo ) . toMatch ( / a n g u l a r - s c h u l e \/ a n g u l a r - c l i - g h p a g e s / ) ;
85
+ } ) ;
86
+
87
+ /*
88
+ // i was not able to somehow catch an error... :-(
89
+ it('should should throw an exception, if remote url could not be discovered', async () => {
90
+
91
+ expect.assertions(1);
92
+
93
+ const options = { git: 'xxx' };
94
+
95
+ try {
96
+ await engine.prepareOptions(options, logger);
97
+ } catch (e) {
98
+ expect(e).toBeTruthy();
99
+ }
100
+ })*/
75
101
} ) ;
76
102
} ) ;
0 commit comments