-
-
Notifications
You must be signed in to change notification settings - Fork 11
feat: extend harness with assert methods, gcUntil, and --expose-gc #27
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,24 @@ | ||
|
|
||
| import { ok } from "node:assert/strict"; | ||
| import { | ||
| ok, | ||
| strictEqual, | ||
| notStrictEqual, | ||
| deepStrictEqual, | ||
| throws, | ||
| } from "node:assert/strict"; | ||
|
|
||
| const assert = (value, message) => { | ||
| ok(value, message); | ||
| }; | ||
| const assert = Object.assign( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-blocking: I would prefer avoiding the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was my initial thought as well (which is why I didn't add it initially). I realised later as I was porting tests that it's probably more important that the tests are ported as close to their original source as possible - to minimise the risk of loosing coverage. With these helpers it's more obvious that we're actually testing the same as the Node.js test suite. I suggest we keep this as is for now and when we have more tests ported and ideally multiple implementors running these tests we can start refactoring them in isolation. How does that plan sound to you? |
||
| (value, message) => ok(value, message), | ||
| { | ||
| ok: (value, message) => ok(value, message), | ||
| strictEqual: (actual, expected, message) => | ||
| strictEqual(actual, expected, message), | ||
| notStrictEqual: (actual, expected, message) => | ||
| notStrictEqual(actual, expected, message), | ||
| deepStrictEqual: (actual, expected, message) => | ||
| deepStrictEqual(actual, expected, message), | ||
| throws: (fn, error, message) => throws(fn, error, message), | ||
| }, | ||
| ); | ||
|
|
||
| Object.assign(globalThis, { assert }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| const gcUntil = async (name, condition) => { | ||
| let count = 0; | ||
| while (!condition()) { | ||
| await new Promise((resolve) => setImmediate(resolve)); | ||
| if (++count < 10) { | ||
| globalThis.gc(); | ||
| } else { | ||
| throw new Error(`GC test "${name}" failed after ${count} attempts`); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| Object.assign(globalThis, { gcUntil }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| if (typeof gcUntil !== 'function') { | ||
| throw new Error('Expected a global gcUntil function'); | ||
| } | ||
|
|
||
| // gcUntil should resolve once the condition becomes true | ||
| let count = 0; | ||
| await gcUntil('test-passes', () => { | ||
| count++; | ||
| return count >= 2; | ||
| }); | ||
| if (count < 2) { | ||
| throw new Error(`Expected condition to be checked at least twice, got ${count}`); | ||
| } | ||
|
|
||
| // gcUntil should throw after exhausting retries when condition never becomes true | ||
| let threw = false; | ||
| try { | ||
| await gcUntil('test-fails', () => false); | ||
| } catch (error) { | ||
| threw = true; | ||
| if (!error.message.includes('test-fails')) { | ||
| throw new Error(`Expected error message to include 'test-fails' but got: ${error.message}`); | ||
| } | ||
| } | ||
| if (!threw) { | ||
| throw new Error('gcUntil must throw when the condition never becomes true'); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See https://cmake.org/cmake/help/latest/command/function.html#arguments for details on the
ARGNvariable.