Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
vitest-mongodb
Advanced tools
Run your tests with Vitest and MongoDB Memory server.
yarn add -D vitest-mongodb
npm i -D vitest-mongodb
pnpm i -D vitest-mongodb
An example project can be found at /example
.
// ./setup/mongo-memory-server.ts
import { afterAll, beforeAll } from "vitest";
import { setup, teardown } from "vitest-mongodb";
beforeAll(async () => {
await setup();
});
afterAll(async () => {
await teardown();
});
// vitest.config.ts
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
setupFiles: ["./setup/mongo-memory-server.ts"],
},
});
globalThis.__MONGO_URI__
global variable.import { MongoClient } from "mongodb";
import { it, expect } from "vitest";
it("connects to mongodb", () => {
expect(async () => {
const client = new MongoClient(globalThis.__MONGO_URI__);
try {
const db = client.db("test");
await db.command({ ping: 1 });
} finally {
await client.close();
}
}).not.toThrow();
});
The setup function provides some configuration options.
Setup Options:
type Options =
| {
type?: "default";
serverOptions?: Partial<MongoMemoryServerOpts>;
}
| {
type: "replSet";
serverOptions?: Partial<MongoMemoryReplSetOpts>;
};
Example: create a ReplSet
// ./setup/mongo-memory-server.ts
import { afterAll, beforeAll } from "vitest";
import { setup, teardown } from "vitest-mongodb";
beforeAll(async () => {
await setup({ type: "replSet", serverOptions: { replSet: { count: 4 } } });
});
afterAll(async () => {
await teardown();
});
To get __MONGO_URI__
on your globalThis
object, add the follow file:
// test/global.d.ts
declare var __MONGO_URI__: string;
These two packages are fairly similar with slightly different configuration.
The following is how to get the desired effect as jest-mongodb options.
useSharedDBForAllJestWorkers
: Run vitest with option --no-threads
so that the setup file is only called once.mongoURLEnvName
: No plans to implement.FAQs
Run your tests using Vitest and MongoDB in Memory server.
The npm package vitest-mongodb receives a total of 4,696 weekly downloads. As such, vitest-mongodb popularity was classified as popular.
We found that vitest-mongodb demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.