-
Notifications
You must be signed in to change notification settings - Fork 3
Assert logs and run test suites conditionally #143
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
4 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
@@ -1,3 +1,8 @@ | ||
{ | ||
"extends": "@react-native/typescript-config/tsconfig.json" | ||
"extends": "@react-native/typescript-config/tsconfig.json", | ||
"compilerOptions": { | ||
"types": ["react-native", "mocha"] | ||
}, | ||
"files": ["App.tsx", "index.ts"], | ||
"references": [{ "path": "./tsconfig.node-scripts.json" }] | ||
} |
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,11 @@ | ||
{ | ||
"extends": "@tsconfig/node22/tsconfig.json", | ||
"compilerOptions": { | ||
"composite": true, | ||
"emitDeclarationOnly": true, | ||
"outDir": "dist", | ||
"rootDir": "scripts", | ||
"types": ["node"] | ||
}, | ||
"include": ["scripts/**/*.ts"] | ||
} |
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
This file was deleted.
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
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,105 @@ | ||
/* eslint-disable @typescript-eslint/no-require-imports */ | ||
|
||
function assertLogs(cb: () => void, expectedMessages: string[]) { | ||
const errors: Error[] = []; | ||
// Spying on the console.log function, as the examples don't assert anything themselves | ||
const originalLog = console.log; | ||
console.log = (message: string, ...args: unknown[]) => { | ||
const nextMessage = expectedMessages.shift(); | ||
const combinedMessage = [message, ...args].map(String).join(" "); | ||
if (nextMessage !== combinedMessage) { | ||
errors.push(new Error(`Unexpected log message '${combinedMessage}'`)); | ||
} | ||
}; | ||
try { | ||
cb(); | ||
if (expectedMessages.length > 0) { | ||
errors.push( | ||
new Error(`Missing expected message(s): ${expectedMessages.join(", ")}`) | ||
); | ||
} | ||
} finally { | ||
console.log = originalLog; | ||
} | ||
// Throw and first error | ||
const [firstError] = errors; | ||
if (firstError) { | ||
throw firstError; | ||
} | ||
} | ||
shirakaba marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
export const suites: Record< | ||
string, | ||
Record<string, () => void | (() => void)> | ||
> = { | ||
"1-getting-started": { | ||
"1_hello_world/napi": () => | ||
assertLogs( | ||
() => | ||
require("../examples/1-getting-started/1_hello_world/napi/hello.js"), | ||
["world"] | ||
), | ||
"1_hello_world/node-addon-api": () => | ||
assertLogs( | ||
() => | ||
require("../examples/1-getting-started/1_hello_world/node-addon-api/hello.js"), | ||
["world"] | ||
), | ||
"1_hello_world/node-addon-api-addon-class": () => | ||
assertLogs( | ||
() => | ||
require("../examples/1-getting-started/1_hello_world/node-addon-api-addon-class/hello.js"), | ||
["world"] | ||
), | ||
"2_function_arguments/napi": () => | ||
assertLogs( | ||
() => | ||
require("../examples/1-getting-started/2_function_arguments/napi/addon.js"), | ||
["This should be eight: 8"] | ||
), | ||
"2_function_arguments/node-addon-api": () => | ||
assertLogs( | ||
() => | ||
require("../examples/1-getting-started/2_function_arguments/node-addon-api/addon.js"), | ||
["This should be eight: 8"] | ||
), | ||
"3_callbacks/napi": () => | ||
assertLogs( | ||
() => | ||
require("../examples/1-getting-started/3_callbacks/napi/addon.js"), | ||
["hello world"] | ||
), | ||
"3_callbacks/node-addon-api": () => | ||
assertLogs( | ||
() => | ||
require("../examples/1-getting-started/3_callbacks/node-addon-api/addon.js"), | ||
["hello world"] | ||
), | ||
"4_object_factory/napi": () => | ||
assertLogs( | ||
() => | ||
require("../examples/1-getting-started/4_object_factory/napi/addon.js"), | ||
["hello world"] | ||
), | ||
"4_object_factory/node-addon-api": () => | ||
assertLogs( | ||
() => | ||
require("../examples/1-getting-started/4_object_factory/node-addon-api/addon.js"), | ||
["hello world"] | ||
), | ||
"5_function_factory": () => | ||
assertLogs( | ||
() => | ||
require("../examples/1-getting-started/5_function_factory/napi/addon.js"), | ||
["hello world"] | ||
), | ||
}, | ||
"5-async-work": { | ||
// TODO: This crashes (SIGABRT) | ||
// "async_work_thread_safe_function": () => require("../examples/5-async-work/async_work_thread_safe_function/napi/index.js"), | ||
}, | ||
tests: { | ||
buffers: () => require("../tests/buffers/addon.js"), | ||
async: () => require("../tests/async/addon.js"), | ||
}, | ||
}; |
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 |
---|---|---|
@@ -1,8 +1,7 @@ | ||
{ | ||
"extends": "@tsconfig/node22/tsconfig.json", | ||
"compilerOptions": { | ||
"module": "node16", | ||
"moduleResolution": "node16" | ||
}, | ||
"include": ["scripts"] | ||
"files": [], | ||
"references": [ | ||
{ "path": "./tsconfig.tests.json" }, | ||
{ "path": "./tsconfig.node-scripts.json" } | ||
] | ||
} |
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 @@ | ||
{ | ||
"extends": "@tsconfig/node22/tsconfig.json", | ||
"compilerOptions": { | ||
"composite": true, | ||
"emitDeclarationOnly": true, | ||
"outDir": "dist", | ||
"rootDir": "scripts", | ||
"types": ["node", "read-pkg"] | ||
}, | ||
"include": ["scripts/**/*.mts"], | ||
"exclude": [] | ||
} |
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 @@ | ||
{ | ||
"extends": "@tsconfig/react-native", | ||
"compilerOptions": { | ||
"composite": true, | ||
"noEmit": false, | ||
"module": "commonjs", | ||
"outDir": "dist", | ||
"rootDir": "src", | ||
"types": ["react-native"] | ||
}, | ||
"include": ["src/*.ts"] | ||
} |
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
Oops, something went wrong.
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.
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.
So by default, both
nodeAddonExamples
andferricExample
resolve tofalse
and so both the "Node Addon Examples" and "ferric-example" tests get skipped? Is that the intention?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.
I might still be debating this with myself 😊
On one hand it might be confusing to skip so many tests by default and on the other it does leave a potential to cut down on the time pre-building while bootstrapping and complexity (having to have the Rust toolchain installed) when someone wants to contribute to the project.
Looking back at this (I wrote it some weeks back), the optimization does seem a bit premature.
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.
In my (though not strongly held)) opinion we could either enable all tests by default or skip only
ferric-example
since it requires additional Rust setup.