Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wobsoriano/vitest-canvas-mock
🌗 A module used to mock canvas in Vitest.
https://github.com/wobsoriano/vitest-canvas-mock
canvas ci mock test vitest
Last synced: 7 days ago
JSON representation
🌗 A module used to mock canvas in Vitest.
- Host: GitHub
- URL: https://github.com/wobsoriano/vitest-canvas-mock
- Owner: wobsoriano
- License: mit
- Created: 2022-06-30T16:39:23.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-01-23T16:59:44.000Z (12 months ago)
- Last Synced: 2024-05-01T16:36:49.729Z (9 months ago)
- Topics: canvas, ci, mock, test, vitest
- Language: TypeScript
- Homepage:
- Size: 145 KB
- Stars: 51
- Watchers: 3
- Forks: 8
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# vitest-canvas-mock
[![npm (tag)](https://img.shields.io/npm/v/vitest-canvas-mock?style=flat&colorA=000000&colorB=000000)](https://www.npmjs.com/package/vitest-canvas-mock) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/vitest-canvas-mock?style=flat&colorA=000000&colorB=000000) ![NPM](https://img.shields.io/npm/l/vitest-canvas-mock?style=flat&colorA=000000&colorB=000000)
Mock `canvas` when running unit tests with [vitest](https://vitest.dev/). Uses [jest-canvas-mock](https://github.com/hustcc/jest-canvas-mock).
## Install
```bash
npm install vitest-canvas-mock -D
```## Usage
1. Create a new setup file that imports `vitest-canvas-mock` or add it to an existing setup file.
```ts
// vitest.setup.ts
import 'vitest-canvas-mock'
```2. In your `vitest.config.ts` file, create a `setupFiles` array and add that file:
```ts
import { defineConfig } from 'vitest/config'export default defineConfig({
test: {
setupFiles: ['./vitest.setup.ts'],
environment: 'jsdom',
deps: {
// vitest < 0.34
inline: ['vitest-canvas-mock'],
// >= 0.34
optimizer: {
web: {
include: ['vitest-canvas-mock']
}
}
},
// For this config, check https://github.com/vitest-dev/vitest/issues/740
// Vitest < 0.1.x
threads: false,
// >= 0.1.0
poolOptions: {
threads: {
singleThread: true,
},
},
environmentOptions: {
jsdom: {
resources: 'usable',
},
},
},
})
```## Mock Strategy
View mock strategy doc [here](https://github.com/hustcc/jest-canvas-mock#mock-strategy).
## Snapshots
View snapshots doc [here](https://github.com/hustcc/jest-canvas-mock#snapshots)
## License
MIT