Skip to content

Commit

Permalink
test/gopls/vulncheck: add logging for viewer test failure
Browse files Browse the repository at this point in the history
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 golang#2360

Change-Id: I9a9ed244221cfd7d352969ab1953aff5d7eacf13
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/419108
TryBot-Result: kokoro <[email protected]>
Reviewed-by: Suzy Mueller <[email protected]>
Run-TryBot: Hyang-Ah Hana Kim <[email protected]>
  • Loading branch information
hyangah committed Jul 25, 2022
1 parent 5bf7237 commit 484a3ba
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 39 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
"yarn": "1.22.10"
},
"engines": {
"vscode": "^1.67.0"
"vscode": "^1.67.0",
"node": ">=12.0.0"
},
"activationEvents": [
"onLanguage:go",
Expand Down
92 changes: 54 additions & 38 deletions test/gopls/vulncheck.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,44 +29,60 @@ suite('vulncheck result viewer tests', () => {
vscode.Disposable.from(...disposables).dispose();
});

test('populates webview', async function () {
this.timeout(5000);
const webviewPanel = _register(
vscode.window.createWebviewPanel(webviewId, 'title', { viewColumn: vscode.ViewColumn.One }, {})
);
const source = path.join(fixtureDir, 'test.vulncheck.json');
const doc = await vscode.workspace.openTextDocument(source);
const canceller = new vscode.CancellationTokenSource();
_register(canceller);

const watcher = getMessage<{ type: string; target?: string }>(webviewPanel);

await provider.resolveCustomTextEditor(doc, webviewPanel, canceller.token);
webviewPanel.reveal();

// Trigger snapshotContent that sends `snapshot-result` as a result.
webviewPanel.webview.postMessage({ type: 'snapshot-request' });
const res = await watcher;

assert.deepStrictEqual(res.type, 'snapshot-result', `want snapshot-result, got ${JSON.stringify(res)}`);
// res.target type is defined in vulncheckView.js.
const { log = '', vulns = '', unaffecting = '' } = JSON.parse(res.target ?? '{}');

assert(
log.includes('Found 1 known vulnerabilities'),
`expected "1 known vulnerabilities", got ${JSON.stringify(res.target)}`
);
assert(
vulns.includes('GO-2021-0113') &&
vulns.includes('<td>Affecting</td><td>github.com/golang/vscode-go/test/testdata/vuln</td>'),
`expected "Affecting" section, got ${JSON.stringify(res.target)}`
);
// Unaffecting vulnerability's detail is omitted, but its ID is reported.
assert(
unaffecting.includes('GO-2021-0000') && unaffecting.includes('golang.org/x/text'),
`expected reports about unaffecting vulns, got ${JSON.stringify(res.target)}`
);
});
test('populates webview', async () => {
const doTest = async (tag: string) => {
const webviewPanel = _register(
vscode.window.createWebviewPanel(webviewId, 'title', { viewColumn: vscode.ViewColumn.One }, {})
);
const source = path.join(fixtureDir, 'test.vulncheck.json');
const doc = await vscode.workspace.openTextDocument(source);
console.timeLog(tag, 'opened document');
const canceller = new vscode.CancellationTokenSource();
_register(canceller);

const watcher = getMessage<{ type: string; target?: string }>(webviewPanel);

await provider.resolveCustomTextEditor(doc, webviewPanel, canceller.token);
console.timeLog(tag, 'resolved custom text editor');

webviewPanel.reveal();

// Trigger snapshotContent that sends `snapshot-result` as a result.
webviewPanel.webview.postMessage({ type: 'snapshot-request' });
console.timeLog(tag, 'posted snapshot-request');

const res = await watcher;
console.timeLog(tag, 'received message');

assert.deepStrictEqual(res.type, 'snapshot-result', `want snapshot-result, got ${JSON.stringify(res)}`);
// res.target type is defined in vulncheckView.js.
const { log = '', vulns = '', unaffecting = '' } = JSON.parse(res.target ?? '{}');

assert(
log.includes('Found 1 known vulnerabilities'),
`expected "1 known vulnerabilities", got ${JSON.stringify(res.target)}`
);
assert(
vulns.includes('GO-2021-0113') &&
vulns.includes('<td>Affecting</td><td>github.com/golang/vscode-go/test/testdata/vuln</td>'),
`expected "Affecting" section, got ${JSON.stringify(res.target)}`
);
// Unaffecting vulnerability's detail is omitted, but its ID is reported.
assert(
unaffecting.includes('GO-2021-0000') && unaffecting.includes('golang.org/x/text'),
`expected reports about unaffecting vulns, got ${JSON.stringify(res.target)}`
);
};
try {
console.time('populates-webview');
await doTest('populates-webview');
} catch (e) {
console.timeLog('populates-webview', `error thrown: ${e}`);
throw e;
} finally {
console.timeEnd('populates-webview');
}
}).timeout(5_000);

test('handles empty input', async () => {
const webviewPanel = _register(
Expand Down

0 comments on commit 484a3ba

Please sign in to comment.