{"id":18370843,"url":"https://github.com/ugate/labrat","last_synced_at":"2025-04-10T21:27:42.042Z","repository":{"id":44029744,"uuid":"227188121","full_name":"ugate/labrat","owner":"ugate","description":"🐁 Run @hapi/lab tests on vanilla test suites","archived":false,"fork":false,"pushed_at":"2023-01-05T06:54:25.000Z","size":1495,"stargazers_count":0,"open_issues_count":11,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-01T15:40:27.766Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ugate.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-12-10T18:22:26.000Z","updated_at":"2020-12-29T13:48:07.000Z","dependencies_parsed_at":"2023-02-03T16:46:26.866Z","dependency_job_id":null,"html_url":"https://github.com/ugate/labrat","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ugate%2Flabrat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ugate%2Flabrat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ugate%2Flabrat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ugate%2Flabrat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ugate","download_url":"https://codeload.github.com/ugate/labrat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248300461,"owners_count":21080735,"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","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":"2024-11-05T23:40:31.174Z","updated_at":"2025-04-10T21:27:42.023Z","avatar_url":"https://github.com/ugate.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🐭 @ugate/labrat\n\n🐁 Run [@hapi/lab](https://github.com/hapijs/lab) tests on vanilla test suites\n\n`npm install -D @ugate/labrat`\n\n**test/lib/tester.js**:\n\n```js\n// vanilla test suite (all tests should be static)\n\nconst { Labrat, LOGGER } = require('@ugate/labrat');\n\nclass Tester {\n\n  static async before() {\n    // OPTIONAL: run before all tests\n  }\n\n  static async after() {\n    // OPTIONAL: run after all tests\n  }\n\n  static async beforeEach() {\n    // OPTIONAL: run before each test\n  }\n\n  static async afterEach() {\n    // OPTIONAL: run after each test\n  }\n\n  static myTest1() {\n    if (LOGGER.info) LOGGER.info('Show this when info level enabled');\n    // test here\n  }\n\n  static async myTest2() {\n    Labrat.header('My Test #2');\n    // test here\n  }\n\n  static async testException() {\n    // do something that throws an error\n    throw new Error('TEST Error');\n  }\n}\n\n// when not ran in a test runner execute static Tester static functions\nif (!Labrat.usingTestRunner()) {\n  (async () =\u003e await Labrat.run(Tester))();\n}\n```\n\n**test/tester.js**:\n\n```js\nconst Lab = require('@hapi/lab');\nconst Tester = require('./lib/tester');\nconst lab = Lab.script();\nexports.lab = lab;\n\nconst plan = `Demo`;\n\nlab.experiment(plan, () =\u003e {\n\n  if (Tester.before) lab.before(Tester.before);\n  if (Tester.after) lab.after(Tester.after);\n  if (Tester.beforeEach) lab.beforeEach(Tester.beforeEach);\n  if (Tester.afterEach) lab.afterEach(Tester.afterEach);\n\n  lab.test(`${plan}: Test #1`, { timeout: 1000 }, Tester.myTest1);\n  lab.test(`${plan}: Test #2`, { timeout: 1000 }, Tester.myTest2);\n  lab.test(`${plan}: Test Error`, { timeout: 1000 },\n    Labrat.expectFailure('onUnhandledRejection', { expect, label: 'throw error' }, Tester.testException)\n  );\n});\n```\n\n#### Log Levels\n\n-   `-NODE_ENV=development` or `-NODE_ENV=dev` - All levels/functions included in _console_\n-   `-NODE_ENV=test` - Includes _console.info_, _console.warn_, _console.error_\n-   `-NODE_ENV=production` or `-NODE_ENV=prod` - Includes _console.warn_, _console.error_\n-   Omit or set to another environment to disable logging\n\n#### Running Tests\n\nTests can be ran in a `Node.js` command or in [@hapi/lab](https://github.com/hapijs/lab).\n\nRun in node:\n\n`node test/lib/tester.js -NODE_ENV=test`\n\nRun _myTest1_ in node:\n\n`node test/lib/tester.js -NODE_ENV=test myTest1`\n\nRun in [@hapi/lab](https://github.com/hapijs/lab):\n\n`\"node_modules/.bin/lab\" test/tester.js -v`\n\nRun _myTest1_ in [@hapi/lab](https://github.com/hapijs/lab):\n\n`\"node_modules/.bin/lab\" test/tester.js -vi 1`\n\nRun _myTest2_ in [@hapi/lab](https://github.com/hapijs/lab):\n\n`\"node_modules/.bin/lab\" test/tester.js -vi 2`\n\n\u003c!-- npx documentation readme index.js --section=API --\u003e\n#### API\n\n\u003c!-- Generated by documentation.js. Update this documentation by updating the source code. --\u003e\n\n###### Table of Contents\n\n-   [header](#header)\n    -   [Parameters](#parameters)\n-   [expectFailure](#expectfailure)\n    -   [Parameters](#parameters-1)\n-   [wait](#wait)\n    -   [Parameters](#parameters-2)\n-   [usingTestRunner](#usingtestrunner)\n\n##### header\n\nLogs a message with header formatting\n\n###### Parameters\n\n-   `msg` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The message to log\n-   `level` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The log level to execute (optional, default `'info'`)\n\n##### expectFailure\n\nConvenience function that will handle expected thrown errors\n\n###### Parameters\n\n-   `type` **([String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \\| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)\u0026lt;[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)\u003e)** The `flags` type/name that will be set on incoming flags (e.g. `onUnhandledRejection`, `onUncaughtException`, etc.)\n-   `opts` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The failure options\n    -   `opts.expect` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** The `@hapi/code` expect function\n    -   `opts.label` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** The label that will be used for `expect`\n    -   `opts.code` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** The `Error.code` that will be expected\n-   `func` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** A _test_ function with a signature of `async function(flags)` that `@hapi/lab` accepts\n\n##### wait\n\nAsync test that will either `resolve`/`reject` after a given amount of time\n\n###### Parameters\n\n-   `delay` **Integer** The delay in milliseconds to wait before resolving/rejecting\n-   `val` **any?** The value to return when resolved or error message/Error when rejecting\n-   `rejectIt` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** `true` to reject, otherwise resolve\n\n##### usingTestRunner\n\nReturns **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** `true` when the process is being ran from a _test utility_\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fugate%2Flabrat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fugate%2Flabrat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fugate%2Flabrat/lists"}