Skip to content

Commit

Permalink
fix: add node 22 support
Browse files Browse the repository at this point in the history
  • Loading branch information
connor4312 committed Apr 29, 2024
1 parent 607239e commit a490ae2
Show file tree
Hide file tree
Showing 12 changed files with 235 additions and 122 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ on:
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20, 22]

steps:
- name: Checkout code
Expand All @@ -19,7 +22,7 @@ jobs:
- name: Setup Node.js environment
uses: actions/setup-node@v2
with:
node-version: '21'
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: npm ci
Expand Down
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
"@types/picomatch": "^2.3.3",
"@types/sinon": "^17.0.3",
"@types/split2": "^4.2.3",
"@types/vscode": "^1.86.0",
"@types/vscode": "^1.88.0",
"@types/ws": "^8.5.10",
"@vscode/test-electron": "^2.3.9",
"acorn": "^8.11.3",
Expand All @@ -204,7 +204,7 @@
"mocha": "^10.3.0",
"prettier": "^3.2.5",
"sinon": "^17.0.1",
"tsx": "^4.7.1",
"tsx": "^4.7.3",
"typescript": "^5.4.2",
"vitest": "^1.3.1"
},
Expand Down
1 change: 1 addition & 0 deletions src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ICreateOpts, ItemType, getContainingItemsForFile, testMetadata } from "
import { IParsedNode, parseSource } from "./parsing";
import { RunHandler, TestRunner } from "./runner";
import { ISourceMapMaintainer, SourceMapStore } from "./source-map-store";
import { ExtensionConfig } from './extension-config';

const diagnosticCollection = vscode.languages.createDiagnosticCollection("nodejs-testing-dupes");

Expand Down
2 changes: 1 addition & 1 deletion src/ExtensionConfig.ts → src/extension-config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
interface ExtensionConfig {
export interface ExtensionConfig {
extensions: string[];
filePatterns?: string[];
parameters: string[];
Expand Down
20 changes: 20 additions & 0 deletions src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,23 @@ export function* getContainingItemsForFile(
}
}
}

export function getFullTestName(test: vscode.TestItem) {
let name = test.label;
while (test.parent && testMetadata.get(test.parent)?.type === ItemType.Test) {
test = test.parent;
name = `${test.label} ${name}`;
}

return name;
}

export function isParent(possibleParent: vscode.TestItem, possibleChild: vscode.TestItem) {
for (let t: vscode.TestItem | undefined = possibleChild; t; t = t.parent) {
if (t === possibleParent) {
return true;
}
}

return false;
}
14 changes: 5 additions & 9 deletions src/runner-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export const contract = makeContract({
// the interface for servers to interact with clients
client: {
kill: notificationType({}),
version: requestType({
params: s.sNull(),
result: s.sString(),
}),
start: requestType({
params: s.sObject({
verbose: s.sBoolean(),
Expand Down Expand Up @@ -101,10 +105,7 @@ export const contract = makeContract({
),
extraEnv: s.sMap(s.sString()),
}),
result: s.sObject({
status: s.sNumber(),
message: s.optionalProp(s.sString()),
}),
result: s.sNull(),
}),
},
});
Expand All @@ -118,11 +119,6 @@ export type ITestRunResult = (typeof contract)["client"]["start"]["resultSeriali

export type ILog = (typeof log)["T"];

export const enum CompleteStatus {
Done,
NodeVersionOutdated,
}

export const enum Result {
Ok,
Skipped,
Expand Down
14 changes: 5 additions & 9 deletions src/runner-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import split from "split2";
import { StackFrame } from "stacktrace-parser";
import { pathToFileURL } from "url";
import { WebSocket } from "ws";
import { ExtensionConfig } from "./extension-config";
import { escapeRegex } from "./regex";
import { CompleteStatus, ITestRunFile, JsonFromReporter, contract } from "./runner-protocol";
import { ITestRunFile, JsonFromReporter, contract } from "./runner-protocol";

const colors = [
ansiColors.redBright,
Expand Down Expand Up @@ -45,19 +46,14 @@ const start: (typeof contract)["TClientHandler"]["start"] = async ({
extraEnv,
coverageDir,
}) => {
const majorVersion = /^v([0-9]+)/.exec(process.version);
if (!majorVersion || Number(majorVersion[1]) < 19) {
return { status: CompleteStatus.NodeVersionOutdated, message: process.version };
}

const todo: Promise<void>[] = [];
for (let i = 0; i < concurrency && i < files.length; i++) {
const prefix = colors[i % colors.length](`worker${i + 1}> `);
todo.push(doWork(prefix, files, extensions, verbose, extraEnv, coverageDir));
}
await Promise.all(todo);

return { status: CompleteStatus.Done };
return null;
};

async function doWork(
Expand Down Expand Up @@ -90,7 +86,7 @@ async function doWork(

args.push(next.path);
if (verbose) {
server.output(`${prefix}${path.basename(process.argv0)} ${args.join('" "')}`);
server.output(`${prefix}${process.argv0} ${args.join('" "')}`);
}

const cp = spawn(process.argv0, args, {
Expand Down Expand Up @@ -282,5 +278,5 @@ const { server } = Contract.getServerFromStream(
contract,
new NodeJsMessageStream(socket, socket),
{},
{ start, kill: () => process.exit() },
{ start, kill: () => process.exit(), version: () => Promise.resolve(process.version) },
);
Loading

0 comments on commit a490ae2

Please sign in to comment.