File tree Expand file tree Collapse file tree 2 files changed +60
-1
lines changed Expand file tree Collapse file tree 2 files changed +60
-1
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,15 @@ export default class GitHubTree {
35
35
branch,
36
36
path
37
37
} ) ;
38
- return data . repository . ref . target . history . nodes [ 0 ] . oid ;
38
+
39
+ const targetHistoryNodes = data . repository . ref . target . history . nodes ;
40
+ if ( ! targetHistoryNodes . length ) {
41
+ // Sometimes this function is in a spinner, and we need to print the error
42
+ // after a new line.
43
+ console . log ( ) ;
44
+ throw new Error ( `Cannot find WPT for "${ path } ". Please check the WPT name.` ) ;
45
+ }
46
+ return targetHistoryNodes [ 0 ] . oid ;
39
47
}
40
48
41
49
/**
Original file line number Diff line number Diff line change
1
+ import { describe , it , before , after } from 'node:test' ;
2
+ import assert from 'node:assert' ;
3
+ import TestCLI from '../fixtures/test_cli.js' ;
4
+ import sinon from 'sinon' ;
5
+
6
+ import { WPTUpdater } from '../../lib/wpt/index.js' ;
7
+
8
+ describe ( 'WPTUpdater' , function ( ) {
9
+ const UNKNOWN_PATH = 'unknown path' ;
10
+ let request ;
11
+ let wptUpdater ;
12
+ let nodedir ;
13
+ let cli ;
14
+ let path ;
15
+ const emptyData = {
16
+ repository :
17
+ {
18
+ ref : { target : { history : { nodes : [ ] } } }
19
+ }
20
+ } ;
21
+
22
+ before ( ( ) => {
23
+ cli = cli = new TestCLI ( ) ;
24
+ request = {
25
+ gql : sinon . stub ( )
26
+ } ;
27
+ nodedir = '.' ;
28
+ request . gql . withArgs (
29
+ 'LastCommit' ,
30
+ { path : UNKNOWN_PATH }
31
+ ) . returns ( Promise . resolve ( emptyData ) ) ;
32
+ } ) ;
33
+
34
+ after ( ( ) => {
35
+ cli . clearCalls ( ) ;
36
+ } ) ;
37
+
38
+ it ( 'throws meaningful error when WPT name not found' , async ( ) => {
39
+ path = UNKNOWN_PATH ;
40
+ wptUpdater = new WPTUpdater ( path , cli , request , nodedir ) ;
41
+ let thrown = null ;
42
+ try {
43
+ await wptUpdater . update ( ) ;
44
+ } catch ( err ) {
45
+ thrown = err ;
46
+ }
47
+
48
+ assert ( thrown instanceof Error ) ;
49
+ assert ( thrown . message , `Cannot find WPT for "${ path } ". Please check the WPT name.` ) ;
50
+ } ) ;
51
+ } ) ;
You can’t perform that action at this time.
0 commit comments