@codspeed/vitest-plugin>=3.1.0
CodSpeedHQ/codspeed-nestjs-mongodb
repository.
It uses the following technologies:
Cat
model is defined:
CatsController
exposes the following endpoints:
swc
and vitest
with nest-js
, follow the
setup guide on the NestJS website.
At the end of this setup, you should be able to run e2e tests with a running
MongoDB instance, using the following command:
vite-tsconfig-paths
is used to resolve the paths defined in the
tsconfig.json
file automatically.
Rename the file vitest.config.e2e.ts
to vitest.config.e2e.mts
since
@codspeed/vitest-plugin
is only available in ESM. Apply the following
modifications to the file:
*.e2e.spec.ts
file,
we can create a benchmark in a *.e2e.bench.ts
file.
cats
endpoints:
GET /cats
: retrieve all the catsGET /cats/name/:name
: retrieve all the cats with the given nameGET /cats/breed/:breed
: retrieve all the cats with the given breedGET /cats/age/greater/:age
: retrieve all the cats with an age greater than
the given ageexpect
in the benchmarks.package.json
:
testcontainers
to start a
MongoDB instance dynamically during the benchmarks.
For this setup, we assume that the state of the application is similar to the
one described in the above section.
testcontainers
dependencies:
src/global.d.ts
with the following content:
globalThis.__MONGO_URI__
variable available in the whole
application with the correct type.⚠️ Make sure to use var
and not let
or const
, as otherwise the TypeScript
type will not be set.src/testUtils/setup-vitest.ts
with the following content:
testcontainers
on macOSOn macOS, we recommend using colima
to
run Docker containers. However there are
issues using testcontainers
on macOS.
To bypass those issues, some environment variables need to be set when running
the tests:Enforce a check that the correct environment variables are set
testcontainers
work on macOS with colima
, the following environment variables need to be set:vitest
. Add the following function to your src/testUtils/setup-vitest.ts
file:setupMongoDB
function:setupFiles
entry in vite.config.e2e.mts
:
src/app.module.ts
file to use the
globalThis.__MONGO_URI__
variable instead of the MONGO_URL
environment
variable when it is defined:
codspeed.yml
file to the following:
mongodb-cluster-action
stepmongo-uri-env-name
inputMONGO_URI
environment variable