
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
@nifty-lil-tricks/testing-plugin-nestjs
Advanced tools
A nifty li'l plugin for setting up NestJS applications when testing
Note: this package is currently a work in progress
A nifty li'l plugin for setting up PostgreSQL database instances when testing
Note: this package works with TypeScript v5 or later
import { nestJsPlugin } from "@nifty-lil-tricks/testing-plugin-nestjs";
npm install @nifty-lil-tricks/testing-plugin-nestjs
The TypeScript tsconfig.json
must contain the following recommended settings:
{
"compilerOptions": {
"target": "ES2022",
"strict": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true
}
}
The following features are supported:
Setup a NestJS server as follows:
// Copyright 2023-2023 the Nifty li'l' tricks authors. All rights reserved. MIT license.
import { assertEquals } from "testing/asserts.ts";
import {
afterEach,
beforeEach,
describe,
it,
} from "testing/bdd.ts";
import {
setupTestsFactory,
type SetupTestsTeardown,
} from "@nifty-lil-tricks/testing";
import {
nestJsPlugin,
type PluginConfig,
} from "@nifty-lil-tricks/testing-plugin-nestjs";
import { Controller, Get, Module } from "npm:@nestjs/common@^10.2.7";
// In another file, load plugins as follows to generate a setupTests function:
const { setupTests } = setupTestsFactory({ server: nestJsPlugin });
// In another file, define a NestJS app as follows:
@Controller()
export class BasicAppController {
@Get("/hello")
getHello(): string {
return "Hello, world!";
}
}
@Module({
imports: [],
controllers: [BasicAppController],
})
export class BasicAppModule {}
// Then one can use this in any test file as follows:
describe("Service", () => {
let teardownTests: SetupTestsTeardown;
let origin: string;
beforeEach(async () => {
// Setup tests with configured plugins
const result = await setupTests({
server: {
appModule: BasicAppModule,
} as PluginConfig,
});
teardownTests = result.teardownTests;
origin = result.outputs.server.output.origin;
});
afterEach(async () => {
// Teardown tests to restore environment after tests have run
await teardownTests();
});
describe("method", () => {
it("should test something that relies on the nestjs plugin", async () => {
// Arrange & Act
const response = await fetch(new URL("/hello", origin));
// Assert
assertEquals(response.status, 200);
assertEquals(await response.text(), "Hello, world!");
});
});
});
One can also use define a NestJS app with testing overrides to allow one to mock out dependencies where needed. For example, module overrides:
// Copyright 2023-2023 the Nifty li'l' tricks authors. All rights reserved. MIT license.
import { assertEquals } from "testing/asserts.ts";
import {
afterEach,
beforeEach,
describe,
it,
} from "testing/bdd.ts";
import {
setupTestsFactory,
type SetupTestsTeardown,
} from "@nifty-lil-tricks/testing";
import {
nestJsPlugin,
type PluginConfig,
} from "@nifty-lil-tricks/testing-plugin-nestjs";
import { Controller, Get, Module } from "npm:@nestjs/common@^10.2.7";
// In another file, load plugins as follows to generate a setupTests function:
const { setupTests } = setupTestsFactory({ server: nestJsPlugin });
// In another file, define a NestJS app as follows:
@Controller()
export class BasicAppController {
@Get("/hello")
getHello(): string {
return "Hello, world!";
}
}
@Module({
imports: [],
controllers: [BasicAppController],
})
export class BasicAppModule {}
// In another file, define a NestJS app overrides for testing as follows:
@Controller()
class NewAppController {
@Get("/hello")
getHello(): string {
return "Ahoy!";
}
}
@Module({
controllers: [NewAppController],
})
class NewModule {}
// Then one can use this in any test file as follows:
describe("Service", () => {
let teardownTests: SetupTestsTeardown;
let origin: string;
beforeEach(async () => {
// Setup tests with configured plugins
const result = await setupTests({
server: {
appModule: BasicAppModule,
modules: [{
moduleToOverride: BasicAppModule,
newModule: NewModule,
}],
} as PluginConfig,
});
teardownTests = result.teardownTests;
origin = result.outputs.server.output.origin;
});
afterEach(async () => {
// Teardown tests to restore environment after tests have run
await teardownTests();
});
describe("method", () => {
it("should test something that relies on the nestjs plugin", async () => {
// Arrange & Act
const response = await fetch(new URL("/hello", origin));
// Assert
assertEquals(response.status, 200);
assertEquals(await response.text(), "Ahoy!");
});
});
});
The API Docs can be found here.
Examples can be found here.
Platform Version | Supported | Notes |
---|---|---|
Deno v1 | :white_check_mark: | |
Node.JS v18 | :white_check_mark: | TypeScript v5+ for typings |
Node.JS v20 | :white_check_mark: | TypeScript v5+ for typings |
Web Browsers | :x: | Coming soon |
Nifty li'l tricks nestjs package is 100% free and open-source, under the MIT license.
This package is Treeware. If you use it in production, then we ask that you buy the world a tree to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.
Contributions, issues and feature requests are very welcome. If you are using this package and fixed a bug for yourself, please consider submitting a PR!
FAQs
A nifty li'l plugin for setting up NestJS applications when testing
The npm package @nifty-lil-tricks/testing-plugin-nestjs receives a total of 28 weekly downloads. As such, @nifty-lil-tricks/testing-plugin-nestjs popularity was classified as not popular.
We found that @nifty-lil-tricks/testing-plugin-nestjs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.