From cb4e98042a5014435d6ee762fc56fceec2313855 Mon Sep 17 00:00:00 2001 From: Tobias Davis Date: Sat, 15 Jun 2024 15:31:08 -0500 Subject: [PATCH] feature: testing in 18 and 20 --- .github/workflows/test.yml | 2 +- CHANGELOG.md | 1 + demo/demo.js | 21 ++++++++++++++++----- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1115817..6503162 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fa832e..f1da967 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/demo/demo.js b/demo/demo.js index cd6467b..d021d73 100644 --- a/demo/demo.js +++ b/demo/demo.js @@ -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 @@ -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) @@ -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.') @@ -201,10 +204,12 @@ const { insertedIds } = await db.insertMany({ { name: 'Bilbo Baggins', type: 'hobbit', + nodeVersion, }, { name: 'Samwise Gamgee', type: 'hobbit', + nodeVersion, }, ], }) @@ -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') @@ -234,6 +240,7 @@ console.log('db.updateMany') const out4 = await db.updateMany({ filter: { type: 'hobbit', + nodeVersion, }, update: { $set: { teaTime: true }, @@ -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') @@ -265,7 +273,7 @@ console.log('db.aggregate') const out6 = await db.aggregate({ pipeline: [ { - $match: { type: 'hobbit' }, + $match: { type: 'hobbit', nodeVersion }, }, { $sort: { name: 1 }, @@ -280,6 +288,7 @@ assert.deepStrictEqual( { name: 'Bilbo Baggins', type: 'hobbit', + nodeVersion, pipe: true, teaTime: true, age: '111', @@ -290,6 +299,7 @@ assert.deepStrictEqual( { name: 'Samwise Gamgee', type: 'hobbit', + nodeVersion, teaTime: true, }, ) @@ -309,7 +319,7 @@ const interposeDb = mongodb({ assert.deepStrictEqual( body, { - filter: { currentDate }, + filter: { currentDate, nodeVersion }, dataSource: 'BAD', database: 'BAD', collection: 'BAD', @@ -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)