=============== LIBRARY RULES =============== From library maintainers: - Install Poku as a dev dependency. On Node.js run `npm i -D poku`, and for TypeScript on Node.js run `npm i -D poku tsx`. - On Bun run `bun add -d poku`. On Deno the install is optional with `deno add npm:poku`. Bun and Deno support TypeScript natively. - To organize related tests, prefer grouping them with `describe` plus `it` or `test`. A title is optional, for example: `describe('Sum', () => {})` and `describe(() => {})` are both valid, and the same applies to `it` and `test`. - Synchronous tests do not need `await`. For asynchronous tests use an `async` callback and `await` the `it` or `test` call so the group waits for it to finish. - When top-level `await` is not available, for example in CommonJS, you can put the test groups inside an asynchronous `describe` without awaiting it, like `describe(async () => { await it(async () => {}) })`. - You can nest `describe` inside `describe`, for example: `describe(() => { describe(() => {}) })`, `await describe(async () => { await describe(async () => {}) })` or `describe(async () => { await describe(() => {}) })`. - Avoid nesting `it` or `test` inside another `it` or `test`. Prefer `describe` for nesting, and keep `it` and `test` as the innermost test cases (when defined, `beforeEach`/`afterEach` run around each `it`/`test`). - `assert` and `strict` keep the familiar Node.js assert API. Every method accepts an optional message as the last argument. - When an assertion message is defined, write the message as the assertion's description, not a failure note, for example: `assert.strictEqual(res.status, 200, 'Server is on')`, `assert.strictEqual(res.status, 200, 'Server should be on')`, etc. - Never open or close a service, process, or resource in the same scope as an assertion that may fail. If it throws, the cleanup never runs and the process hangs. Do both in an outer `describe` scope, keeping assertions in their own `it`. - Run the tests with `npx poku` on Node.js, `bun --bun poku` on Bun, and `deno run npm:poku` on Deno. - Prefer defining a script in `package.json` for Node.js and Bun (for example, `npm test` or `bun run test`), or a task in `deno.json` for Deno (for example `deno task test`), instead of typing the full command. - Avoid the advanced programmatic Poku API (`poku()`, `noExit`, `exit()`) unless the user explicitly asks for it. Prefer the CLI, a `package.json` script, a `poku.config.js`, a `.pokurc.json` or a `.pokurc.jsonc` instead. - To run the same suite on every runtime, define one script each, for example: `"test:node": "poku"`, `"test:bun": "bun --bun poku"`, `"test:deno": "deno run npm:poku"`. - Run coverage with the `--coverage` flag. It needs one coverage plugin installed as a dev dependency, for example: `@pokujs/c8`, `@pokujs/monocart`, `@pokujs/one-double-zero`, `@pokujs/istanbul`, `@pokujs/coverage`. - Select a reporter with `--reporter=` (short `-r`). The default is `poku` and `compact` shows only file paths with PASS or FAIL. The other reporters are `dot`, `focus`, and `classic`. - To see the available CLI options quickly, run `poku -h` (or `--help`). - You can configure Poku with a config file. By default it auto-detects, in priority order, `poku.config.js`, `.pokurc.json`, and `.pokurc.jsonc` in the project root. CLI flags override the file. - To use a custom config name or extension, pass `--config=` (short `-c`), for example `--config=poku.config.ts`. It accepts `.js`, `.cjs`, `.mjs`, `.ts`, `.cts`, `.mts`, `.json`, and `.jsonc`. - To run only tests whose title matches a pattern, you can use `--testNamePattern=` (short `-t`), for example: `poku -t='Auth:' ./test`. - Poku omits any non-Poku output by default. To show all logs, you can use `--debug` (short `-d`), or force a specific output with the `log()` helper from `poku`. - Never include any comment of any kind in code examples: not `//`, `/* */`, `/** */`, or any other form. Put all explanations in the answer prose. Use `describe`, `it`, `test`, and `assert` message arguments to convey intent. ### Setup Hook Example Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/creating-plugins.mdx Demonstrates the `setup` hook within `definePlugin` to perform initialization tasks like logging runtime information. ```typescript export const myPlugin = definePlugin({ name: 'my-setup', async setup({ configs, runtime, cwd }) { console.log(`Running on ${runtime} from ${cwd}`); // start a server, seed a database, etc. }, }); ``` -------------------------------- ### Start Server using package.json script (Bun) Source: https://github.com/wellwelwel/poku/blob/main/website/docs/examples/local-server.mdx Defines a 'start' script in package.json for Bun. This enables starting the server with `bun run start` or similar commands. ```json { "script": { "start": "bun server.js" } } ``` -------------------------------- ### Start Server using package.json script (Node.js) Source: https://github.com/wellwelwel/poku/blob/main/website/docs/examples/local-server.mdx Configures a 'start' script in package.json to run a Node.js server. This allows the server to be started using `npm start` or `yarn start`. ```json { "script": { "start": "node server.js" } } ``` -------------------------------- ### Start Server using deno.json task (Deno) Source: https://github.com/wellwelwel/poku/blob/main/website/docs/examples/local-server.mdx Sets up a 'start' task in deno.json for Deno projects. This allows the server to be executed using `deno task start`. ```json { "tasks": { "start": "deno run --allow-net server.js" } } ``` -------------------------------- ### Install Prisma Client Source: https://github.com/wellwelwel/poku/blob/main/website/docs/examples/database/prisma.mdx Install the Prisma client package for your project. ```bash npm i @prisma/client ``` -------------------------------- ### Install Dependencies Source: https://github.com/wellwelwel/poku/blob/main/website/docs/examples/database/typeorm.mdx Install TypeORM, its PostgreSQL driver, and reflect-metadata for decorators. Also install Poku and the Docker plugin for testing. ```bash npm i typeorm pg reflect-metadata ``` ```bash npm i -D poku tsx @pokujs/docker ``` -------------------------------- ### Example .env File Content Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/helpers/env.mdx This is an example of how to structure your .env file with key-value pairs. ```dotenv HOST='localhost' PORT='8080' ``` -------------------------------- ### Define a Basic Plugin with Setup and Teardown Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/creating-plugins.mdx Use `definePlugin` to create a plugin with `setup` and `teardown` hooks. The `setup` hook runs before the test suite, and `teardown` runs after. ```typescript import { definePlugin } from 'poku/plugins'; export const myPlugin = definePlugin({ name: 'my-plugin', async setup({ runtime, cwd }) { // runs before the test suite }, async teardown() { // runs after the test suite }, }); ``` -------------------------------- ### Install @pokujs/react Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/official/react.mdx Install the React plugin and its dependencies using npm. ```bash npm i -D @pokujs/react ``` -------------------------------- ### Install pg Driver Source: https://github.com/wellwelwel/poku/blob/main/website/docs/examples/database/pg.mdx Install the PostgreSQL driver for Node.js. ```bash npm i pg ``` -------------------------------- ### Install Dependencies Source: https://github.com/wellwelwel/poku/blob/main/website/docs/examples/database/knex.mdx Install Knex and the PostgreSQL driver for application use, and Poku, tsx, and the Docker plugin for testing. ```bash npm i knex pg ``` ```bash npm i -D poku tsx @pokujs/docker @types/pg ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/wellwelwel/poku/blob/main/website/docs/examples/database/prisma.mdx Install Poku, TypeScript, and the Poku Docker plugin for development and testing. ```bash npm i -D poku tsx @pokujs/docker prisma ``` -------------------------------- ### Vue Single File Component Example Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/official/vue.mdx A basic Vue 3 component using ``` -------------------------------- ### Install Poku and Docker Plugin Source: https://github.com/wellwelwel/poku/blob/main/website/docs/examples/database/drizzle.mdx Install Poku, its TypeScript runner, the Docker plugin, and PostgreSQL types. ```bash npm i -D poku tsx @pokujs/docker @types/pg ``` -------------------------------- ### Install @pokujs/docker Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/official/containers.mdx Install the @pokujs/docker package as a development dependency. ```sh npm i -D @pokujs/docker ``` -------------------------------- ### Install cassandra-driver Source: https://github.com/wellwelwel/poku/blob/main/website/docs/examples/database/scylladb.mdx Install the official Cassandra driver for Node.js. This is required to interact with ScyllaDB. ```bash npm i cassandra-driver ``` -------------------------------- ### Install lsof on Debian/Ubuntu Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/helpers/processes/kill.mdx Install the 'lsof' utility using apt-get on Debian or Ubuntu systems. ```bash sudo apt-get install lsof ``` -------------------------------- ### Install Dependencies Source: https://github.com/wellwelwel/poku/blob/main/website/docs/examples/database/sequelize.mdx Install the necessary packages for Sequelize and PostgreSQL, along with Poku and its Docker plugin. ```bash npm i sequelize pg pg-hstore ``` ```bash npm i -D poku tsx @pokujs/docker ``` -------------------------------- ### Integration Test Setup with Docker and Database Wait Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/helpers/processes/wait-for-expected-result.mdx Configures Poku to run integration tests, starting Docker containers and waiting for the database to be ready before tests begin. The database connection is checked using waitForExpectedResult. ```javascript import { defineConfig, waitForExpectedResult } from 'poku'; import { docker } from '@pokujs/docker'; import { db } from './db.js'; const compose = docker.compose(); export default defineConfig({ include: './test/integration', plugins: [ { setup: async () => { await compose.up(); await waitForExpectedResult(async () => { try { await db.connect(); return true; } catch {} }, true); }, teardown: () => compose.down(), }, ], }); ``` ```bash npx poku ``` -------------------------------- ### Install Poku with npm Source: https://github.com/wellwelwel/poku/blob/main/README.md Install Poku as a development dependency for Node.js projects. ```bash npm i -D poku ``` -------------------------------- ### Install Poku Source: https://github.com/wellwelwel/poku/blob/main/website/llms/llms.md Install Poku using npm for Node.js, Bun for Bun, or deno add for Deno. TypeScript support may require additional packages like tsx. ```bash # Node.js npm i -D poku # Node.js with TypeScript npm i -D poku tsx # Bun (TypeScript supported natively) bun add -d poku # Deno (TypeScript supported natively, installation is optional) deno add npm:poku ``` -------------------------------- ### Install Poku and Docker Plugin Source: https://github.com/wellwelwel/poku/blob/main/website/docs/examples/database/mongodb.mdx Install Poku and the necessary Docker plugin for container management as development dependencies. ```bash npm i -D poku tsx @pokujs/docker ``` -------------------------------- ### Traditional Test Runner Setup and Teardown Source: https://github.com/wellwelwel/poku/blob/main/website/llms/philosophy.md Illustrates how traditional test runners use dedicated hooks like `beforeAll` and `afterAll` for setup and teardown, and how they schedule `it` blocks. ```javascript describe('My Test', () => { // Setup goes in a dedicated hook that runs before the tests beforeAll(() => { console.log('Started'); }); // Teardown is declared here, before the tests even begin, yet runs after them afterAll(() => { console.log('Done'); }); // The runner schedules these it(async () => { await stepOne(); }); // Although asynchronous they run sequentially even without await it(async () => { await stepTwo(); }); }); ``` -------------------------------- ### Install Multi Suite Plugin Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/official/multi-suite.mdx Install the Multi Suite plugin using npm or yarn. ```sh npm i -D @pokujs/multi-suite ``` -------------------------------- ### Create a Deno Server Source: https://github.com/wellwelwel/poku/blob/main/website/docs/examples/local-server.mdx Sets up a server using Deno's built-in serve function. It listens on port 4000, responds with JSON, and logs a 'ready' message when the server starts listening. ```typescript Deno.serve({ port: 4000, handler: () => new Response(JSON.stringify({ name: 'Poku' }), { headers: { 'Content-Type': 'application/json' }, }), onListen: () => console.log('ready'), }); ``` -------------------------------- ### Configure Custom DOM Setup Module Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/official/vue.mdx Provide a path to a custom module for setting up the DOM environment. ```javascript vueTestingPlugin({ dom: { setupModule: './tests/setup/custom.ts' }, }); ``` -------------------------------- ### Install Poku Vue Plugin Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/official/vue.mdx Install the @pokujs/vue package as a development dependency. ```bash npm i -D @pokujs/vue ``` -------------------------------- ### Install MongoDB Driver Source: https://github.com/wellwelwel/poku/blob/main/website/docs/examples/database/mongodb.mdx Install the official MongoDB Node.js driver using npm. ```bash npm i mongodb ``` -------------------------------- ### Install happy-dom Adapter Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/official/vue.mdx Install happy-dom and its global registrator as development dependencies for the recommended DOM environment. ```bash # happy-dom (recommended) npm i -D happy-dom \ @happy-dom/global-registrator ``` -------------------------------- ### Install Poku with Bun Source: https://github.com/wellwelwel/poku/blob/main/README.md Add Poku as a development dependency for Bun projects. ```bash bun add -d poku ``` -------------------------------- ### Install lsof on Alpine Linux Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/helpers/processes/kill.mdx Install the 'lsof' utility using apk on Alpine Linux and similar minimal distributions. ```bash apk add lsof ``` -------------------------------- ### Install Poku Canary with Bun Source: https://github.com/wellwelwel/poku/blob/main/website/docs/index.mdx Install the canary version of Poku using Bun. This allows you to use the latest pre-release features. ```bash bun add -d poku@canary ``` -------------------------------- ### Custom DOM Setup Module Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/official/vue.mdx Provide a custom setup module path in `vueTestingPlugin` for full control over DOM initialization and global API configuration. ```javascript // poku.config.js vueTestingPlugin({ dom: { setupModule: './tests/setup/custom.ts' }, }); ``` -------------------------------- ### Install lsof on Debian/Ubuntu Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/helpers/processes/get-pids.mdx Installs the 'lsof' utility using apt-get, which is required for getPIDs on Debian/Ubuntu systems if not already present. ```shell sudo apt-get install lsof ``` -------------------------------- ### Install lsof on Arch Linux Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/helpers/processes/kill.mdx Install the 'lsof' utility using pacman on Arch Linux and similar distributions. ```bash sudo pacman -S lsof ``` -------------------------------- ### Install happy-dom Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/official/react.mdx Install happy-dom and its global registrator as development dependencies for the recommended DOM adapter. ```bash # happy-dom (recommended) npm i -D happy-dom \ @happy-dom/global-registrator ``` -------------------------------- ### Install mysql2 Driver Source: https://github.com/wellwelwel/poku/blob/main/website/docs/examples/database/mysql2.mdx Install the mysql2 package for Node.js to interact with MySQL databases. ```bash npm i mysql2 ``` -------------------------------- ### Install Drizzle ORM and PostgreSQL Driver Source: https://github.com/wellwelwel/poku/blob/main/website/docs/examples/database/drizzle.mdx Install the necessary packages for Drizzle ORM and the PostgreSQL driver. ```bash npm i drizzle-orm pg ``` -------------------------------- ### Install Poku with Deno Source: https://github.com/wellwelwel/poku/blob/main/README.md Add Poku as a development dependency for Deno projects using npm. ```bash deno add npm:poku ``` -------------------------------- ### Install Shared Resources Plugin Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/official/shared-resources.mdx Install the Shared Resources plugin using npm. This command should be run in your project's development environment. ```sh npm i -D @pokujs/shared-resources ``` -------------------------------- ### Install lsof on macOS Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/helpers/processes/kill.mdx Install the 'lsof' utility using Homebrew on macOS if it's not already present. ```bash brew install lsof ``` -------------------------------- ### Install Poku Canary with npm Source: https://github.com/wellwelwel/poku/blob/main/website/docs/index.mdx Install the latest canary (pre-release) version of Poku using npm. This is useful for testing upcoming features. ```bash npm i -D poku@canary ``` -------------------------------- ### Install Poku Canary and tsx with npm for TypeScript Source: https://github.com/wellwelwel/poku/blob/main/website/docs/index.mdx Install the canary version of Poku along with tsx for TypeScript development in Node.js. ```bash npm i -D poku@canary tsx ``` -------------------------------- ### Install @pokujs/one-double-zero Plugin Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/official/coverage/index.mdx Install the one-double-zero plugin as a dev dependency. This plugin supports various configuration file formats. ```bash npm i -D @pokujs/one-double-zero ``` -------------------------------- ### Example test file structure Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/poku/options/testSkipPattern.mdx This is an example of a test file with several test cases, demonstrating different test titles that can be targeted by `testSkipPattern`. ```typescript import { test, assert } from 'poku'; test('Auth: login with valid credentials', () => { assert(true); }); test('Auth: reject invalid token', () => { assert(true); }); test('Users: list all users', () => { assert(true); }); ``` -------------------------------- ### Install @pokujs/istanbul Plugin Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/official/coverage/index.mdx Install the istanbul plugin as a dev dependency. This plugin supports various configuration file formats. ```bash npm i -D @pokujs/istanbul ``` -------------------------------- ### Install Poku with npm for TypeScript Source: https://github.com/wellwelwel/poku/blob/main/README.md Install Poku and tsx as development dependencies for TypeScript projects in Node.js. ```bash npm i -D poku tsx ``` -------------------------------- ### Custom File Discovery Example Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/creating-plugins.mdx Shows how to use the `discoverFiles` hook to intercept and return custom file paths for test discovery. ```typescript export const myPlugin = definePlugin({ name: 'my-discovery', discoverFiles(paths, context) { // Return custom file paths return ['test/unit/a.test.ts', 'test/unit/b.test.ts']; }, }); ``` -------------------------------- ### Configure Custom DOM Setup Module Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/official/react.mdx Provide a path to a custom module for setting up the DOM environment when using the reactTestingPlugin. ```javascript reactTestingPlugin({ dom: { setupModule: './tests/setup/custom.ts' }, }); ``` -------------------------------- ### Install @pokujs/c8 Plugin Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/official/coverage/index.mdx Install the c8 plugin as a dev dependency. This plugin supports various configuration file formats. ```bash npm i -D @pokujs/c8 ``` -------------------------------- ### Configure beforeEach and afterEach in poku.config.js Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/helpers/before-after-each/per-file.mdx Use `beforeEach` to run a setup function before each test file and `afterEach` to run a teardown function after each test file. The `prepareService` function resolves successfully, while `resetService` rejects to simulate a failure. ```typescript import { defineConfig } from 'poku'; const prepareService = () => new Promise((resolve) => resolve(undefined)); const resetService = () => new Promise((_, reject) => reject('Let\'s crash it')); export default defineConfig({ include: 'test/unit', beforeEach: prepareService, afterEach: resetService, }); ``` ```bash npx poku ``` -------------------------------- ### Install lsof on Arch Linux Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/helpers/processes/get-pids.mdx Installs the 'lsof' utility using pacman, which is required for getPIDs on Arch Linux systems if not already present. ```shell sudo pacman -S lsof ``` -------------------------------- ### Custom DOM setup for React plugin Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/official/react.mdx Provides a module path for custom DOM setup, allowing configuration of global variables and browser APIs. Use this for advanced DOM environment control. ```javascript // poku.config.js reactTestingPlugin({ dom: { setupModule: './tests/setup/custom.ts' }, }); ``` -------------------------------- ### Install lsof on macOS Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/helpers/processes/get-pids.mdx Installs the 'lsof' utility using Homebrew, which is required for getPIDs on Unix-like systems if not already present. ```shell brew install lsof ``` -------------------------------- ### Install lsof on Alpine Linux Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/helpers/processes/get-pids.mdx Installs the 'lsof' utility using apk, which is required for getPIDs on Alpine Linux systems if not already present. ```shell apk add lsof ``` -------------------------------- ### Skip File Discovery Example Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/creating-plugins.mdx Demonstrates using the `discoverFiles` hook to completely skip file discovery by returning an empty array. ```typescript export const skipDiscovery = definePlugin({ name: 'skip-discovery', discoverFiles() { // Return empty array to skip file discovery entirely return []; }, }); ``` -------------------------------- ### List files programmatically with TypeScript Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/helpers/list-files.mdx Import and use the `listFiles` helper function to get all files in a directory. For TypeScript projects, ensure you have `@types/node` installed. ```ts import { listFiles } from 'poku'; await listFiles('some-dir'); ``` -------------------------------- ### Start and End a Service Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/helpers/startService.mdx Starts a service from a given file path and waits for a specific console output ('ready') before proceeding. It also sets a custom timeout for the service. The service is then explicitly ended. ```typescript import { startService } from 'poku'; const server = await startService('server.js', { /** * Wait for the "ready" console output */ startAfter: 'ready', /** * By default, the `timeout` is `60000` (1 minute) for neither success nor failure */ timeout: 60000, }); await server.end(); ``` -------------------------------- ### Define a Poku Timing Plugin Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/creating-plugins.mdx This plugin logs the start and end times of the test suite and each individual test file. It uses the `definePlugin` function and hooks into `setup`, `onTestProcess`, and `teardown`. ```typescript import { definePlugin } from 'poku/plugins'; export const timingPlugin = definePlugin({ name: 'timing', async setup({ runtime }) { console.log(`\n[timing] Suite starting on ${runtime}`); }, onTestProcess(child, file) { const start = Date.now(); child.on('close', () => { console.log(`[timing] ${file}: ${Date.now() - start}ms`); }); }, async teardown() { console.log('[timing] Suite complete\n'); }, }); ``` -------------------------------- ### Build and Manage Dockerfile Containers Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/official/containers.mdx Utilize the docker.dockerfile() helper to build images from Dockerfiles and manage their lifecycle. Use build() to create the image, start() to run the container, and remove() to clean up both. ```ts import { docker } from '@pokujs/docker'; const dockerfile = docker.dockerfile({ containerName: 'container-name', tagName: 'image-name', }); // Builds the image from the Dockerfile await dockerfile.build(); // Starts the container await dockerfile.start(); /** * Tests come here ๐Ÿงช */ // Stops and removes both the container and image await dockerfile.remove(); ``` -------------------------------- ### Accessing and Mutating Shared State in Tests Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/official/shared-resources.mdx Demonstrates how to use a shared resource (CounterContext) to get its current state and mutate it within a test. This example highlights automatic state synchronization across tests. ```typescript test('shared state across tests', async () => { const counter = await resource.use(CounterContext); // This gets the current state from the resource const value = await counter.getCount(); assert.equal(value, 1); // reflects changes from other test // This mutates the shared state await counter.increment(); }); ``` -------------------------------- ### Run Tests in Docker Compose Service Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/official/containers.mdx This example demonstrates setting up tests to run within a specific service defined in a docker-compose.yml file. It involves customized images from a Dockerfile, returning output, and cleaning up containers and images after the tests. ```typescript import { defineConfig } from 'poku'; import { docker } from '@pokujs/docker'; const compose = docker.compose({ cwd: './test/docker' }); export default defineConfig({ include: './test/integration', plugins: [ { setup: () => compose.up(), teardown: () => compose.down(), }, ], }); ``` -------------------------------- ### Run Poku with failFast CLI Option Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/poku/options/fail-fast.mdx Use the `--failFast` flag with the Poku CLI to stop tests on the first failure. Ensure you have Poku installed globally or use npx. ```bash npx poku --failFast ./test ``` -------------------------------- ### Test Scripted Server with Poku Source: https://github.com/wellwelwel/poku/blob/main/website/docs/examples/local-server.mdx Tests a server started via a script (e.g., from package.json) using Poku's `startScript`. It waits for a 'ready' signal before performing fetch requests. ```javascript import { assert, startScript } from 'poku'; const server = await startScript('start', { // Wait for the "ready" console output startAfter: 'ready', }); // Use the requester you want // highlight-start const res = await fetch('http://localhost:4000'); const data = await res.json(); // highlight-end assert.strictEqual(res.status, 200, 'Server is on'); assert.deepStrictEqual(data, { name: 'Poku' }, 'Poku is here'); server.end(); ``` -------------------------------- ### Start and End a Script with Options Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/helpers/startScript.mdx Execute a script from package.json, wait for a specific 'ready' console output, and set a custom timeout. The server process is then explicitly ended. ```typescript import { startScript } from 'poku'; const server = await startScript('start', { /** * Wait for the "ready" console output */ startAfter: 'ready', /** * By default, the `timeout` is `60000` (1 minute) for neither success nor failure */ timeout: 60000, }); await server.end(); ``` -------------------------------- ### Poku's Plain Statement Control Flow Source: https://github.com/wellwelwel/poku/blob/main/website/llms/philosophy.md Demonstrates Poku's approach using plain JavaScript statements for control flow, including setup, test execution, and teardown, all within sequential `await` calls. ```javascript import { describe, it } from 'poku'; await describe('My Test', async () => { console.log('Started'); await it(async () => { await stepOne(); }); await it(async () => { await stepTwo(); }); console.log('Done'); }); ``` -------------------------------- ### Create a Bun Server Source: https://github.com/wellwelwel/poku/blob/main/website/docs/examples/local-server.mdx Implements a simple server using Bun. It listens on port 4000 and returns a JSON response. The 'ready' message is logged to the console upon successful startup. ```javascript Bun.serve({ port: 4000, fetch: () => new Response(JSON.stringify({ name: 'Poku' }), { headers: { 'Content-Type': 'application/json' }, }), }); console.log('ready'); ``` -------------------------------- ### Configure Database Credentials Source: https://github.com/wellwelwel/poku/blob/main/website/docs/examples/database/sequelize.mdx Set up the database connection details in a .env.test file and add it to .gitignore. ```bash DB_HOST=localhost DB_PORT=5432 DB_USER=postgres DB_PASSWORD=secret DB_NAME=app ``` ```bash .env.test ``` -------------------------------- ### IPC Enabled Plugin Example Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/creating-plugins.mdx Demonstrates enabling the IPC channel for test processes by setting `ipc: true` and attaching a message listener in the `onTestProcess` hook. ```typescript export const myPlugin = definePlugin({ name: 'my-ipc', ipc: true, onTestProcess(child, file) { child.on('message', (msg) => { console.log(`Message from ${file}:`, msg); }); }, }); ``` -------------------------------- ### Drizzle Database Connection Setup Source: https://github.com/wellwelwel/poku/blob/main/website/docs/examples/database/drizzle.mdx Establish a connection to the PostgreSQL database using a single client and Drizzle ORM. Reads the connection string from environment variables. ```typescript import { drizzle } from 'drizzle-orm/node-postgres'; import { Client } from 'pg'; export const client = new Client({ connectionString: process.env.DATABASE_URL, }); await client.connect(); export const db = drizzle({ client }); ``` -------------------------------- ### Async beforeEach and afterEach with Promises Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/helpers/before-after-each/in-code.mdx Demonstrates using `beforeEach` and `afterEach` with asynchronous operations by leveraging promises. This is suitable for setup and teardown tasks that involve asynchronous I/O or other promise-based operations. ```typescript import { test, beforeEach, afterEach } from 'poku'; const prepareService = () => new Promise((resolve) => resolve(true)); const resetService = () => new Promise((resolve) => resolve(true)); beforeEach(async () => await prepareService()); afterEach(async () => await resetService()); await test(async () => { // do anything you want }); await test(async () => { // do anything you want }); ``` -------------------------------- ### Start and Stop Docker Compose Services Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/official/containers.mdx Use the docker.compose() helper to manage services defined in a docker-compose.yml file. Ensure you call compose.up() before your tests and compose.down() after. ```ts import { docker } from '@pokujs/docker'; const compose = docker.compose(); // Starts the container(s) await compose.up(); /** * Tests come here ๐Ÿงช */ // Stops the container(s) await compose.down(); ``` -------------------------------- ### Poku JSON Configuration Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/poku/config-files.mdx Configure Poku using a standard JSON file (`.pokurc.json`). This example shows basic settings for test execution and platform compatibility. ```json { "$schema": "https://poku.io/schemas/configs.json", "include": ["."], "sequential": true, "debug": false, "filter": ".test.|.spec.", "exclude": "", "failFast": false, "concurrency": 0, "timeout": 5000, "quiet": false, "envFile": ".env", "kill": { "port": [3000], "range": [ [3000, 3003], [4000, 4002] ], "pid": [612] }, "platform": "node", "deno": { "allow": ["run", "env", "read", "net"], "deny": [], "cjs": [".js", ".cjs"] } } ``` -------------------------------- ### Execute Post-Test Actions with Promise.all Source: https://github.com/wellwelwel/poku/blob/main/website/docs/examples/promises.mdx Run multiple asynchronous tests concurrently using `Promise.all` and then execute a post-step action. This is useful for performing setup or cleanup operations after a batch of tests. ```javascript import { describe, it, assert, sleep } from 'poku'; describe(async () => { console.log('Printing it before all tests ๐Ÿƒ๐Ÿปโ€โ™€๏ธ'); await Promise.all([ test(async () => { const actual = 1; const expected = 1; await sleep(2000); assert.strictEqual(actual, expected); }), test(async () => { const actual = 2; const expected = 2; await sleep(1000); assert.strictEqual(actual, expected); }), ]); console.log('Printing it after all tests ๐Ÿ˜ด'); }); ``` -------------------------------- ### Configure Database Credentials Source: https://github.com/wellwelwel/poku/blob/main/website/docs/examples/database/knex.mdx Set up database connection details in a .env.test file for the testing environment. Ensure this file is added to .gitignore to prevent accidental commits. ```bash DB_HOST=localhost DB_PORT=5432 DB_USER=postgres DB_PASSWORD=secret DB_NAME=app ``` ```bash .env.test ``` -------------------------------- ### Create a JSON Reporter Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/reporters.mdx This example demonstrates how to create a custom reporter that writes test results to a JSON file. It utilizes `createReporter` to define handlers for file results and exit events. ```typescript import { writeFileSync } from 'node:fs'; import { createReporter } from 'poku/plugins'; type FileResult = { path: string; status: boolean; duration: number; }; const fileResults: FileResult[] = []; export const jsonReporter = createReporter({ onFileResult({ status, path, duration }) { fileResults.push({ path: path.relative, status, duration }); }, onExit({ code, timespan }) { writeFileSync( 'test-results.json', JSON.stringify( { code, duration: timespan.duration, files: fileResults, }, null, 2 ) ); }, }); ``` -------------------------------- ### Test Local Server with Poku Source: https://github.com/wellwelwel/poku/blob/main/website/docs/examples/local-server.mdx Tests a local server using Poku's `startService` utility. It waits for a 'ready' signal before making a fetch request to verify the server's response. ```javascript import { assert, startService } from 'poku'; const server = await startService('server.js', { // Wait for the "ready" console output startAfter: 'ready', }); // Use the requester you want // highlight-start const res = await fetch('http://localhost:4000'); const data = await res.json(); // highlight-end assert.strictEqual(res.status, 200, 'Server is on'); assert.deepStrictEqual(data, { name: 'Poku' }, 'Poku is here'); server.end(); ``` -------------------------------- ### Install jsdom Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/official/react.mdx Install jsdom as a development dependency if you require broader browser API compatibility. ```bash # jsdom npm i -D jsdom ``` -------------------------------- ### Generate Prisma Client and Run Tests Source: https://github.com/wellwelwel/poku/blob/main/website/docs/examples/database/prisma.mdx Execute commands to generate the Prisma client and run your Poku tests. ```bash npx prisma generate npm test ``` -------------------------------- ### Create a Node.js HTTP Server Source: https://github.com/wellwelwel/poku/blob/main/website/docs/examples/local-server.mdx Sets up a basic HTTP server using Node.js's built-in 'http' module that responds with JSON. The server listens on port 4000 and logs a 'ready' message to the console. ```javascript import { createServer } from 'node:http'; createServer((_, res) => { res.writeHead(200, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ name: 'Poku' })); }).listen(4000, () => console.log('ready')); ``` -------------------------------- ### Install Node types for TypeScript Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/helpers/list-files.mdx If you are using `listFiles` with TypeScript, you may need to install the Node.js types package. ```bash npm i -D @types/node ``` -------------------------------- ### Configure Test Database Credentials Source: https://github.com/wellwelwel/poku/blob/main/website/docs/examples/database/drizzle.mdx Set up environment variables for the test database connection in a .env.test file. ```bash DB_USER=postgres DB_PASSWORD=secret DB_PORT=5432 DB_NAME=app DATABASE_URL="postgresql://${DB_USER}:${DB_PASSWORD}@localhost:${DB_PORT}/${DB_NAME}" ``` -------------------------------- ### onFileStart Event Options Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/reporters.mdx The `onFileStart` event handler provides the absolute and relative paths of the test file that is about to be executed. ```typescript type options = { path: { absolute: string; relative: string; }; }; ``` -------------------------------- ### Install @pokujs/monocart Plugin Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/official/coverage/index.mdx Install the monocart plugin as a dev dependency. This plugin supports various configuration file formats. ```bash npm i -D @pokujs/monocart ``` -------------------------------- ### Run Canary Version of Poku with Deno Source: https://github.com/wellwelwel/poku/blob/main/website/docs/index.mdx Execute the canary (latest development) version of Poku using Deno's npm integration. ```bash deno run npm:poku@canary ``` -------------------------------- ### Run Tests Source: https://github.com/wellwelwel/poku/blob/main/website/docs/examples/database/pg.mdx Execute the test suite using npm. ```bash npm test ``` -------------------------------- ### Run Poku Tests Source: https://github.com/wellwelwel/poku/blob/main/website/docs/examples/browser/DOM.mdx Execute your Poku test suite from the command line. ```bash npx poku ``` -------------------------------- ### Runner Hook Example for Custom Runtimes Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/creating-plugins.mdx Illustrates the `runner` hook, which modifies the command array for spawning test processes. This example changes the runtime for specific file types. ```typescript export const myPlugin = definePlugin({ name: 'my-runner', runner(command, file) { if (file.endsWith('.custom.ts')) { return ['my-runtime', ...command.slice(1)]; } return command; }, }); ``` -------------------------------- ### Run Poku CLI Source: https://github.com/wellwelwel/poku/blob/main/website/llms/llms.md Execute Poku tests using the command line interface for Node.js, Bun, or Deno. The CLI automatically detects configuration files. ```bash # Node.js npx poku # Bun bun --bun poku # Deno deno run npm:poku ``` -------------------------------- ### Plugin Example: AsyncLocalStorage Scope Hooks Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/test-scope-hooks.mdx An example of implementing scoped test lifecycle hooks using Node.js's `AsyncLocalStorage`. This ensures that test-specific data is isolated across concurrent test executions. ```typescript import { AsyncLocalStorage } from 'node:async_hooks'; import { composeScopeHooks } from 'poku/plugins'; type ScopeHooks = { createHolder: () => { scope: unknown }; runScoped: ( holder: { scope: unknown }, fn: () => Promise | unknown ) => Promise; }; const SCOPE_HOOKS_KEY = Symbol.for('@pokujs/poku.test-scope-hooks'); const als = new AsyncLocalStorage<{ id: number }>(); let idSeed = 0; composeScopeHooks({ name: '@acme/my-plugin.scope-hooks', createHolder: () => ({ scope: undefined }), runScoped: async (holder, fn) => { const id = ++idSeed; holder.scope = { id }; await als.run({ id }, async () => { const result = fn(); if (result instanceof Promise) await result; }); }, }); ``` -------------------------------- ### Define a Resource Context with resource.create() Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/official/shared-resources.mdx Create a resource context using `resource.create()`. This function takes a factory that returns the resource object and automatically detects the module path. Use the `module` option as a fallback if automatic detection fails. ```ts import { resource } from '@pokujs/shared-resources'; export const CounterContext = resource.create(() => ({ count: 0, increment() { this.count++; return this.count; }, getCount() { return this.count; } })); ``` ```ts export const CounterContext = resource.create( () => ({ /* ... */ }), { module: __filename } // or import.meta.url for ESM ); ``` -------------------------------- ### Configure jsdom Adapter Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/official/react.mdx Specify 'jsdom' as the DOM adapter in the reactTestingPlugin configuration. Ensure jsdom is installed. ```javascript reactTestingPlugin({ dom: 'jsdom' }); ``` -------------------------------- ### Configure happy-dom Adapter Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/official/react.mdx Specify 'happy-dom' as the DOM adapter in the reactTestingPlugin configuration. Ensure happy-dom and @happy-dom/global-registrator are installed. ```javascript reactTestingPlugin({ dom: 'happy-dom' }); ``` -------------------------------- ### Teardown Hook Example Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/creating-plugins.mdx Shows how to use the `teardown` hook in `definePlugin` for cleanup operations after the test suite completes. ```typescript export const myPlugin = definePlugin({ name: 'my-cleanup', async teardown() { // stop servers, close connections, etc. }, }); ``` -------------------------------- ### Poku Strict Assert Example Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/assert/index.mdx Demonstrates the usage of Poku's strict assert with custom messages for equality checks. ```typescript strict(true, "It's true ๐Ÿงช"); strict.strictqual(1, '1', 'Poku will describe it and show an error ๐Ÿท'); ``` -------------------------------- ### Grouped Test with Assertions Source: https://github.com/wellwelwel/poku/blob/main/website/llms/llms.md Use the 'test' helper to group logic and assertions. This example demonstrates a simple sum calculation and assertion. ```javascript import { test, strict } from 'poku'; test('sum', () => { const actual = 2 + 3; strict.strictEqual(actual, 5, 'It sums two numbers'); }); ``` -------------------------------- ### poku(targetPaths, options) Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/poku/programmatic-api.mdx Runs Poku programmatically. By default, it runs the suite and exits the process with the result. It accepts a single path or an array of paths and optional configuration options. ```APIDOC ## `poku(targetPaths, options)` ### Description Runs Poku programmatically. By default, it runs the suite and exits the process with the result. It accepts a single path or an array of paths and optional configuration options. ### Signature `poku(targetPaths: string | string[], options?: Configs): Promise` ### Parameters #### `targetPaths` - **Type**: `string | string[]` - **Description**: The path or an array of paths to the test suites. #### `options` - **Type**: `Configs` (optional) - **Description**: Configuration options for Poku. ### Request Example ```ts import { poku } from 'poku'; await poku('./test'); ``` ### Execution Example ```bash node test/run.test.js ``` ```bash npx tsx test/run.test.ts ``` ``` -------------------------------- ### Write a Vue Component Test Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/official/vue.mdx Example test for a Vue Single File Component using Poku's testing utilities. ```typescript // tests/counter-button.test.ts import { afterEach, assert, test } from 'poku'; import { cleanup, fireEvent, render, screen } from '@pokujs/vue'; import CounterButton from './CounterButton.vue'; afterEach(cleanup); test('renders and updates an SFC component', async () => { render(CounterButton, { props: { initialCount: 1 }, }); assert.strictEqual( screen.getByRole('heading', { name: 'Count: 1' }).textContent, 'Count: 1' ); await fireEvent.click(screen.getByRole('button', { name: 'Increment' })); assert.strictEqual( screen.getByRole('heading', { name: 'Count: 2' }).textContent, 'Count: 2' ); }); ``` -------------------------------- ### Quick enable render metrics Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/official/react.mdx Enables the recording of render durations for components. This provides a quick way to identify performance bottlenecks. ```javascript reactTestingPlugin({ dom: 'happy-dom', metrics: true, }); ``` -------------------------------- ### Docker Compose Configuration for PostgreSQL Source: https://github.com/wellwelwel/poku/blob/main/website/docs/examples/database/drizzle.mdx Define a Docker Compose setup for a PostgreSQL service, reading credentials from .env.test. Includes a healthcheck for the database. ```yaml services: postgres: image: postgres:18 environment: POSTGRES_USER: ${DB_USER} POSTGRES_PASSWORD: ${DB_PASSWORD} POSTGRES_DB: ${DB_NAME} ports: - '${DB_PORT}:5432' healthcheck: test: ['CMD-SHELL', 'pg_isready -U ${DB_USER} -d ${DB_NAME}'] interval: 5s timeout: 5s retries: 10 start_period: 30s db-ready: image: busybox command: ['tail', '-f', '/dev/null'] depends_on: postgres: condition: service_healthy ``` -------------------------------- ### CLI: Default Process Isolation Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/poku/options/isolation.mdx Use this command to run tests with the default process isolation, where each test file gets its own child process. ```bash npx poku --isolation=process ./test # default ``` -------------------------------- ### Create Vite React App Source: https://github.com/wellwelwel/poku/blob/main/website/docs/examples/browser/react.mdx Use npm to create a new Vite React application. This command sets up the basic project structure. ```bash npm create vite@latest my-project -- --template react ``` -------------------------------- ### kill.range Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/helpers/processes/kill.mdx Terminates the specified port range. This function takes a starting port and an ending port. It requires `lsof` on Unix-like systems and `netstat` on Windows. ```APIDOC ## kill.range ### Description Terminates the specified port range. This function takes a starting port and an ending port. - Requires `lsof` for **Unix** and `netstat` for **Windows**. ### Method Signature `kill.range(startsAt: number, endsAt: number)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### CLI Usage Terminates the specified port range before running the test suite. ```bash npx poku --killRange="4000-4100" targetPath ``` Also, terminating multiple port ranges: ```bash npx poku --killRange="4000-4100,5000-5100" targetPath ``` ### Config File Usage #### poku.config.js ```ts import { defineConfig } from 'poku'; export default defineConfig({ kill: { range: [[4000, 4100]], }, }); ``` #### .pokurc.jsonc ```json { "$schema": "https://poku.io/schemas/configs.json", "kill": { "range": [[4000, 4100]] } } ``` ### Helper Function Usage ```ts import { kill } from 'poku'; await kill.range(4000, 4100); ``` ``` -------------------------------- ### Configure Poku for In-Process Isolation Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/official/vue.mdx Set `isolation: 'none'` in `poku.config.js` to run tests in-process, enabling the SFC loader and direct DOM setup. ```javascript // poku.config.js export default defineConfig({ isolation: 'none', plugins: [vueTestingPlugin({ dom: 'happy-dom' })], }); ``` -------------------------------- ### Write ScyllaDB Test Cases Source: https://github.com/wellwelwel/poku/blob/main/website/docs/examples/database/scylladb.mdx Write integration tests for a users table using Poku. Includes seeding the database with a keyspace and table, inserting data, and asserting retrieved data. ```typescript import { describe, it, assert } from 'poku'; import { connect } from './db.js'; const keyspace = process.env.DB_KEYSPACE; await describe('Users table', async () => { const client = await connect(); await describe('Seed', async () => { await client.execute( `CREATE KEYSPACE IF NOT EXISTS ${keyspace} WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}` ); await client.execute( `CREATE TABLE IF NOT EXISTS ${keyspace}.users (id INT PRIMARY KEY, name TEXT)` ); await client.execute( `INSERT INTO ${keyspace}.users (id, name) VALUES (?, ?)`, [1, 'Poku'], { prepare: true } ); }); await it('reads the inserted user', async () => { const result = await client.execute( `SELECT name FROM ${keyspace}.users WHERE id = ?`, [1], { prepare: true } ); assert.strictEqual( result.first().name, 'Poku', 'The inserted user is returned' ); }); await client.shutdown(); }); ``` -------------------------------- ### PluginContext Type Definition Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/creating-plugins.mdx Illustrates the structure of the `PluginContext` object passed to `setup` and `teardown` hooks, providing access to runtime information and test results. ```typescript type PluginContext = { readonly configs: Configs; readonly runtime: Runtime; // 'node' | 'bun' | 'deno' readonly cwd: string; readonly configFile: string | undefined; readonly runAsOnly: boolean; readonly results: { passed: number; failed: number; skipped: number; todo: number; }; readonly timespan: { started: Date; finished: Date; duration: number }; readonly reporter: ReturnType; }; ``` -------------------------------- ### Scope Plugins Per Suite Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/official/multi-suite.mdx Apply specific plugins to individual test suites. This example scopes the 'sharedResources' plugin to the integration test suite. ```ts import { sharedResources } from '@pokujs/shared-resources'; multiSuite([ { include: 'test/unit' }, { include: 'test/integration', plugins: [sharedResources()] }, ]); ``` -------------------------------- ### Configure Deno Allow Permissions in .pokurc.jsonc Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/poku/options/deno.mdx Manage Deno permissions using the JSON configuration file for more persistent settings. ```json { "$schema": "https://poku.io/schemas/configs.json", "deno": { "allow": ["read", "run"] } } ``` ```json { "$schema": "https://poku.io/schemas/configs.json", "deno": { "allow": ["read=file.js", "run"] } } ``` ```json { "$schema": "https://poku.io/schemas/configs.json", "deno": { "allow": [] } } ``` -------------------------------- ### Render a Vue Component Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/plugins/official/vue.mdx Render a Vue component and get access to DOM query helpers, rerender, and unmount functions. Props can be passed to the component. ```typescript const { getByText, rerender, unmount } = render(CounterButton, { props: { initialCount: 0 }, }); ``` -------------------------------- ### Describe and It for 'sum' and 'sub' Methods Source: https://github.com/wellwelwel/poku/blob/main/website/docs/tutorials/good-practices.mdx Organizes tests for 'sum' and 'sub' methods using 'describe' and 'it' blocks for better structure and readability. Imports 'describe', 'it', and 'assert' from 'poku'. ```javascript import { describe, it, assert } from 'poku'; import { sum, sub } from '../../src/calc.mjs'; describe('Testing calculation methods', () => { it('"sum" method', () => { assert(sum(0, 0), 0, 'should return zero'); assert(sum(0, 1), 1, 'should return one'); assert(sum(1, 1), 2, 'should return two'); }); it('"sub" method', () => { assert(sub(1, 1), 0, 'should return zero'); assert(sub(2, 1), 1, 'should return one'); assert(sub(3, 1), 2, 'should return two'); }); }); ``` -------------------------------- ### CLI: Run tests matching 'auth' Source: https://github.com/wellwelwel/poku/blob/main/website/docs/documentation/poku/options/testNamePattern.mdx Use the --testNamePattern CLI flag to filter tests by title. This example runs tests containing 'auth'. ```bash npx poku --testNamePattern='auth' ./test ```