{"id":15416612,"url":"https://github.com/remcohaszing/snapshot-fixtures","last_synced_at":"2025-04-19T14:33:23.559Z","repository":{"id":229693128,"uuid":"777397634","full_name":"remcohaszing/snapshot-fixtures","owner":"remcohaszing","description":"Snapshot fixtures for node:test","archived":false,"fork":false,"pushed_at":"2024-03-26T09:55:26.000Z","size":176,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-05-02T05:14:23.839Z","etag":null,"topics":["assert","diff","equal","fixture","snapshot","string","test"],"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/remcohaszing.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2024-03-25T19:22:40.000Z","updated_at":"2024-04-13T11:04:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"fff30b7e-0116-4eff-8fb8-9685c2f2a37c","html_url":"https://github.com/remcohaszing/snapshot-fixtures","commit_stats":null,"previous_names":["remcohaszing/snapshot-fixtures"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remcohaszing%2Fsnapshot-fixtures","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remcohaszing%2Fsnapshot-fixtures/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remcohaszing%2Fsnapshot-fixtures/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remcohaszing%2Fsnapshot-fixtures/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/remcohaszing","download_url":"https://codeload.github.com/remcohaszing/snapshot-fixtures/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234444586,"owners_count":18833657,"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":["assert","diff","equal","fixture","snapshot","string","test"],"created_at":"2024-10-01T17:12:46.107Z","updated_at":"2025-01-17T23:52:54.227Z","avatar_url":"https://github.com/remcohaszing.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# snapshot-fixtures\n\n[![github actions](https://github.com/remcohaszing/snapshot-fixtures/actions/workflows/ci.yaml/badge.svg)](https://github.com/remcohaszing/snapshot-fixtures/actions/workflows/ci.yaml)\n[![codecov](https://codecov.io/gh/remcohaszing/snapshot-fixtures/branch/main/graph/badge.svg)](https://codecov.io/gh/remcohaszing/snapshot-fixtures)\n[![npm version](https://img.shields.io/npm/v/snapshot-fixtures)](https://www.npmjs.com/package/snapshot-fixtures)\n[![npm downloads](https://img.shields.io/npm/dm/snapshot-fixtures)](https://www.npmjs.com/package/snapshot-fixtures)\n\nSnapshot fixtures for [`node:test`](https://nodejs.org/api/test.html).\n\n## Table of Contents\n\n- [Installation](#installation)\n- [When to use this?](#when-to-use-this)\n- [Usage](#usage)\n- [API](#api)\n  - [`assertEqual(actual, expected[, options])`](#assertequalactual-expected-options)\n    - [Arguments](#arguments)\n  - [`testFixturesDirectory(options)`](#testfixturesdirectoryoptions)\n    - [Options](#options)\n  - [`Test`](#test)\n- [Compatibility](#compatibility)\n- [License](#license)\n\n## Installation\n\n```sh\nnpm install snapshot-fixtures\n```\n\n## When to use this?\n\nThis package exposes a function for creating tests based on a directory containing test fixtures.\nThis is useful if you want to run tests based on a string input and a string output, especially for\nmultiline content.\n\n## Usage\n\nLet’s say you have the following project structure:\n\n```\nmy-project/\n├── fixtures/\n│   ├── fixture-1/\n│   │   ├── input.txt\n│   │   ├── expected-1.txt\n│   │   ├── expected-2.txt\n│   │   └── options.json\n│   └── fixture-2/\n│       ├── input.txt\n│       ├── expected-1.txt\n│       ├── expected-2.txt\n│       └── options.js\n└── test/\n    └── fixtures.test.js\n```\n\nThen `src/fixtures.test.js` could look like this:\n\n```typescript\nimport { fn } from 'my-project'\nimport { testFixturesDirectory } from 'snapshot-fixtures'\n\ntestFixturesDirectory({\n  directory: new URL('../fixtures', import.meta.url),\n  tests: {\n    'expected-1.txt'(file, options) {\n      return fn(file, options)\n    },\n\n    'expected-2.txt'(file, options) {\n      return fn(file, options, 'additional options')\n    }\n  }\n})\n```\n\nThis test asserts that the contents of the `expected-1.txt` and `expected-2.txt` tests of each\nfixture match the respective return value of matching test function.\n\n## API\n\n### `assertEqual(actual, expected[, options])`\n\nAssert two strings are equal.\n\nIf the strings are not equal, an assertion error will be thrown. This assertion error contains a\npretty diff of the two strings.\n\n#### Arguments\n\n- `actual` (`string`) — The actual value that was produced.\n- `expected` (`string`) — The value that was expected.\n- `options` (`object`, optional) — An object with additional options. The following options are\n  supported:\n  - `url` (`string` | `URL`) — The file URL to include in the assertion error if `expected` is not\n    equal to `actual`.\n\n### `testFixturesDirectory(options)`\n\nCreate a test suite for a fixtures directory based on\n[`node:test`](https://nodejs.org/api/test.html). A fixtures directory is a directory that contains\nother directories. For each of these directories a nested test suite is created. For each of these\nnested test suites, a test is created based on the tests passed. Each test reads the input file,\nuses the given test function to generate output, and compares it to the content of the expected\noutput file.\n\n#### Options\n\n- `directory` (`string` | `URL`) — The directory containing fixtures as a URL or URL string.\n- `prettier` (`boolean`, optional) — If true, format the generated value with Prettier. (Default:\n  false)\n- `tests` (`object`) — A mapping of test name to a [fixture test](#test).\n- `write` (`boolean`) — If true, overwrite the expected content with the actual content. In CI, the\n  output is never written. (Default: false)\n\n### `Test`\n\nA test to run, either as a fixture test object, or as a generate function. The generate function\ntakes a [`VFile`](https://github.com/vfile/vfile) as input, which is read from the `input` file and\nreturn a string that should match the expected output. A second argument `options` can be accepted.\nThis may contain the options of the fixture. These options are read from the `options.cjs`,\n`options.js`, `options.json` or `options.mjs` file in the fixture directory.\n\nA test may be an object with the `generate` and optional `input`, `expected`, and `ignore`\nproperties. In this case `input` determines which input file to read, `generate` serves as the\ngenerate function, and `expected` refers to the expected output file. If `ignore` is true, the\nresult is written, but assertion failures are ignored.\n\n## Compatibility\n\nThis project is compatible with Node.js 16 or greater.\n\n## License\n\n[MIT](LICENSE.md) © [Remco Haszing](https://github.com/remcohaszing)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fremcohaszing%2Fsnapshot-fixtures","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fremcohaszing%2Fsnapshot-fixtures","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fremcohaszing%2Fsnapshot-fixtures/lists"}