vitest-mms
Advanced tools
Comparing version 0.1.7 to 0.1.8
@@ -6,3 +6,2 @@ import { MongoClient, Db } from 'mongodb'; | ||
declare const globalContextSymbol: unique symbol; | ||
declare module "vitest" { | ||
@@ -14,3 +13,1 @@ interface TestContext { | ||
} | ||
export { globalContextSymbol }; |
{ | ||
"name": "vitest-mms", | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"description": "mongodb-memory-server integration for vitest", | ||
@@ -20,2 +20,7 @@ "exports": { | ||
"import": "./dist/mmsTest.mjs" | ||
}, | ||
"./mongoose/setupFile": { | ||
"types": "./dist/mongoose/setupFile.d.ts", | ||
"require": "./dist/mongoose/setupFile.cjs", | ||
"import": "./dist/mongoose/setupFile.mjs" | ||
} | ||
@@ -47,4 +52,9 @@ }, | ||
}, | ||
"optionalDependencies": { | ||
"mongoose": "*", | ||
"mongodb": "*" | ||
}, | ||
"peerDependencies": { | ||
"mongodb": "*", | ||
"mongoose": "*", | ||
"mongodb-memory-server": "*", | ||
@@ -51,0 +61,0 @@ "vitest": "*" |
@@ -132,1 +132,35 @@ # vitest-mms [![NPM Version](https://img.shields.io/npm/v/vitest-mms)](https://www.npmjs.com/package/vitest-mms) | ||
``` | ||
## Usage with mongoose | ||
```js | ||
// vitest.config.mjs | ||
import { defineConfig } from "vitest/config"; | ||
export default defineConfig({ | ||
test: { | ||
globalSetup: ["vitest-mms/globalSetup"], | ||
setupFile: ["vitest-mms/mongoose/setupFile"], | ||
}, | ||
}); | ||
``` | ||
```json | ||
// tsconfig.json | ||
{ | ||
"compilerOptions": { | ||
"types": ["vitest-mms/mongoose/setupFile"] | ||
} | ||
} | ||
``` | ||
```js | ||
// index.test.js | ||
test("my test", async ({ mongoose }) => { | ||
mongoose.connection.db; // use db | ||
const User = mongoose.model("User", new mongoose.Schema({ name: String })); | ||
await User.create({ name: "John" }); | ||
expect(await User.countDocuments()).toBe(1); | ||
}); | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
11419
15
161
166
6