File tree Expand file tree Collapse file tree 3 files changed +17
-19
lines changed
Expand file tree Collapse file tree 3 files changed +17
-19
lines changed Original file line number Diff line number Diff line change @@ -9,9 +9,8 @@ class GithubHelper {
99 * @param {Object } repo - personal access token
1010 */
1111 constructor ( pkg , config ) {
12- if ( ! isValidRepositoryUrl ( pkg ) || ! hasGithubToken ( config . token ) ) {
13- throw new Error ( ) ;
14- }
12+ isValidRepositoryUrl ( pkg ) ;
13+ hasGithubToken ( config . token ) ;
1514
1615 this . repo = this . _getRepo ( pkg , config ) ;
1716 this . config = config ;
Original file line number Diff line number Diff line change @@ -17,8 +17,7 @@ function getRepositoryUrl(pkg) {
1717 }
1818
1919 if ( ! GIT_REPO_REGEXP . test ( repositoryUrl ) ) {
20- console . error ( 'Invalid repository url on package.json' ) ;
21- repositoryUrl = '' ;
20+ throw new Error ( 'Invalid repository url on package.json' ) ;
2221 }
2322
2423 return repositoryUrl ;
@@ -41,7 +40,7 @@ function isValidRepositoryUrl(pkg) {
4140function hasGithubToken ( token ) {
4241 const isValidToken = typeof token === 'string' && token . length > 0 ;
4342 if ( ! isValidToken ) {
44- console . error ( 'Missing TUI_GITHUB_TOKEN environment variable ' ) ;
43+ throw new Error ( 'Missing Github access token ' ) ;
4544 }
4645
4746 return isValidToken ;
Original file line number Diff line number Diff line change @@ -21,32 +21,32 @@ describe('utils.isValidRepositoryUrl()', () => {
2121 } )
2222 ) . toBe ( true ) ;
2323
24- expect (
25- isValidRepositoryUrl ( {
24+ expect ( ( ) => {
25+ return isValidRepositoryUrl ( {
2626 repository : 'https://github.com/user-name/repository-name'
27- } )
28- ) . toBe ( false ) ;
27+ } ) ;
28+ } ) . toThrow ( new Error ( 'Invalid repository url on package.json' ) ) ;
2929
30- expect (
31- isValidRepositoryUrl ( {
30+ expect ( ( ) => {
31+ return isValidRepositoryUrl ( {
3232 repository : ''
33- } )
34- ) . toBe ( false ) ;
33+ } ) ;
34+ } ) . toThrow ( new Error ( 'Invalid repository url on package.json' ) ) ;
3535
36- expect (
37- isValidRepositoryUrl ( {
36+ expect ( ( ) => {
37+ return isValidRepositoryUrl ( {
3838 repository : {
3939 url : 'https://github.com/user-name/repository-name'
4040 }
41- } )
42- ) . toBe ( false ) ;
41+ } ) ;
42+ } ) . toThrow ( new Error ( 'Invalid repository url on package.json' ) ) ;
4343 } ) ;
4444} ) ;
4545
4646describe ( 'utils.hasGithubToken()' , ( ) => {
4747 it ( 'should determine a token is valid or not.' , ( ) => {
4848 expect ( hasGithubToken ( 'test_token' ) ) . toBe ( true ) ;
49- expect ( hasGithubToken ( 123123 ) ) . toBe ( false ) ;
49+ expect ( ( ) => hasGithubToken ( 123123 ) ) . toThrow ( new Error ( 'Missing Github access token' ) ) ;
5050 } ) ;
5151} ) ;
5252
You can’t perform that action at this time.
0 commit comments