Socket
Socket
Sign inDemoInstall

vitest-environment-nuxt

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vitest-environment-nuxt - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

3

dist/utils.d.ts

@@ -6,5 +6,6 @@ import { EventHandler } from 'h3';

declare function registerEndpoint(url: string, handler: EventHandler): void;
declare function mockNuxtImport<T = any>(name: string, factory: () => T | Promise<T>): void;
declare function mountSuspended<T extends DefineComponent<any, any, any, any>>(component: T): Promise<VueWrapper<InstanceType<T>>>;
export { mountSuspended, registerEndpoint };
export { mockNuxtImport, mountSuspended, registerEndpoint };
{
"name": "vitest-environment-nuxt",
"version": "0.2.0",
"description": "An in-development vitest environment with support for testing code that needs a Nuxt runtime environment.",
"version": "0.3.0",
"description": "An vitest environment with support for testing code that needs a Nuxt runtime environment.",
"repository": "danielroe/vitest-environment-nuxt",

@@ -19,3 +19,13 @@ "keywords": [

"dev:prepare": "unbuild --stub && pnpm nuxi prepare playground",
"test": "cd playground && pnpm vitest"
"dev": "pnpm dev:prepare && pnpm -C playground test:nuxt",
"lint": "pnpm lint:all:eslint && pnpm lint:all:prettier",
"lint:all:eslint": "pnpm lint:eslint --ext .ts,.js,.mjs,.cjs .",
"lint:all:prettier": "pnpm lint:prettier \"{src,test}/**/*.{js,json,ts}\"",
"lint:eslint": "eslint --fix",
"lint:prettier": "prettier --write --loglevel warn",
"prepare": "husky install && pnpm build",
"prepublishOnly": "pnpm test run && pinst --disable",
"_postinstall": "husky install",
"postpublish": "pinst --enable",
"test": "pnpm -C playground test"
},

@@ -52,11 +62,22 @@ "main": "./dist/index.cjs",

"ofetch": "^1.0.0",
"magic-string": "^0.27.0",
"estree-walker": "^3.0.1",
"unenv": "^1.0.0"
},
"devDependencies": {
"@nuxt/eslint-config": "latest",
"@release-it/conventional-changelog": "latest",
"@vitest/coverage-c8": "latest",
"conventional-changelog-conventionalcommits": "latest",
"eslint": "latest",
"eslint-config-prettier": "latest",
"eslint-plugin-prettier": "latest",
"husky": "latest",
"lint-staged": "latest",
"nuxt": "3.0.0",
"pinst": "latest",
"prettier": "latest",
"release-it": "latest",
"unbuild": "^1.0.2",
"vitest": "0.24.5",
"vitest": "0.26.2",
"vue": "^3.2.45"

@@ -63,0 +84,0 @@ },

@@ -1,6 +0,3 @@

<h1 align="center">vitest-environment-nuxt</h1>
<p align="center">An in-development vitest environment with support for testing code that needs a Nuxt runtime environment.</p>
# vitest-environment-nuxt
<p align="center">
[![npm version][npm-version-src]][npm-version-href]

@@ -11,22 +8,63 @@ [![npm downloads][npm-downloads-src]][npm-downloads-href]

</p>
> A vitest environment for testing code that needs a [Nuxt](https://nuxt.com) runtime environment
> An in-development vitest environment with support for testing code that needs a Nuxt runtime environment
- [✨ &nbsp;Changelog](https://github.com/danielroe/vitest-environment-nuxt/blob/main/CHANGELOG.md)
⚠️ This library is in active development and you should pin the patch version before using.
> **Warning**
> This library is in active development and you should pin the patch version before using.
## Quick Start
## Installation
First install `vitest-environment-nuxt`:
1. First install `vitest-environment-nuxt`:
```bash
pnpm add -D vitest-environment-nuxt
# or
yarn add --dev vitest-environment-nuxt
# or npm
npm i -D vitest-environment-nuxt
```
# or pnpm
pnpm add -D vitest-environment-nuxt
2. Then create a `vitest.config.mjs` with the following content:
```js
import { defineConfigWithNuxtEnv } from 'vitest-environment-nuxt/config'
export default defineConfigWithNuxtEnv({
// any custom vitest config you require
})
```
That's it. Now when you run `vitest` your Nuxt environment will be available throughout your tests.
## 👉 Important notes
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`).
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).
## 🛠️ Helpers
`vitest-environment-nuxt` provides a number of helpers to make testing Nuxt apps easier.
### `mountSuspended`
// TODO:
### `mockNuxtImport`
`mockNuxtImport` allows you to mock Nuxt's auto import functionality. For example, to mock `useStorage`, you can do so like this:
```ts
import { mockNuxtImport } from 'vitest-environment-nuxt/utils'
mockNuxtImport('useStorage', () => {
return () => {
return { value: 'mocked storage' }
}
})
// your tests here
```
## 💻 Development

@@ -44,3 +82,3 @@

Published under [MIT License](./LICENCE).
Published under the [MIT License](./LICENCE).

@@ -53,5 +91,5 @@ <!-- Badges -->

[npm-downloads-href]: https://npmjs.com/package/vitest-environment-nuxt
[github-actions-src]: https://img.shields.io/github/workflow/status/danielroe/vitest-environment-nuxt/ci/main?style=flat-square
[github-actions-src]: https://img.shields.io/github/actions/workflow/status/danielroe/vitest-environment-nuxt/ci.yml?branch=main&style=flat-square
[github-actions-href]: https://github.com/danielroe/vitest-environment-nuxt/actions?query=workflow%3Aci
[codecov-src]: https://img.shields.io/codecov/c/gh/danielroe/vitest-environment-nuxt/main?style=flat-square
[codecov-href]: https://codecov.io/gh/danielroe/vitest-environment-nuxt

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc