@@ -4,30 +4,32 @@ import * as engine from './engine';
44
55describe ( 'engine' , ( ) => {
66 describe ( 'prepareOptions' , ( ) => {
7+ const logger = new NullLogger ( ) ;
8+
79 beforeEach ( ( ) => {
810 process . env = { } ;
911 } ) ;
1012
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 ( ) => {
1214 const options = {
1315 repo :
'https://[email protected] /organisation/your-repo.git' 1416 } ;
1517 process . env . GH_TOKEN = 'XXX' ;
16- const finalOptions = engine . prepareOptions ( options , new NullLogger ( ) ) ;
18+ const finalOptions = await engine . prepareOptions ( options , logger ) ;
1719
1820 expect ( finalOptions . repo ) . toBe (
1921 'https://[email protected] /organisation/your-repo.git' 2022 ) ;
2123 } ) ;
2224
2325 // 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 ( ) => {
2527 const options = {
2628 repo :
2729 'https://x-access-token:[email protected] /organisation/your-repo.git' 2830 } ;
2931 process . env . GH_TOKEN = 'XXX' ;
30- const finalOptions = engine . prepareOptions ( options , new NullLogger ( ) ) ;
32+ const finalOptions = await engine . prepareOptions ( options , logger ) ;
3133
3234 expect ( finalOptions . repo ) . toBe (
3335 'https://x-access-token:[email protected] /organisation/your-repo.git' @@ -36,41 +38,65 @@ describe('engine', () => {
3638
3739 // ----
3840
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 ( ) => {
4042 const options = {
4143 repo : 'https://github.com/organisation/your-repo.git'
4244 } ;
4345 process . env . GH_TOKEN = 'XXX' ;
44- const finalOptions = engine . prepareOptions ( options , new NullLogger ( ) ) ;
46+ const finalOptions = await engine . prepareOptions ( options , logger ) ;
4547
4648 expect ( finalOptions . repo ) . toBe (
4749 'https://x-access-token:[email protected] /organisation/your-repo.git' 4850 ) ;
4951 } ) ;
5052
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 ( ) => {
5254 const options = {
5355 repo : 'https://github.com/organisation/your-repo.git'
5456 } ;
5557 process . env . PERSONAL_TOKEN = 'XXX' ;
56- const finalOptions = engine . prepareOptions ( options , new NullLogger ( ) ) ;
58+ const finalOptions = await engine . prepareOptions ( options , logger ) ;
5759
5860 expect ( finalOptions . repo ) . toBe (
5961 'https://x-access-token:[email protected] /organisation/your-repo.git' 6062 ) ;
6163 } ) ;
6264
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 ( ) => {
6566 const options = {
6667 repo : 'https://github.com/organisation/your-repo.git'
6768 } ;
6869 process . env . GITHUB_TOKEN = 'XXX' ;
69- const finalOptions = engine . prepareOptions ( options , new NullLogger ( ) ) ;
70+ const finalOptions = await engine . prepareOptions ( options , logger ) ;
7071
7172 expect ( finalOptions . repo ) . toBe (
7273 'https://x-access-token:[email protected] /organisation/your-repo.git' 7374 ) ;
7475 } ) ;
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+ })*/
75101 } ) ;
76102} ) ;
0 commit comments