{"id":22106970,"url":"https://github.com/mooyoul/chai-image","last_synced_at":"2025-07-25T03:32:11.905Z","repository":{"id":35119577,"uuid":"209059479","full_name":"mooyoul/chai-image","owner":"mooyoul","description":"Extends Chai with assertions about images","archived":false,"fork":false,"pushed_at":"2024-11-28T08:27:47.000Z","size":3895,"stargazers_count":6,"open_issues_count":18,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-29T15:57:52.206Z","etag":null,"topics":["assertions","chai","image","visual-comparison-testing","visual-regression-testing"],"latest_commit_sha":null,"homepage":null,"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/mooyoul.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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":"2019-09-17T13:19:35.000Z","updated_at":"2023-03-04T17:51:56.000Z","dependencies_parsed_at":"2023-02-19T01:46:12.377Z","dependency_job_id":"cd3076b4-dde4-41af-bada-68d469b2515f","html_url":"https://github.com/mooyoul/chai-image","commit_stats":{"total_commits":555,"total_committers":4,"mean_commits":138.75,"dds":0.2918918918918919,"last_synced_commit":"c346d9780bc0efbe6aa7ecd779d7141b5974cba4"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mooyoul%2Fchai-image","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mooyoul%2Fchai-image/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mooyoul%2Fchai-image/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mooyoul%2Fchai-image/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mooyoul","download_url":"https://codeload.github.com/mooyoul/chai-image/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227515007,"owners_count":17782642,"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":["assertions","chai","image","visual-comparison-testing","visual-regression-testing"],"created_at":"2024-12-01T08:12:51.506Z","updated_at":"2024-12-01T08:12:52.127Z","avatar_url":"https://github.com/mooyoul.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# chai-image\n\n[![Build Status](https://github.com/mooyoul/chai-image/workflows/workflow/badge.svg)](https://github.com/mooyoul/chai-image/actions)\n[![Semantic Release enabled](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n[![Renovate enabled](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com/)\n[![MIT license](http://img.shields.io/badge/license-MIT-blue.svg)](http://mooyoul.mit-license.org/)\n\nExtends Chai with assertions about images\n\n```typescript\nexpect(bufImage).to.matchImage(bufExpectedImage);\n```\n\n\n![Example](example.png)\n\n| Expected | Actual |\n| --- | --- |\n| ![Expected Image](fixtures/red_velvet_perfect_velvet_all_2_co_m_l.png) | ![Actual Image](fixtures/red_velvet_perfect_velvet_all_2_co_l.png)\n\n| Diff (LEFT_TOP Aligned) | Diff (CENTER Aligned)\n| --- | --- |\n| ![Diff Image](fixtures/test_diff_left_top.png) | ![Diff Image](fixtures/test_diff_center.png) |\n\nIn this case, `matchImage` assertion will fail.\n\n## Usage\n\nInstall `chai-image` to get up and running. \n\n```bash\n$ npm install chai-image --save-dev\n```\n\nThen:\n\n```typescript\nimport * as chai from \"chai\";\nimport { chaiImage } from \"chai-image\";\n\nchai.use(chaiImage);\n\n// Then either:\nconst expect = chai.expect;\n// or:\nconst assert = chai.assert;\n// or:\nchai.should();\n// according to your preference of assertion style\n\n```\n\n## Assertions\n\n#### `matchImage(expected: Buffer, options?: MatchImageOptions)`\n\n\u003e NOTE: Currently it only supports PNG image format.\n\n##### Example\n\n```typescript\n// Simple Example\nimport * as fs from \"fs\";\n\nconst bufActual = fs.readFileSync(\"actual.png\");\nconst bufExpected = fs.readFileSync(\"expected.png\");\n\nexpect(bufActual).to.matchImage(bufExpected);\n```\n\n```typescript\n// Real-world Example\nimport * as sharp from \"sharp\";\n\nclass ImageService {\n  public async transform(buf: Buffer): Promise\u003cBuffer\u003e {\n    return await sharp(buf).resize().max(320, 320).png().toBuffer();\n  }\n}\n\nconst service = new ImageService();\n\ndescribe(\"ImageService\", () =\u003e {\n  describe(\"#transform\", () =\u003e {\n    it(\"should transform image\", async () =\u003e {\n      const input = fs.readFileSync(\"fixtures/input.png\");\n      const output = fs.readFileSync(\"fixtures/output.png\");\n      \n      expect(await service.transform(input)).to.matchImage(output);\n    });\n  });\n});\n\n```\n\nTests image matches to given image or not.\n\nImage comparision is proceeded by [pixelmatch](https://github.com/mapbox/pixelmatch) library.\nIf output config is provided, `chai-image` will create some files to show diff results.\n\n\n\n```typescript\n\nenum Align {\n  LEFT_TOP = \"leftTop\",\n  CENTER = \"center\",\n}\n\ninterface MatchImageOptions {\n  // Custom diff config passed to pixelmatch\n  diff?: DiffOptions;\n  \n  // Image aligning config for aligning different size image (default: Align.LEFT_TOP)\n  align?: Align;\n  \n  // Output config\n  // if specified, chai-image will create output files to visualize diff \n  output?: OutputOptions;\n}\n\ninterface DiffOptions {\n  threshold?: number;\n  includeAA?: boolean;\n  alpha?: number;\n  aaColor?: [number, number, number];\n  /* The color of differing pixels in the diff output. [255, 0, 0] by default. */\n  diffColor?: [number, number, number];\n}\n\ninterface OutputOptions {\n  // Currently name is used to generate filename\n  name: string;\n  // Path of output directory (default: WORKDING_DIR/outputs)\n  dir?: string;\n  \n  // Output creation conditions\n  // Controls when to create output files (default: failure)\n  on?: \"failure\" | \"always\";\n  \n  // Controls output file types (default: false)\n  diffOnly?: boolean;\n}\n```\n\n## Changelog\n\nSee [CHANGELOG](/CHANGELOG.md).\n\n## Testing\n\n```bash\n$ npm run test\n```\n\n## Build\n\n```bash\n$ npm run build\n```\n\n\n## License\n[MIT](LICENSE)\n\nSee full license on [mooyoul.mit-license.org](http://mooyoul.mit-license.org/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmooyoul%2Fchai-image","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmooyoul%2Fchai-image","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmooyoul%2Fchai-image/lists"}