Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

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