Skip to content

Commit fc6f903

Browse files
authored
test: check tech debt for old nodejs versions #2651
When the minimum nodejs is 16+, we can use the `performance` global always, instead of using `perf_hooks` on nodejs (which doesn't work in the browser).
1 parent 2f0337b commit fc6f903

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

src/shared/extensionUtilities.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,7 @@ export function showWelcomeMessage(context: vscode.ExtensionContext): void {
329329
}
330330

331331
/**
332-
* Creates a modal to display OS, AWS Toolkit, and VS Code
333-
* versions and allows user to copy to clipboard
334-
* Also prints to the toolkit output channel
335-
*
336-
* @param toolkitOutputChannel VS Code Output Channel
332+
* Shows info about the extension and its environment.
337333
*/
338334
export async function aboutToolkit(): Promise<void> {
339335
const toolkitEnvDetails = getToolkitEnvironmentDetails()
@@ -353,16 +349,21 @@ export function getToolkitEnvironmentDetails(): string {
353349
const osArch = os.arch()
354350
const osRelease = os.release()
355351
const vsCodeVersion = vscode.version
352+
const node = process.versions.node ? `node: ${process.versions.node}\n` : 'node: ?\n'
353+
const electron = process.versions.electron ? `electron: ${process.versions.electron}\n` : ''
354+
356355
const envDetails = localize(
357356
'AWS.message.toolkitInfo',
358-
'OS: {0} {1} {2}\n{3} Extension Host Version: {4}\n{5} Toolkit Version: {6}\n',
357+
'OS: {0} {1} {2}\n{3} extension host: {4}\n{5} Toolkit: {6}\n{7}{8}',
359358
osType,
360359
osArch,
361360
osRelease,
362361
getIdeProperties().longName,
363362
vsCodeVersion,
364363
getIdeProperties().company,
365-
extensionVersion
364+
extensionVersion,
365+
node,
366+
electron
366367
)
367368

368369
return envDetails

src/shared/vscode/env.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,10 @@ export function isMinimumVersion(): boolean {
8888
export function getMinVscodeVersion(): string {
8989
return packageJson.engines.vscode.replace(/[^~]/, '')
9090
}
91+
92+
/**
93+
* Returns the minimum nodejs version declared in `package.json`.
94+
*/
95+
export function getMinNodejsVersion(): string {
96+
return packageJson.devDependencies['@types/node'].replace(/[^~]/, '')
97+
}

src/test/techdebt.test.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
import * as assert from 'assert'
77
import * as semver from 'semver'
8-
import { getMinVscodeVersion } from '../shared/vscode/env'
8+
import * as env from '../shared/vscode/env'
99

1010
// Checks project config and dependencies, to remind us to remove old things
1111
// when possible.
1212
describe('tech debt', function () {
1313
it('vscode minimum version', async function () {
14-
const minVscode = getMinVscodeVersion()
14+
const minVscode = env.getMinVscodeVersion()
1515

1616
assert.ok(
1717
semver.lt(minVscode, '1.53.0'),
@@ -23,4 +23,18 @@ describe('tech debt', function () {
2323
'remove filesystemUtilities.findFile(), use vscode.workspace.findFiles() instead'
2424
)
2525
})
26+
27+
it('nodejs minimum version', async function () {
28+
const minNodejs = env.getMinNodejsVersion()
29+
30+
assert.ok(
31+
semver.lt(minNodejs, '16.0.0'),
32+
'remove require("perf_hooks").performance workarounds, use globalThis.performance instead (always available since nodejs 16.x)'
33+
)
34+
35+
assert.ok(
36+
semver.lt(minNodejs, '16.0.0'),
37+
'with node16+, we can now use AbortController to cancel Node things (child processes, HTTP requests, etc.)'
38+
)
39+
})
2640
})

0 commit comments

Comments
 (0)