4.2.0 • Published 20 days ago

testcontainers-mongoose v4.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
20 days ago

Testcontainers-mongoose

Node.js CI NPM version

a mongoose helper for using testcontainers with mongodb

https://www.npmjs.com/package/testcontainers-mongoose

Installation

npm i -D testcontainers-mongoose

if using mongoose 7.x version

npm i -D testcontainers-mongoose@2.2.2

Configuration

Reference

Logs

  • DEBUG=testcontainers Enable testcontainers logs
  • DEBUG=testcontainers:containers Enable container logs
  • DEBUG=testcontainers* Enable all logs

Testcontainers

  • TESTCONTAINERS_RYUK_DISABLED=true Disable ryuk
  • RYUK_CONTAINER_IMAGE=registry.mycompany.com/mirror/ryuk:0.3.0 Custom image for ryuk

Usage

Testing with Vitest

import * as dbHandler from 'testcontainers-mongoose'
import { describe, beforeAll, afterAll, afterEach, it, expect } from 'vitest'

describe('testcontainers-mongoose test', () => {
  beforeAll(async () => {
    await dbHandler.connect('harbor.yourcompany.com/mongo:4.4.4')
    // ...
  })
  afterAll(async () => {
    await dbHandler.closeDatabase()
  })

  afterEach(async () => {
    await dbHandler.clearDatabase()
  })

  it('some test using mongoose', async () => {
    // ...
  })
})

Start Mongo Container without connect with mongoose

In case you want to connect the mongo by yourself

using startedMongoTestContainerOf

Get the mongo connection string by .getUri()

Example

import { startedMongoTestContainerOf, StartedMongoTestContainer } from 'testcontainers-mongoose'
import { describe, beforeAll, afterAll, afterEach, it, expect } from 'vitest'

describe('testcontainers-mongoose test', () => {
  let mongoTestContainer: StartedMongoTestContainer
  beforeAll(async () => {
    mongoTestContainer = await startedMongoTestContainerOf('harbor.yourcompany.com/mongo:4.4.4')
    // connect to mongoTestContainer by yourself
    // mongoTestContainer.getUri() is the connection string of the mongo container
  })
  afterAll(async () => {
    await mongoTestContainer.closeDatabase()
  })

  afterEach(async () => {
    await mongoTestContainer.clearDatabase()
  })

  it('some test case', async () => {
    // ...
  })
})
4.2.0

20 days ago

4.1.6

29 days ago

4.1.4

2 months ago

4.1.3

4 months ago

4.1.2

4 months ago

4.1.1

5 months ago

4.1.0

5 months ago

4.0.0

5 months ago

3.0.2

5 months ago

3.0.1

6 months ago

2.2.1

7 months ago

2.2.2

6 months ago

3.0.0

6 months ago

2.1.2

8 months ago

2.0.3

10 months ago

2.2.0

8 months ago

2.1.1

8 months ago

2.0.2

11 months ago

2.1.4

8 months ago

2.1.3

8 months ago

2.0.4

10 months ago

2.1.6

8 months ago

2.1.5

8 months ago

2.1.7

8 months ago

2.1.0

8 months ago

1.1.1

1 year ago

2.0.1

12 months ago

2.0.0

1 year ago

1.1.0

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.2.3

2 years ago

0.2.0

2 years ago

0.2.2

2 years ago

0.1.3

2 years ago

0.1.0

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago