{"id":17743091,"url":"https://github.com/julien-r44/japa-database-plugin","last_synced_at":"2025-04-21T08:32:10.656Z","repository":{"id":59567769,"uuid":"537947249","full_name":"Julien-R44/japa-database-plugin","owner":"Julien-R44","description":"💽 Database assertions and testing helpers for Japa","archived":false,"fork":false,"pushed_at":"2023-06-12T17:59:35.000Z","size":423,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-12T15:59:36.387Z","etag":null,"topics":["database","japa","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/Julien-R44.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","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},"funding":{"github":["julien-r44"],"polar":"Julien-R44"}},"created_at":"2022-09-17T22:44:54.000Z","updated_at":"2025-03-30T09:49:03.000Z","dependencies_parsed_at":"2024-10-26T09:12:22.055Z","dependency_job_id":"341c27cd-b7d3-4ab7-b180-63abc4c1d8f8","html_url":"https://github.com/Julien-R44/japa-database-plugin","commit_stats":{"total_commits":17,"total_committers":1,"mean_commits":17.0,"dds":0.0,"last_synced_commit":"1967b9e7c04efe90a3a4cb432dacbe7f3373d211"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Julien-R44%2Fjapa-database-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Julien-R44%2Fjapa-database-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Julien-R44%2Fjapa-database-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Julien-R44%2Fjapa-database-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Julien-R44","download_url":"https://codeload.github.com/Julien-R44/japa-database-plugin/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250023564,"owners_count":21362423,"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":["database","japa","testing"],"created_at":"2024-10-26T05:42:34.918Z","updated_at":"2025-04-21T08:32:10.379Z","avatar_url":"https://github.com/Julien-R44.png","language":"TypeScript","funding_links":["https://github.com/sponsors/julien-r44","https://polar.sh/Julien-R44"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://user-images.githubusercontent.com/8337858/190878581-43ed9b9d-bf4a-47d2-9af0-b00b2e79027a.png\"\u003e\n\u003c/p\u003e\n\n# @julr/japa-database-plugin\n\nThis plugin for [Japa](http://japa.dev) provides some utility functions to make it easier for you to test a database. Built on top of [knex](https://knexjs.org/).\n\n## Features\n- Support Mysql, Sqlite, PostgreSQL, MSSQL\n- Support expect, and assert\n\n## Installation\n```bash\npnpm install @julr/japa-database-plugin\n```\n\n## Configuration\nThe first step is to register the plugin in your Japa configuration : \n\n```ts\nimport { database } from '@julr/japa-database-plugin'\n\nconfigure({\n  ...processCliArgs(process.argv.slice(2)),\n  ...{\n    plugins: [\n      expect(),\n      database({ \n        database: {\n          client: 'pg',\n          connection: {\n            host: 'localhost',\n            user: 'japa',\n            password: 'password',\n            database: 'japa',\n          }\n        } \n      }),\n    ],\n    // ...\n  },\n})\n```\nYou can find more information about the configuration of your database in the [knex documentation](https://knexjs.org/guide/#configuration-options)\n\n## Usage\n\nThe plugin provides the DatabaseUtils class which you can use for refreshing the database between your tests :\n\n```ts\nimport { DatabaseUtils } from '@julr/japa-database-plugin'\n\ntest.group('My tests', group =\u003e {\n  group.each.teardown(async () =\u003e DatabaseUtils.refreshDatabase())\n\n  // ...\n})\n```\n\nThis will truncate all tables in your database.\n\n### Assertions\n\nYou can access the main object from the test context as follows :\n\n```ts\ntest.group('My tests', group =\u003e {\n  test('My test', async ({ database }) =\u003e {\n    await database.assertHas('users', { email: 'jul@japa.com' })\n  })\n})\n```\n\nThe plugin proposes the following assertions: \n\n```ts\ntest('My test', async ({ database }) =\u003e {\n  // Assert that an user with jul@japa.com in DB\n  await database.assertHas('users', { email: 'jul@japa.com' })\n\n  // Assert that we have 5 users with bonjour@ok.com in DB\n  await database.assertHas('users', { email: 'bonjour@ok.com' }, 5)\n\n  // Assert that the db does not have the given row\n  await database.assertMissing('users', { email: 'shouldNotBe@inDatabase.com'})\n\n  // Assert that the db 5 users rows\n  await database.assertHasCount('users', 5)\n})\n```\n\n## License\n\n[MIT](./LICENSE.md) License © 2022 [Julien Ripouteau](https://github.com/Julien-R44)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjulien-r44%2Fjapa-database-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjulien-r44%2Fjapa-database-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjulien-r44%2Fjapa-database-plugin/lists"}