{"id":28386392,"url":"https://github.com/nifty-lil-tricks/testing","last_synced_at":"2025-06-26T13:31:24.993Z","repository":{"id":182792326,"uuid":"658004339","full_name":"nifty-lil-tricks/testing","owner":"nifty-lil-tricks","description":"A selection of useful utilities (or nifty li'l tricks!) for all things testing","archived":false,"fork":false,"pushed_at":"2024-09-03T22:31:28.000Z","size":266,"stargazers_count":3,"open_issues_count":4,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-08T16:02:08.843Z","etag":null,"topics":["deno","nodejs","testing"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/nifty-lil-tricks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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,"zenodo":null}},"created_at":"2023-06-24T13:19:52.000Z","updated_at":"2024-03-22T11:58:34.000Z","dependencies_parsed_at":"2023-09-27T02:55:51.131Z","dependency_job_id":"b22c3772-a0d6-4e58-9e4d-062e9af549de","html_url":"https://github.com/nifty-lil-tricks/testing","commit_stats":null,"previous_names":["jonnydgreen/nifty-lil-tricks-testing","nifty-lil-tricks/testing"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/nifty-lil-tricks/testing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nifty-lil-tricks%2Ftesting","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nifty-lil-tricks%2Ftesting/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nifty-lil-tricks%2Ftesting/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nifty-lil-tricks%2Ftesting/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nifty-lil-tricks","download_url":"https://codeload.github.com/nifty-lil-tricks/testing/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nifty-lil-tricks%2Ftesting/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262076506,"owners_count":23255024,"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":["deno","nodejs","testing"],"created_at":"2025-05-30T14:42:23.421Z","updated_at":"2025-06-26T13:31:24.985Z","avatar_url":"https://github.com/nifty-lil-tricks.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Nifty li'l tricks Logo](https://raw.githubusercontent.com/nifty-lil-tricks/assets/main/nifty-lil-tricks-logo.png)\n\n# nifty_lil_tricks_testing\n\n**Note: this package and selected plugins are currently a work in progress**\n\n[![Latest Version](https://img.shields.io/npm/v/@nifty-lil-tricks/testing?style=flat-square)](https://www.npmjs.com/package/@nifty-lil-tricks/testing)\n[![GitHub License](https://img.shields.io/github/license/nifty-lil-tricks/testing?style=flat-square)](https://raw.githubusercontent.com/nifty-lil-tricks/testing/main/LICENSE)\n[![Buy us a tree](https://img.shields.io/badge/Treeware-%F0%9F%8C%B3-lightgreen)](https://plant.treeware.earth/nifty-lil-tricks/testing)\n[![codecov](https://codecov.io/gh/nifty-lil-tricks/testing/branch/main/graph/badge.svg)](https://codecov.io/gh/nifty-lil-tricks/testing)\n\nA selection of useful utilities (or nifty li'l tricks!) for all things testing.\n\n## Installation\n\n**Note: this package works with TypeScript v5 or later**\n\n### Deno\n\n```typescript\nimport * as testing from \"https://deno.land/x/nifty_lil_tricks_testing/mod.ts\";\n```\n\n### Node.js\n\n```shell\nnpm install @nifty-lil-tricks/testing\n```\n\n### TypeScript\n\nThe TypeScript `tsconfig.json` must contain the following recommended settings:\n\n```jsonc\n{\n  \"compilerOptions\": {\n    \"target\": \"ES2022\",\n    \"strict\": true\n  }\n}\n```\n\nNote, check the plugin READMEs for any additional TypeScript settings.\n\n## Features\n\nThe following features are supported\n\n- An extensible setup tests factory that allows one to declaratively setup a\n  test suite for testing with loaded plugins through a simple to use interface.\n- Teardown functionality for restoring the state of the environment after tests\n  have run.\n- Ready-made plugins to get started with straight-away.\n\n### Plugins\n\nThe following plugins are available to that make use of the setup tests plugin\nsystem.\n\n| Plugin                                                                                           | Description                                                                                                                                                                                                                                                                                                                                                                                 | Status | Npm                                                                                                                                                                                        | Docs                                                                                       |\n| ------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ |\n| [PostgreSQl](https://github.com/nifty-lil-tricks/testing/blob/main/plugin_postgresql/README.md)  | Setup the World's Most Advanced Open Source Relational Database for testing. It has the following features: \u003cbr\u003e\u003cul\u003e\u003cli\u003eSetup a Postgresql server in [Docker](https://www.docker.com/) for testing.\u003c/li\u003e\u003cli\u003eSetup an existing Postgresql server for testing.\u003c/li\u003e\u003cli\u003eRun migrations on the configured Postgresql server.\u003c/li\u003e\u003cli\u003eSeed the configured Postgresql server with data.\u003c/li\u003e\u003c/ul\u003e | ✅     | [![Latest Version](https://img.shields.io/npm/v/@nifty-lil-tricks/testing-plugin-postgresql?style=flat-square)](https://www.npmjs.com/package/@nifty-lil-tricks/testing-plugin-postgresql) | [Docs](https://github.com/nifty-lil-tricks/testing/blob/main/plugin_postgresql/README.md). |\n| [NestJS Server](https://github.com/nifty-lil-tricks/testing/blob/main/plugin_nestjs/README.md)   | Setup a progressive Node.js framework for building efficient, reliable and scalable server-side applications for testing.                                                                                                                                                                                                                                                                   | ✅     | [![Latest Version](https://img.shields.io/npm/v/@nifty-lil-tricks/testing-plugin-nestjs?style=flat-square)](https://www.npmjs.com/package/@nifty-lil-tricks/testing-plugin-nestjs)         | [Docs](https://github.com/nifty-lil-tricks/testing/blob/main/plugin_nestjs/README.md)      |\n| [Express Server](https://github.com/nifty-lil-tricks/testing/blob/main/plugin_express/README.md) | Setup a minimal and flexible Node.js web Express application for testing.                                                                                                                                                                                                                                                                                                                   | 🚧     | [![Latest Version](https://img.shields.io/npm/v/@nifty-lil-tricks/testing-plugin-express?style=flat-square)](https://www.npmjs.com/package/@nifty-lil-tricks/testing-plugin-express)       | [Docs](https://github.com/nifty-lil-tricks/testing/blob/main/plugin_express/README.md)     |\n\n### Setup tests\n\n- [Quick start](#quick-start)\n- [Setup tests overview](#setup-tests-overview)\n\n#### Quick start\n\n```typescript\nimport {\n  afterEach,\n  beforeEach,\n  describe,\n  it,\n} from \"https://deno.land/std/testing/bdd.ts\";\nimport { assertEquals } from \"https://deno.land/std/testing/asserts.ts\";\nimport {\n  setupTestsFactory,\n  type SetupTestsTeardown,\n} from \"https://deno.land/x/nifty_lil_tricks_testing/mod.ts\";\n\n// Define or import a plugin as follows:\nconst helloWorldPlugin = {\n  setup: (config: { message: string }) =\u003e {\n    // Setup plugin according to config\n    return {\n      output: config,\n      teardown: () =\u003e {},\n    };\n  },\n};\n\n// In another file, load plugins as follows to generate a setupTests function:\nexport const { setupTests } = setupTestsFactory({\n  helloWorld: helloWorldPlugin,\n});\n\n// Then one can use this in any test file as follows:\ndescribe(\"Service\", () =\u003e {\n  let teardownTests: SetupTestsTeardown;\n  let message: string;\n\n  beforeEach(async () =\u003e {\n    // Setup tests with configured plugins\n    const result = await setupTests({\n      helloWorld: { message: \"Hello, world!\" },\n    });\n    message = result.outputs.helloWorld.output.message;\n    teardownTests = result.teardownTests;\n  });\n\n  afterEach(async () =\u003e {\n    // Teardown tests to restore environment after tests have run\n    await teardownTests();\n  });\n\n  describe(\"method\", () =\u003e {\n    it(\"should test something that relies on the plugin being configured\", () =\u003e {\n      // Some other testing\n      assertEquals(message, \"Hello, world!\");\n    });\n  });\n});\n```\n\n#### Setup tests overview\n\n##### `setupTestsFactory`\n\nOne can use the `setupTestsFactory` to register or load defined plugins. It is\nonly needed to load these once so it is recommended to share the returned\n`setupTests` function across all test files.\n\nEach plugin must be given a name that is not one of the reserved plugin names.\nThis returns a function that when run, sets up the tests to use the loaded\nplugins according to the provided config.\n\nEach plugin must contain the following functions in order to be correctly\nloaded:\n\n- `setup`\n- `teardown`\n\nAn example of a plugin is as follows:\n\n```typescript\nimport {\n  type Plugin,\n} from \"https://deno.land/x/nifty_lil_tricks_testing/mod.ts\";\n\ninterface HelloWorldConfig {\n  message: string;\n}\n\ntype HelloWorldResult = string;\n\nconst helloWorldPlugin: Plugin\u003cHelloWorldConfig, HelloWorldResult\u003e = {\n  setup(config: HelloWorldConfig) {\n    // Setup plugin according to config\n    return {\n      output: config.message,\n      teardown() {\n        // Teardown any setup resources\n      },\n    };\n  },\n};\n```\n\n##### `setupTests`\n\nOne can use the returned `setupTests` function use the loaded plugins.\n\nThe loaded plugins available to the setupTests function returned from the\nfactory can be configured using config namespaced to the name of the plugin.\n\nFor example, if the plugin is named `helloWorld`, then the config for that\nplugin must be provided under the `helloWorld` namespace.\n\nWhen run, setupTests will return an object with the data returned from the\nplugin invocation. The data will be namespaced to the plugin name. For example:\n\n```typescript\nimport {\n  setupTestsFactory,\n  type SetupTestsTeardown,\n} from \"https://deno.land/x/nifty_lil_tricks_testing/mod.ts\";\n\n// Define or import a plugin as follows:\nconst helloWorldPlugin = {\n  setup: (config: { message: string }) =\u003e {\n    // Setup plugin according to config\n    return {\n      output: config.message,\n      teardown: () =\u003e {\n        // Teardown any setup resources\n      },\n    };\n  },\n};\n\n// In another file, load plugins as follows to generate a setupTests function:\nexport const { setupTests } = setupTestsFactory({\n  helloWorld: helloWorldPlugin,\n});\n\nconst result = await setupTests({\n  helloWorld: { message: \"Hello, world!\" },\n});\n\nresult.outputs.helloWorld.output; // \"Hello, world!\"\n```\n\nOnly plugins that are configured will be run. If a plugin is not configured,\nthen it will not be run. The order of the plugins in the config is defined the\norder in which they defined in the config object. This follows the rules as\ndefined\n[here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in#description).\n\nThe returned object will also contain a `teardown` function that when run, will\nteardown the plugins in the reverse order that they were setup.\n\n##### `teardownTests`\n\nOne can use the returned `teardownTests` function to restore the environment to\nits original state after the tests have run.\n\nFor example:\n\n```typescript\nimport {\n  setupTestsFactory,\n  type SetupTestsTeardown,\n} from \"https://deno.land/x/nifty_lil_tricks_testing/mod.ts\";\n\n// Define or import a plugin as follows:\nconst helloWorldPlugin = {\n  setup: (config: { message: string }) =\u003e {\n    // Setup plugin according to config\n    return {\n      output: config.message,\n      teardown: () =\u003e {\n        // Teardown any setup resources\n      },\n    };\n  },\n};\n\n// In another file, load plugins as follows to generate a setupTests function:\nexport const { setupTests } = setupTestsFactory({\n  helloWorld: helloWorldPlugin,\n});\n\nconst result = await setupTests({\n  helloWorld: { message: \"Hello, world!\" },\n});\n\n// Teardown tests to restore environment after tests have run\nawait result.teardownTests();\n```\n\n### API\n\nThe API Docs can be found [here](https://deno.land/x/nifty_lil_tricks_testing).\n\n## Examples\n\nExamples can be found\n[here](https://github.com/nifty-lil-tricks/testing/blob/main/examples/).\n\n## Support\n\n| Platform Version | Supported          | Notes                      |\n| ---------------- | ------------------ | -------------------------- |\n| Deno `v1`        | :white_check_mark: |                            |\n| Node.JS `v18`    | :white_check_mark: | TypeScript v5+ for typings |\n| Node.JS `v20`    | :white_check_mark: | TypeScript v5+ for typings |\n| Web Browsers     | :x:                | Coming soon                |\n\n## Useful links\n\n- For help or feedback on this project, join us in\n  [GitHub Discussions](https://github.com/nifty-lil-tricks/testing/discussions)\n\n## License\n\nNifty li'l tricks packages are 100% free and open-source, under the\n[MIT license](https://github.com/nifty-lil-tricks/testing/blob/main/LICENSE).\n\nThis package is [Treeware](https://treeware.earth). If you use it in production,\nthen we ask that you\n[**buy the world a tree**](https://plant.treeware.earth/nifty-lil-tricks/testing)\nto thank us for our work. By contributing to the Treeware forest you’ll be\ncreating employment for local families and restoring wildlife habitats.\n\n## Contributions\n\n[Contributions](https://github.com/nifty-lil-tricks/testing/blob/main/CONTRIBUTING.md),\nissues and feature requests are very welcome. If you are using this package and\nfixed a bug for yourself, please consider submitting a PR!\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/nifty-lil-tricks/testing/graphs/contributors\"\u003e\n    \u003cimg src=\"https://contrib.rocks/image?repo=nifty-lil-tricks/testing\u0026columns=8\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnifty-lil-tricks%2Ftesting","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnifty-lil-tricks%2Ftesting","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnifty-lil-tricks%2Ftesting/lists"}