[READ-ONLY] Mirror of https://github.com/danielroe/nuxt-vitest. An vitest environment with support for testing code that needs a Nuxt runtime environment
nuxt nuxt-module testing unit-testing vitest
0

Configure Feed

Select the types of activity you want to include in your feed.

docs: add some more info about usage

Daniel Roe (Dec 21, 2022, 9:57 AM UTC) e2754ffa 8759dd45

+31 -17
+30 -16
README.md
··· 1 - <h1 align="center">vitest-environment-nuxt</h1> 2 - <p align="center">An in-development vitest environment with support for testing code that needs a Nuxt runtime environment.</p> 3 - 4 - <p align="center"> 1 + # vitest-environment-nuxt 5 2 6 3 [![npm version][npm-version-src]][npm-version-href] 7 4 [![npm downloads][npm-downloads-src]][npm-downloads-href] 8 5 [![Github Actions][github-actions-src]][github-actions-href] 9 6 [![Codecov][codecov-src]][codecov-href] 10 7 11 - </p> 8 + > A vitest environment for testing code that needs a [Nuxt](https://nuxt.com) runtime environment 12 9 13 - > An in-development vitest environment with support for testing code that needs a Nuxt runtime environment 10 + - [✨ &nbsp;Changelog](https://github.com/danielroe/vitest-environment-nuxt/blob/main/CHANGELOG.md) 14 11 15 - ⚠️ This library is in active development and you should pin the patch version before using. 12 + > **Warning** 13 + > This library is in active development and you should pin the patch version before using. 16 14 17 - ## Quick Start 15 + ## Installation 18 16 19 - First install `vitest-environment-nuxt`: 17 + 1. First install `vitest-environment-nuxt`: 20 18 21 19 ```bash 22 - yarn add --dev vitest-environment-nuxt 23 - 24 - # or npm 25 - npm i -D vitest-environment-nuxt 26 - 27 - # or pnpm 28 20 pnpm add -D vitest-environment-nuxt 21 + 22 + # or 23 + yarn add --dev vitest-environment-nuxt 24 + npm i -D vitest-environment-nuxt 29 25 ``` 26 + 27 + 2. Then create a `vitest.config.mjs` with the following content: 28 + 29 + ```js 30 + import { defineConfigWithNuxtEnv } from 'vitest-environment-nuxt/config' 31 + 32 + export default defineConfigWithNuxtEnv({ 33 + // any custom vitest config you require 34 + }) 35 + ``` 36 + 37 + That's it. Now when you run `vitest` your Nuxt environment will be available throughout your tests. 38 + 39 + ## 👉 Important notes 40 + 41 + When you run your tests within `vitest-environment-nuxt`, they will be running in a [`happy-dom`](https://github.com/capricorn86/happy-dom) environment. Before your tests run, a global Nuxt app will be initialised (including, for example, running any plugins or code you've defined in your `app.vue`). 42 + 43 + This means you should be take particular care not to mutate the global state in your tests (or, if you have, to reset it afterwards). 30 44 31 45 ## 💻 Development 32 46 ··· 40 54 41 55 Made with ❤️ 42 56 43 - Published under [MIT License](./LICENCE). 57 + Published under the [MIT License](./LICENCE). 44 58 45 59 <!-- Badges --> 46 60
+1 -1
package.json
··· 1 1 { 2 2 "name": "vitest-environment-nuxt", 3 3 "version": "0.2.0", 4 - "description": "An in-development vitest environment with support for testing code that needs a Nuxt runtime environment.", 4 + "description": "An vitest environment with support for testing code that needs a Nuxt runtime environment.", 5 5 "repository": "danielroe/vitest-environment-nuxt", 6 6 "keywords": [ 7 7 "nuxt",