{"id":33062617,"url":"https://github.com/jamesshore/test-console","last_synced_at":"2025-11-15T00:01:09.835Z","repository":{"id":15549324,"uuid":"18284316","full_name":"jamesshore/test-console","owner":"jamesshore","description":"A simple and pragmatic library for testing Node.js console output.","archived":false,"fork":false,"pushed_at":"2023-04-15T18:37:12.000Z","size":97,"stargazers_count":86,"open_issues_count":4,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-11-08T04:22:27.504Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jamesshore.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-03-31T06:49:27.000Z","updated_at":"2025-11-03T22:11:00.000Z","dependencies_parsed_at":"2024-06-18T13:54:56.763Z","dependency_job_id":"b5cd1f11-d652-422d-9f88-4c494b66edea","html_url":"https://github.com/jamesshore/test-console","commit_stats":{"total_commits":56,"total_committers":3,"mean_commits":"18.666666666666668","dds":0.0357142857142857,"last_synced_commit":"358b70500bc76232a7ba74f4b0e5b30b8f552319"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/jamesshore/test-console","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesshore%2Ftest-console","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesshore%2Ftest-console/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesshore%2Ftest-console/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesshore%2Ftest-console/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jamesshore","download_url":"https://codeload.github.com/jamesshore/test-console/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesshore%2Ftest-console/sbom","scorecard":{"id":504235,"data":{"date":"2025-08-11","repo":{"name":"github.com/jamesshore/test-console","commit":"358b70500bc76232a7ba74f4b0e5b30b8f552319"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":1.2,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":0,"reason":"Found 2/29 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: npmCommand not pinned by hash: jake.sh:3","Info:   0 out of   1 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"License","score":0,"reason":"license file not detected","details":["Warn: project does not have a license file"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 3 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"10 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-4q6p-r6v2-jvc5","Warn: Project is vulnerable to: GHSA-hxm2-r34f-qmc5","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-qrpm-p2h7-hrv2","Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55","Warn: Project is vulnerable to: GHSA-4rq4-32rv-6wp6","Warn: Project is vulnerable to: GHSA-64g7-mvw6-v9qj"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-19T22:52:59.814Z","repository_id":15549324,"created_at":"2025-08-19T22:52:59.814Z","updated_at":"2025-08-19T22:52:59.814Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":283459971,"owners_count":26839474,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-09T02:00:05.828Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-11-14T06:00:37.075Z","updated_at":"2025-11-15T00:01:09.809Z","avatar_url":"https://github.com/jamesshore.png","language":"JavaScript","funding_links":[],"categories":["📦 Modules/Packages"],"sub_categories":["Testing"],"readme":"# test-console\n\nA simple and pragmatic library for testing Node.js console output.\n\n\n## Example\n\nSee the API section for more examples.\n\n```javascript\nconst stdout = require(\"test-console\").stdout;\n\nconst output = stdout.inspectSync(() =\u003e {\n    console.log(\"foo\");\n});\nassert.deepEqual(output, [ \"foo\\n \"]);\n```\n\n## Installation\n\nThis is a Node.js library. Install Node, then:\n\n`npm install test-console` (add `--save` or `--save-dev` if you want)\n\nTo use the library in your code, require it as follows:\n\n```javascript\nconst stdout = require(\"test-console\").stdout;\nconst stderr = require(\"test-console\").stderr;\n```\n\n\n## API\n\n* `stdout.inspect`: Redirects writes to `stdout` into an array instead of writing them to console.\n* `stdout.inspectSync`: Just like `inspect()`, but automatically restores the console when done.\n* `stdout.inspectAsync`: Just like `inspectSync()`, but works with async functions.\n* `stdout.ignore`: Prevent writes to `stdout` from appearing on the console.\n* `stdout.ignoreSync`: Just like `ignore()`, but automatically restores the console when done.\n* `stdout.ignoreAsync`: Just like `ignoreSync()`, but works with async functions.\n\nAll functions accept an optional options object as the first argument, where `isTTY` is the only available option. `isTTY`, if defined, will override the `stdout` field of the same name.\n\nThe same API is also available on `stderr`.\n\n\n### `inspect = stdout.inspect(options)`\n\nRedirects writes to `stdout` into an array instead of writing them to the console.\n\n* `options`: object [optional]\n  * `isTTY`: If not undefined, this value will be used to temporarily overwrite `stdout.isTTY`.\n\n* `inspect`: Returned as an `EventEmitter` with two properties and one event:\n  * `inspect.output`: An array containing one string for each call to `stdout.write()`. This array updates every time another call to `stdout.write()` is made.\n  * `inspect.restore()`: Call this function to restore `stdout.write()` to its normal behavior.\n  * `data` event: This event fires every time `stdout.write()` is called.\n\nExample of using `inspect()` to test a synchronous function:\n\n```javascript\nconst inspect = stdout.inspect();\nfunctionUnderTest();\ninspect.restore();\nassert.deepEqual(inspect.output, [ \"foo\\n\" ]);\n```\n\nExample of using `inspect()` to test an asynchronous function with await:\n\n```javascript\nconst inspect = stdout.inspect();\nawait functionUnderTestAsync();\ninspect.restore();\nassert.deepEqual(inspect.output, [ \"foo\\n\" ]);\n```\n\nExample of using `inspect()` to test an asynchronous function with a callback:\n\n```javascript\nconst inspect = stdout.inspect();\nfunctionUnderTest(() =\u003e {\n    inspect.restore();\n    assert.deepEqual(inspect.output, [ \"foo\\n\" ]);\n});\n```\n\nExample of using `inspect()` to listen for an event:\n\n```javascript\nconst inspect = stdout.inspect();\nlet output = \"\";\ninspect.on(\"data\", (chunk) =\u003e {\n    output += chunk;\n});\nfunctionUnderTestAsync();\ninspect.restore();\nassert.equal(output, \"foo\\n\");\n```\n\n\n### `output = stdout.inspectSync(options, fn)`\n### `output = stdout.inspectSync(fn)`\n\nJust like `inspect()`, but automatically restores the console when done.\n\n* `options`: object [optional]\n  * `isTTY`: If not undefined, this value will be used to temporarily overwrite `stdout.isTTY`.\n\n* `fn(output)`: The function to run while inspecting stdout. After the function returns, stdout.write is automatically restored. Note that `output` is passed into this function in addition to being returned from `inspectSync()`.\n\n* `output`: Passed into `fn` and also returned as an array. Contains one string for each call to `stdout.write()`. This array updates every time another call to `stdout.write()` is made.\n\nExample of using `inspectSync()` to test a synchronous function:\n\n```javascript\nconst output = stdout.inspectSync(() =\u003e {\n    functionUnderTest();\n});\nassert.deepEqual(output, [ \"foo\\n\" ]);\n```\n\nExample of using `inspectSync() to incrementally test several synchronous functions:\n\n```javascript\nstdout.inspectSync((output) =\u003e {\n    functionUnderTest();\n    assert.deepEqual(output, [ \"foo\\n\" ]);\n    anotherFunctionUnderTest();\n    assert.deepEqual(output, [ \"foo\\n\", \"bar\\n\" ]);\n});\n```\n\n\n### `output = await stdout.inspectAsync(options, fn)`\n### `output = await stdout.inspectAsync(fn)`\n\nJust like `inspectSync()`, but works with asynchronous functions.\n\n* `options`: object [optional]\n  * `isTTY`: If not undefined, this value will be used to temporarily overwrite `stdout.isTTY`.\n\n* `fnAsync(output)`: The function to run while inspecting stdout. After the function returns, stdout.write is automatically restored. Note that `output` is passed into this function in addition to being returned from `inspectSync()`.\n\n* `output`: Passed into `fnAsync` and also returned as an array containing one string for each call to `stdout.write()`. This array updates every time another call to `stdout.write()` is made.\n\nExample of using `inspectAsync()` to test an asynchronous function:\n\n```javascript\nconst output = await stdout.inspectAsync(async () =\u003e {\n    await functionUnderTestAsync();\n});\nassert.deepEqual(output, [ \"foo\\n\" ]);\n```\n\nExample of using `inspectAsync() to incrementally test several asynchronous functions:\n\n```javascript\nawait stdout.inspectAsync(async (output) =\u003e {\n    await functionUnderTestAsync();\n    assert.deepEqual(output, [ \"foo\\n\" ]);\n    await anotherFunctionUnderTestAsync();\n    assert.deepEqual(output, [ \"foo\\n\", \"bar\\n\" ]);\n});\n```\n\n\n### `restore = stdout.ignore(options)`\n\nPrevent writes to `stdout` from appearing on the console.\n\n* `options`: object [optional]\n  * `isTTY`: If not undefined, this value will be used to temporarily overwrite `stdout.isTTY`\n\n* `restore()`: Call this function to restore stdout.write to its normal behavior.\n\nExample of using `ignore()` to prevent a synchronous function from writing to the console:\n\n```javascript\nconst restore = stdout.ignore();\nfunctionUnderTest();\nrestore();\n```\n\nExample of using `ignore()` to prevent an asynchronous function with a callback from writing to the console:\n\n```javascript\nconst restore = stdout.ignore();\nfunctionUnderTest(() =\u003e {\n    restore();\n});\n```\n\nExample of using `ignore()` to prevent a suite of tests from writing to the console:\n\n```javascript\nlet restoreStdout;\n\nbeforeEach(() =\u003e {\n    restoreStdout = stdout.ignore();\n});\n\nafterEach(() =\u003e {\n    restoreStdout();\n});\n\n// tests go here\n```\n\n\n### `ignoreSync(options, fn)`\n### `ignoreSync(fn)`\n\nJust like `ignore()`, but automatically restores the console when done.\n\n* `options`: object [optional]\n  * `isTTY`: If not undefined, this value will be used to temporarily overwrite `stdout.isTTY`\n\n* `fn()`: The function to run while ignoring stdout. After the function returns, stdout.write is automatically restored.\n\nExample of using `ignoreSync()` to prevent a synchronous function from writing to the console:\n\n```javascript\nstdout.ignoreSync(() =\u003e {\n    functionUnderTest();\n});\n```\n\n\n### `await ignoreAsync(options, fnAsync)`\n### `await ignoreAsync(fn)`\n\nJust like `ignoreSync()`, but works with async/await.\n\n* `options`: object [optional]\n  * `isTTY`: If not undefined, this value will be used to temporarily overwrite `stdout.isTTY`\n\n* `fnAsync()`: The function to run while ignoring stdout. After the function returns, stdout.write is automatically restored.\n\nExample of using `ignoreSync()` to prevent an asynchronous function from writing to the console:\n\n```javascript\nawait stdout.ignoreAsync(async () =\u003e {\n    await functionUnderTestAsync();\n});\n```\n\n\n## Version History\n\n__2.0.0:__ Add events to inspect(). Add inspectAsync(), ignoreAsync(). **BREAKING CHANGE:** Requires Node 7.6.0 or higher (due to async/await support)\n\n__1.1.0:__ Add ability to override stdout.isTTY (and stderr.isTTY).\n\n__1.0.0:__ API fails with nice error messages when called with wrong number of arguments.\n\n__0.7.1:__ Bug fix: Sync() versions restore old behavior even if exception occurs\n\n__0.7.0:__ Initial release: `inspect()`, `inspectSync()`, `ignore()`, and `ignoreSync()`\n\n\n## Contributors\n\nCreated by James Shore. Inspired by Brandon Satrom's [Automated Testing of Standard Output in Node.js](http://userinexperience.com/?p=714).\n\nOption for mocking isTTY added by Jason Boileau.\n\nInspect `data` event added by Tim Toohey.\n\n\n### Release Process\n\n1. Update version history in readme\n2. Ensure clean build: `./jake.sh`\n3. Update npm version: `npm version [major|minor|patch]`\n4. Release to npm: `npm publish`\n5. Release to github: `git push \u0026\u0026 git push --tags`\n\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2014-2015 James Shore\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamesshore%2Ftest-console","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjamesshore%2Ftest-console","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamesshore%2Ftest-console/lists"}