Skip to content

Commit

Permalink
test: use local node if it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed May 11, 2024
1 parent 48f0a75 commit e062973
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
21 changes: 21 additions & 0 deletions tests/utils/get-node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import _getNode from 'get-node';

export const getNode = async (
nodeVersion: string,
) => {
if (nodeVersion === process.version) {
return {
version: process.versions.node,
path: process.execPath,
};
}

console.log('Getting node', nodeVersion);
const startTime = Date.now();
const node = await _getNode(nodeVersion, {
progress: true,
});
console.log(`Got node in ${Date.now() - startTime}ms`, node);

return node;
};
10 changes: 2 additions & 8 deletions tests/utils/tsx.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { fileURLToPath } from 'node:url';
import { execaNode, type NodeOptions } from 'execa';
import getNode from 'get-node';
import {
isFeatureSupported,
moduleRegister,
testRunnerGlob,
type Version,
} from '../../src/utils/node-features.js';
import { getNode } from './get-node.js';

type Options = {
args: string[];
Expand Down Expand Up @@ -45,13 +45,7 @@ export const tsx = (
export const createNode = async (
nodeVersion: string,
) => {
console.log('Getting node', nodeVersion);
const startTime = Date.now();
const node = await getNode(nodeVersion, {
progress: true,
});
console.log(`Got node in ${Date.now() - startTime}ms`, node);

const node = await getNode(nodeVersion);
const versionParsed = node.version.split('.').map(Number) as Version;
const supports = {
moduleRegister: isFeatureSupported(moduleRegister, versionParsed),
Expand Down

0 comments on commit e062973

Please sign in to comment.