-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Respect nvmrc for Node version
- Loading branch information
1 parent
8859e2a
commit 99557ea
Showing
7 changed files
with
166 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Copyright (C) Daniel Kuschny (Danielku15) and contributors. | ||
* Copyright (C) Microsoft Corporation. All rights reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style | ||
* license that can be found in the LICENSE file or at | ||
* https://opensource.org/licenses/MIT. | ||
*/ | ||
|
||
import { expect } from 'chai'; | ||
import * as vscode from 'vscode'; | ||
import { captureTestRun, expectTestTree, getController, integrationTestPrepare } from '../util'; | ||
|
||
describe('nvm', () => { | ||
integrationTestPrepare('nvm'); | ||
|
||
it('discovers tests', async () => { | ||
const c = await getController(); | ||
|
||
expectTestTree(c, [['nvm.test.js', [['nvm', [['ensure-version']]]]]]); | ||
}); | ||
|
||
it('runs tests', async () => { | ||
const c = await getController(); | ||
const profiles = c.profiles; | ||
expect(profiles).to.have.lengthOf(2); | ||
|
||
const run = await captureTestRun( | ||
c, | ||
new vscode.TestRunRequest( | ||
undefined, | ||
undefined, | ||
profiles.find((p) => p.kind === vscode.TestRunProfileKind.Run), | ||
), | ||
); | ||
|
||
run.expectStates({ | ||
'nvm.test.js/nvm/ensure-version': ['enqueued', 'started', 'passed'], | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
spec: '**/*.test.js' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const { match } = require('node:assert'); | ||
const { existsSync } = require('node:fs'); | ||
const { platform, homedir } = require('node:os'); | ||
const { join } = require('node:path'); | ||
|
||
describe('nvm', () => { | ||
it('ensure-version', () => { | ||
// keep this in sync with the .nvmrc | ||
const expectedVersion = 'v20'; | ||
|
||
// nvm is only available on MacOS and Linux | ||
// so we skip it on windows. | ||
// also if NVM on local development we skip this test (for GITHUB_ACTIONS we expect it to be there). | ||
const shouldRun = platform() === 'linux' && (isNvmInstalled() || process.env.GITHUB_ACTIONS); | ||
if (shouldRun) { | ||
match(process.version, new RegExp(expectedVersion + '.*')); | ||
} | ||
}); | ||
|
||
function isNvmInstalled() { | ||
// https://github.com/nvm-sh/nvm/blob/179d45050be0a71fd57591b0ed8aedf9b177ba10/install.sh#L27 | ||
const nvmDir = process.env.NVM_DIR || homedir(); | ||
// https://github.com/nvm-sh/nvm/blob/179d45050be0a71fd57591b0ed8aedf9b177ba10/install.sh#L143 | ||
return existsSync(join(nvmDir, '.nvm', '.git')); | ||
} | ||
}); |