Skip to content

Commit

Permalink
feature: testing in 18 and 20
Browse files Browse the repository at this point in the history
  • Loading branch information
saibotsivad committed Jun 17, 2024
1 parent 532d527 commit cb4e980
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 16.x ]
node-version: [ 16.x, 18.x, 20.x ]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Change categories are:
### Added
- Support for Web API [Headers](https://developer.mozilla.org/en-US/docs/Web/API/Headers),
so you can use the global `fetch` as-is.
- Updated tests to run against Node.js version 18 and 20 as well as 16 (original).
### Fixed
- Type for option parameters had `cluster` instead of `dataSource`, which was a breaking
change in `1.0.0`. Types are now fixed. Closes #3
Expand Down
21 changes: 16 additions & 5 deletions demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import assert from 'node:assert/strict'
import { mongodb } from '../dist/index.mjs'
import { fetch } from './fetch-shim.js'

const nodeVersion = process.version

const apiUrl = process.env.MONGODB_API_URL
const apiKey = process.env.MONGODB_API_KEY
const dataSource = process.env.MONGODB_CLUSTER_NAME
Expand Down Expand Up @@ -154,7 +156,7 @@ for (const { description, success, initialize, overrides } of differentWaysToSet
}
let result
try {
result = await testingDb.insertOne({ document: { description } }, overrides)
result = await testingDb.insertOne({ document: { description, nodeVersion } }, overrides)
} catch (error) {
if (success) {
console.error(error)
Expand All @@ -174,6 +176,7 @@ console.log('db.insertOne')
const { insertedId } = await db.insertOne({
document: {
name: 'Bilbo Baggins',
nodeVersion,
},
})
assert.ok(insertedId, 'The document was correctly inserted.')
Expand Down Expand Up @@ -201,10 +204,12 @@ const { insertedIds } = await db.insertMany({
{
name: 'Bilbo Baggins',
type: 'hobbit',
nodeVersion,
},
{
name: 'Samwise Gamgee',
type: 'hobbit',
nodeVersion,
},
],
})
Expand All @@ -214,6 +219,7 @@ console.log('db.find')
const { documents } = await db.find({
filter: {
type: 'hobbit',
nodeVersion,
},
})
assert.equal(documents.length, 2, 'Found both documents')
Expand All @@ -234,6 +240,7 @@ console.log('db.updateMany')
const out4 = await db.updateMany({
filter: {
type: 'hobbit',
nodeVersion,
},
update: {
$set: { teaTime: true },
Expand All @@ -247,6 +254,7 @@ const { documents: updatedHobbits } = await db.find({
filter: {
type: 'hobbit',
name: 'Bilbo Baggins',
nodeVersion,
},
})
assert.equal(updatedHobbits.length, 1, 'Found one document')
Expand All @@ -265,7 +273,7 @@ console.log('db.aggregate')
const out6 = await db.aggregate({
pipeline: [
{
$match: { type: 'hobbit' },
$match: { type: 'hobbit', nodeVersion },
},
{
$sort: { name: 1 },
Expand All @@ -280,6 +288,7 @@ assert.deepStrictEqual(
{
name: 'Bilbo Baggins',
type: 'hobbit',
nodeVersion,
pipe: true,
teaTime: true,
age: '111',
Expand All @@ -290,6 +299,7 @@ assert.deepStrictEqual(
{
name: 'Samwise Gamgee',
type: 'hobbit',
nodeVersion,
teaTime: true,
},
)
Expand All @@ -309,7 +319,7 @@ const interposeDb = mongodb({
assert.deepStrictEqual(
body,
{
filter: { currentDate },
filter: { currentDate, nodeVersion },
dataSource: 'BAD',
database: 'BAD',
collection: 'BAD',
Expand All @@ -328,16 +338,17 @@ const interposeDb = mongodb({
}
},
})
const interposed = await interposeDb.findOne({ filter: { currentDate } })
const interposed = await interposeDb.findOne({ filter: { currentDate, nodeVersion } })
assert.equal(interposed.document.type, 'hobbit', 'original query would not have found it but modified did')

console.log('db.deleteMany')
const out99 = await db.deleteMany({
filter: {
type: 'hobbit',
nodeVersion,
},
})
assert.equal(out99.deletedCount, 2, 'Deleted both documents.')

const shouldBeEmpty = await db.find({ filter: {} })
const shouldBeEmpty = await db.find({ filter: { nodeVersion } })
assert.equal(shouldBeEmpty.documents.length, 0)

0 comments on commit cb4e980

Please sign in to comment.