@@ -29,44 +29,60 @@ suite('vulncheck result viewer tests', () => {
29
29
vscode . Disposable . from ( ...disposables ) . dispose ( ) ;
30
30
} ) ;
31
31
32
- test ( 'populates webview' , async function ( ) {
33
- this . timeout ( 5000 ) ;
34
- const webviewPanel = _register (
35
- vscode . window . createWebviewPanel ( webviewId , 'title' , { viewColumn : vscode . ViewColumn . One } , { } )
36
- ) ;
37
- const source = path . join ( fixtureDir , 'test.vulncheck.json' ) ;
38
- const doc = await vscode . workspace . openTextDocument ( source ) ;
39
- const canceller = new vscode . CancellationTokenSource ( ) ;
40
- _register ( canceller ) ;
41
-
42
- const watcher = getMessage < { type : string ; target ?: string } > ( webviewPanel ) ;
43
-
44
- await provider . resolveCustomTextEditor ( doc , webviewPanel , canceller . token ) ;
45
- webviewPanel . reveal ( ) ;
46
-
47
- // Trigger snapshotContent that sends `snapshot-result` as a result.
48
- webviewPanel . webview . postMessage ( { type : 'snapshot-request' } ) ;
49
- const res = await watcher ;
50
-
51
- assert . deepStrictEqual ( res . type , 'snapshot-result' , `want snapshot-result, got ${ JSON . stringify ( res ) } ` ) ;
52
- // res.target type is defined in vulncheckView.js.
53
- const { log = '' , vulns = '' , unaffecting = '' } = JSON . parse ( res . target ?? '{}' ) ;
54
-
55
- assert (
56
- log . includes ( 'Found 1 known vulnerabilities' ) ,
57
- `expected "1 known vulnerabilities", got ${ JSON . stringify ( res . target ) } `
58
- ) ;
59
- assert (
60
- vulns . includes ( 'GO-2021-0113' ) &&
61
- vulns . includes ( '<td>Affecting</td><td>github.com/golang/vscode-go/test/testdata/vuln</td>' ) ,
62
- `expected "Affecting" section, got ${ JSON . stringify ( res . target ) } `
63
- ) ;
64
- // Unaffecting vulnerability's detail is omitted, but its ID is reported.
65
- assert (
66
- unaffecting . includes ( 'GO-2021-0000' ) && unaffecting . includes ( 'golang.org/x/text' ) ,
67
- `expected reports about unaffecting vulns, got ${ JSON . stringify ( res . target ) } `
68
- ) ;
69
- } ) ;
32
+ test ( 'populates webview' , async ( ) => {
33
+ const doTest = async ( tag : string ) => {
34
+ const webviewPanel = _register (
35
+ vscode . window . createWebviewPanel ( webviewId , 'title' , { viewColumn : vscode . ViewColumn . One } , { } )
36
+ ) ;
37
+ const source = path . join ( fixtureDir , 'test.vulncheck.json' ) ;
38
+ const doc = await vscode . workspace . openTextDocument ( source ) ;
39
+ console . timeLog ( tag , 'opened document' ) ;
40
+ const canceller = new vscode . CancellationTokenSource ( ) ;
41
+ _register ( canceller ) ;
42
+
43
+ const watcher = getMessage < { type : string ; target ?: string } > ( webviewPanel ) ;
44
+
45
+ await provider . resolveCustomTextEditor ( doc , webviewPanel , canceller . token ) ;
46
+ console . timeLog ( tag , 'resolved custom text editor' ) ;
47
+
48
+ webviewPanel . reveal ( ) ;
49
+
50
+ // Trigger snapshotContent that sends `snapshot-result` as a result.
51
+ webviewPanel . webview . postMessage ( { type : 'snapshot-request' } ) ;
52
+ console . timeLog ( tag , 'posted snapshot-request' ) ;
53
+
54
+ const res = await watcher ;
55
+ console . timeLog ( tag , 'received message' ) ;
56
+
57
+ assert . deepStrictEqual ( res . type , 'snapshot-result' , `want snapshot-result, got ${ JSON . stringify ( res ) } ` ) ;
58
+ // res.target type is defined in vulncheckView.js.
59
+ const { log = '' , vulns = '' , unaffecting = '' } = JSON . parse ( res . target ?? '{}' ) ;
60
+
61
+ assert (
62
+ log . includes ( 'Found 1 known vulnerabilities' ) ,
63
+ `expected "1 known vulnerabilities", got ${ JSON . stringify ( res . target ) } `
64
+ ) ;
65
+ assert (
66
+ vulns . includes ( 'GO-2021-0113' ) &&
67
+ vulns . includes ( '<td>Affecting</td><td>github.com/golang/vscode-go/test/testdata/vuln</td>' ) ,
68
+ `expected "Affecting" section, got ${ JSON . stringify ( res . target ) } `
69
+ ) ;
70
+ // Unaffecting vulnerability's detail is omitted, but its ID is reported.
71
+ assert (
72
+ unaffecting . includes ( 'GO-2021-0000' ) && unaffecting . includes ( 'golang.org/x/text' ) ,
73
+ `expected reports about unaffecting vulns, got ${ JSON . stringify ( res . target ) } `
74
+ ) ;
75
+ } ;
76
+ try {
77
+ console . time ( 'populates-webview' ) ;
78
+ await doTest ( 'populates-webview' ) ;
79
+ } catch ( e ) {
80
+ console . timeLog ( 'populates-webview' , `error thrown: ${ e } ` ) ;
81
+ throw e ;
82
+ } finally {
83
+ console . timeEnd ( 'populates-webview' ) ;
84
+ }
85
+ } ) . timeout ( 5_000 ) ;
70
86
71
87
test ( 'handles empty input' , async ( ) => {
72
88
const webviewPanel = _register (
0 commit comments