Skip to content

Commit 484a3ba

Browse files
committed
test/gopls/vulncheck: add logging for viewer test failure
And specify the minimum node.js version requirement in package.json (require 12.0.0+ - released in 2019). Example logs: vulncheck result viewer tests populates-webview: 66.316ms opened document populates-webview: 68.426ms resolved custom text editor populates-webview: 68.649ms posted snapshot-request populates-webview: 371.995ms received message populates-webview: 372.285ms For #2360 Change-Id: I9a9ed244221cfd7d352969ab1953aff5d7eacf13 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/419108 TryBot-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Suzy Mueller <suzmue@golang.org> Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
1 parent 5bf7237 commit 484a3ba

File tree

2 files changed

+56
-39
lines changed

2 files changed

+56
-39
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@
8686
"yarn": "1.22.10"
8787
},
8888
"engines": {
89-
"vscode": "^1.67.0"
89+
"vscode": "^1.67.0",
90+
"node": ">=12.0.0"
9091
},
9192
"activationEvents": [
9293
"onLanguage:go",

test/gopls/vulncheck.test.ts

Lines changed: 54 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -29,44 +29,60 @@ suite('vulncheck result viewer tests', () => {
2929
vscode.Disposable.from(...disposables).dispose();
3030
});
3131

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);
7086

7187
test('handles empty input', async () => {
7288
const webviewPanel = _register(

0 commit comments

Comments
 (0)