-
-
Notifications
You must be signed in to change notification settings - Fork 9
Harness scaffold and Node.js implementor #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c5c08d2
Add a failing test
kraenhansen f9435d8
Add assert implementation
kraenhansen 73df7c8
Update copilot instructions
kraenhansen 3a51975
Add docs on the implementors directory
kraenhansen 5000068
Add simple GHA action running the Node.js tests
kraenhansen a6f2fa0
Apply suggestions from code review
kraenhansen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,34 @@ | ||
| name: Test Node.js implementation | ||
|
|
||
| on: [push, pull_request] | ||
|
|
||
| jobs: | ||
| test: | ||
| timeout-minutes: 10 | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| node-version: | ||
| - 20.x | ||
| - 22.x | ||
| - 24.x | ||
| - 25.x | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Harden Runner | ||
| uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1 | ||
| with: | ||
| egress-policy: audit | ||
|
|
||
| - name: Use Node.js ${{ matrix.node-version }} | ||
| uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 | ||
| with: | ||
| node-version: ${{ matrix.node-version }} | ||
| - name: Check Node.js installation | ||
| run: | | ||
| node --version | ||
| npm --version | ||
| - name: Install dependencies | ||
| run: npm ci | ||
| - name: npm test | ||
| run: npm run node:test |
This file contains hidden or 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 @@ | ||
| node_modules/ |
This file contains hidden or 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 hidden or 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,8 @@ | ||
|
|
||
| import { ok } from "node:assert/strict"; | ||
|
|
||
| const assert = (value, message) => { | ||
| ok(value, message); | ||
| }; | ||
|
|
||
| Object.assign(globalThis, { assert }); |
This file contains hidden or 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,104 @@ | ||
| import { spawn } from "node:child_process"; | ||
| import { promises as fs } from "node:fs"; | ||
| import path from "node:path"; | ||
| import { test, type TestContext } from "node:test"; | ||
|
|
||
| const ROOT_PATH = path.resolve(import.meta.dirname, "..", ".."); | ||
| const TESTS_ROOT_PATH = path.join(ROOT_PATH, "tests"); | ||
| const ASSERT_MODULE_PATH = path.join( | ||
| ROOT_PATH, | ||
| "implementors", | ||
| "node", | ||
| "assert.js" | ||
| ); | ||
|
|
||
| async function listDirectoryEntries(dir: string) { | ||
| const entries = await fs.readdir(dir, { withFileTypes: true }); | ||
| const directories: string[] = []; | ||
| const files: string[] = []; | ||
|
|
||
| for (const entry of entries) { | ||
| if (entry.isDirectory()) { | ||
| directories.push(entry.name); | ||
| } else if (entry.isFile() && entry.name.endsWith(".js")) { | ||
| files.push(entry.name); | ||
| } | ||
| } | ||
|
|
||
| directories.sort(); | ||
| files.sort(); | ||
|
|
||
| return { directories, files }; | ||
| } | ||
|
|
||
| function runFileInSubprocess(filePath: string): Promise<void> { | ||
| return new Promise((resolve, reject) => { | ||
| const child = spawn(process.execPath, [ | ||
| "--import", | ||
| ASSERT_MODULE_PATH, | ||
| filePath, | ||
| ]); | ||
|
|
||
| let stderrOutput = ""; | ||
| child.stderr.setEncoding("utf8"); | ||
| child.stderr.on("data", (chunk) => { | ||
| stderrOutput += chunk; | ||
| }); | ||
|
|
||
| child.stdout.pipe(process.stdout); | ||
|
|
||
| child.on("error", reject); | ||
|
|
||
| child.on("close", (code, signal) => { | ||
| if (code === 0) { | ||
| resolve(); | ||
| return; | ||
| } | ||
|
|
||
| const reason = | ||
| code !== null ? `exit code ${code}` : `signal ${signal ?? "unknown"}`; | ||
| const trimmedStderr = stderrOutput.trim(); | ||
| const stderrSuffix = trimmedStderr | ||
| ? `\n--- stderr ---\n${trimmedStderr}\n--- end stderr ---` | ||
| : ""; | ||
| reject( | ||
| new Error( | ||
| `Test file ${path.relative( | ||
| TESTS_ROOT_PATH, | ||
| filePath | ||
| )} failed (${reason})${stderrSuffix}` | ||
| ) | ||
| ); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| async function populateSuite( | ||
| testContext: TestContext, | ||
| dir: string | ||
| ): Promise<void> { | ||
| const { directories, files } = await listDirectoryEntries(dir); | ||
|
|
||
| for (const file of files) { | ||
| const filePath = path.join(dir, file); | ||
| await testContext.test(file, () => runFileInSubprocess(filePath)); | ||
| } | ||
|
|
||
| for (const directory of directories) { | ||
| await testContext.test(directory, async (subTest) => { | ||
| await populateSuite(subTest, path.join(dir, directory)); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| test("harness", async (t) => { | ||
| await populateSuite(t, path.join(TESTS_ROOT_PATH, "harness")); | ||
| }); | ||
|
|
||
| test("js-native-api", async (t) => { | ||
| await populateSuite(t, path.join(TESTS_ROOT_PATH, "js-native-api")); | ||
| }); | ||
|
|
||
| test("node-api", async (t) => { | ||
| await populateSuite(t, path.join(TESTS_ROOT_PATH, "node-api")); | ||
| }); | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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,12 @@ | ||
| { | ||
| "name": "node-api-cts", | ||
| "version": "0.1.0", | ||
| "private": true, | ||
| "type": "module", | ||
| "scripts": { | ||
| "node:test": "node --test ./implementors/node/run-tests.ts" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/node": "^24.10.1" | ||
| } | ||
| } |
This file contains hidden or 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,33 @@ | ||
| if (typeof assert !== 'function') { | ||
| throw new Error('Expected a global assert function'); | ||
| } | ||
|
|
||
| try { | ||
| assert(true, 'assert(true, message) should not throw'); | ||
| } catch (error) { | ||
| throw new Error(`Global assert(true, message) must not throw: ${String(error)}`); | ||
| } | ||
|
|
||
| const failureMessage = 'assert(false, message) should throw this message'; | ||
| let threw = false; | ||
|
|
||
| try { | ||
| assert(false, failureMessage); | ||
| } catch (error) { | ||
| threw = true; | ||
|
|
||
| if (!(error instanceof Error)) { | ||
| throw new Error(`Global assert(false, message) must throw an Error instance but got: ${String(error)}`); | ||
| } | ||
|
|
||
| const actualMessage = error.message; | ||
| if (actualMessage !== failureMessage) { | ||
| throw new Error( | ||
| `Global assert(false, message) must throw message "${failureMessage}" but got "${actualMessage}"`, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| if (!threw) { | ||
| throw new Error('Global assert(false, message) must throw'); | ||
| } |
Empty file.
Empty file.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.