From e102f147c2500c966aa42f3fa3ccb4346e854208 Mon Sep 17 00:00:00 2001 From: Sergey Zelenov Date: Mon, 13 Oct 2025 13:06:25 +0200 Subject: [PATCH 1/3] test(NODE-7196): migrate to typescript --- .../crud/{unicode.test.js => unicode.test.ts} | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) rename test/integration/crud/{unicode.test.js => unicode.test.ts} (87%) diff --git a/test/integration/crud/unicode.test.js b/test/integration/crud/unicode.test.ts similarity index 87% rename from test/integration/crud/unicode.test.js rename to test/integration/crud/unicode.test.ts index ab39df20fb0..aa358aa0e3f 100644 --- a/test/integration/crud/unicode.test.js +++ b/test/integration/crud/unicode.test.ts @@ -1,9 +1,9 @@ -'use strict'; -const semver = require('semver'); -const { assert: test, setupDatabase } = require('../shared'); -const { expect } = require('chai'); +import { expect } from 'chai'; +import * as semver from 'semver'; -describe('Unicode', function () { +import { assert as test, setupDatabase } from '../shared'; + +describe.only('Unicode', function () { before(function () { return setupDatabase(this.configuration); }); @@ -19,11 +19,11 @@ describe('Unicode', function () { this.skip(); } - var configuration = this.configuration; - var client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 }); + const configuration = this.configuration; + const client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 }); client.connect(function (err, client) { - var db = client.db(configuration.db); - var doc = { + const db = client.db(configuration.db); + const doc = { statuses_count: 1687, created_at: 'Mon Oct 22 14:55:08 +0000 2007', description: 'NodeJS hacker, Cofounder of Debuggable, CakePHP core alumnus', @@ -120,12 +120,12 @@ describe('Unicode', function () { }, test: function (done) { - var object = { 客家话: 'Hello' }; + const object = { 客家话: 'Hello' }; - var configuration = this.configuration; - var client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 }); + const configuration = this.configuration; + const client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 }); client.connect(function (err, client) { - var db = client.db(configuration.db); + const db = client.db(configuration.db); db.createCollection('create_object_with_chinese_object_name', function (err) { expect(err).to.not.exist; const collection = db.collection('create_object_with_chinese_object_name'); @@ -151,10 +151,10 @@ describe('Unicode', function () { }, test: function (done) { - var configuration = this.configuration; - var client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 }); + const configuration = this.configuration; + const client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 }); client.connect(function (err, client) { - var db = client.db(configuration.db); + const db = client.db(configuration.db); db.createCollection('test_utf8_key_name', function (err, collection) { collection.insert({ šđžčćŠĐŽČĆ: 1 }, { writeConcern: { w: 1 } }, function (err) { expect(err).to.not.exist; From 638b5e9b8c7ed3e9f527c28b6bc45ea6a3d5af04 Mon Sep 17 00:00:00 2001 From: Sergey Zelenov Date: Mon, 13 Oct 2025 13:21:20 +0200 Subject: [PATCH 2/3] test(NODE-7196): migrate to async/await --- test/integration/crud/unicode.test.ts | 247 ++++++++++---------------- 1 file changed, 95 insertions(+), 152 deletions(-) diff --git a/test/integration/crud/unicode.test.ts b/test/integration/crud/unicode.test.ts index aa358aa0e3f..36ef18df91d 100644 --- a/test/integration/crud/unicode.test.ts +++ b/test/integration/crud/unicode.test.ts @@ -1,174 +1,117 @@ import { expect } from 'chai'; -import * as semver from 'semver'; +import { satisfies } from 'semver'; +import type { MongoClient } from '../../../src'; import { assert as test, setupDatabase } from '../shared'; -describe.only('Unicode', function () { +describe('Unicode', function () { + let client: MongoClient; + before(function () { return setupDatabase(this.configuration); }); - it('shouldCorrectlyInsertUnicodeContainingDocument', { - metadata: { - requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } - }, + beforeEach(async function () { + client = this.configuration.newClient(); + }); - test: function (done) { - if (semver.satisfies(process.versions.node, '22.7.0')) { - this.skipReason = 'Node.js 22.7.0 has a UTF-8 encoding bug'; - this.skip(); - } + afterEach(async function () { + await client?.close(); + }); - const configuration = this.configuration; - const client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 }); - client.connect(function (err, client) { - const db = client.db(configuration.db); - const doc = { - statuses_count: 1687, - created_at: 'Mon Oct 22 14:55:08 +0000 2007', - description: 'NodeJS hacker, Cofounder of Debuggable, CakePHP core alumnus', - favourites_count: 6, - profile_sidebar_fill_color: 'EADEAA', - screen_name: 'felixge', - status: { - created_at: 'Fri Mar 12 08:59:44 +0000 2010', - in_reply_to_screen_name: null, - truncated: false, - in_reply_to_user_id: null, - source: 'Tweetie', - favorited: false, - in_reply_to_status_id: null, - id: 10364119169, - text: '#berlin #snow = #fail : (' - }, - contributors_enabled: false, - following: null, - geo_enabled: false, - time_zone: 'Eastern Time (US & Canada)', - profile_sidebar_border_color: 'D9B17E', - url: 'http://debuggable.com', - verified: false, - location: 'Berlin', - profile_text_color: '333333', - notifications: null, - profile_background_image_url: - 'http://s.twimg.com/a/1268354287/images/themes/theme8/bg.gif', - protected: false, - profile_link_color: '9D582E', - followers_count: 840, - name: 'Felix Geisend\u00f6rfer', - profile_background_tile: false, - id: 9599342, - lang: 'en', - utc_offset: -18000, - friends_count: 450, - profile_background_color: '8B542B', - profile_image_url: - 'http://a3.twimg.com/profile_images/107142257/passbild-square_normal.jpg' - }; + it('shouldCorrectlyInsertUnicodeContainingDocument', async function () { + if (satisfies(process.versions.node, '22.7.0')) { + this.skipReason = 'Node.js 22.7.0 has a UTF-8 encoding bug'; + this.skip(); + } - db.createCollection( - 'test_should_correctly_insert_unicode_containing_document', - function (err, collection) { - doc['_id'] = 'felixge'; + const configuration = this.configuration; + const db = client.db(configuration.db); + const doc = { + statuses_count: 1687, + created_at: 'Mon Oct 22 14:55:08 +0000 2007', + description: 'NodeJS hacker, Cofounder of Debuggable, CakePHP core alumnus', + favourites_count: 6, + profile_sidebar_fill_color: 'EADEAA', + screen_name: 'felixge', + status: { + created_at: 'Fri Mar 12 08:59:44 +0000 2010', + in_reply_to_screen_name: null, + truncated: false, + in_reply_to_user_id: null, + source: 'Tweetie', + favorited: false, + in_reply_to_status_id: null, + id: 10364119169, + text: '#berlin #snow = #fail : (' + }, + contributors_enabled: false, + following: null, + geo_enabled: false, + time_zone: 'Eastern Time (US & Canada)', + profile_sidebar_border_color: 'D9B17E', + url: 'http://debuggable.com', + verified: false, + location: 'Berlin', + profile_text_color: '333333', + notifications: null, + profile_background_image_url: 'http://s.twimg.com/a/1268354287/images/themes/theme8/bg.gif', + protected: false, + profile_link_color: '9D582E', + followers_count: 840, + name: 'Felix Geisend\u00f6rfer', + profile_background_tile: false, + id: 9599342, + lang: 'en', + utc_offset: -18000, + friends_count: 450, + profile_background_color: '8B542B', + profile_image_url: 'http://a3.twimg.com/profile_images/107142257/passbild-square_normal.jpg' + }; - collection.insertOne(doc, { writeConcern: { w: 1 } }, function (err) { - expect(err).to.not.exist; - collection.findOne(function (err, doc) { - test.equal('felixge', doc._id); - client.close(done); - }); - }); - } - ); - }); - } - }); + const collection = await db.createCollection( + 'test_should_correctly_insert_unicode_containing_document' + ); + doc['_id'] = 'felixge'; - it('should Correctly Insert Unicode Characters', function (done) { - const client = this.configuration.newClient(this.configuration.writeConcernMax(), { - maxPoolSize: 1 - }); - client.connect((err, client) => { - expect(err).to.not.exist; - const db = client.db(this.configuration.db); - db.createCollection('unicode_test_collection', (err, collection) => { - expect(err).to.not.exist; - const test_strings = ['ouooueauiOUOOUEAUI', 'öüóőúéáűíÖÜÓŐÚÉÁŰÍ', '本荘由利地域に洪水警報']; - collection.insert({ id: 0, text: test_strings[0] }, { writeConcern: { w: 1 } }, err => { - expect(err).to.not.exist; - collection.insert({ id: 1, text: test_strings[1] }, { writeConcern: { w: 1 } }, err => { - expect(err).to.not.exist; - collection.find().forEach( - doc => { - expect(doc).property('text').to.equal(test_strings[doc.id]); - }, - err => { - expect(err).to.not.exist; - client.close(done); - } - ); - }); - }); - }); - }); + await collection.insertOne(doc, { writeConcern: { w: 1 } }); + const document = await collection.findOne(); + test.equal('felixge', document._id); }); - it('shouldCreateObjectWithChineseObjectName', { - metadata: { - requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } - }, + it('should Correctly Insert Unicode Characters', async function () { + const db = client.db(this.configuration.db); + const collection = await db.createCollection('unicode_test_collection'); + const test_strings = ['ouooueauiOUOOUEAUI', 'öüóőúéáűíÖÜÓŐÚÉÁŰÍ', '本荘由利地域に洪水警報']; + await collection.insertOne({ id: 0, text: test_strings[0] }, { writeConcern: { w: 1 } }); + await collection.insertOne({ id: 1, text: test_strings[1] }, { writeConcern: { w: 1 } }); - test: function (done) { - const object = { 客家话: 'Hello' }; + const documents = await collection.find().toArray(); + expect(documents[0]).property('text').to.equal(test_strings[documents[0].id]); + expect(documents[1]).property('text').to.equal(test_strings[documents[1].id]); + }); - const configuration = this.configuration; - const client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 }); - client.connect(function (err, client) { - const db = client.db(configuration.db); - db.createCollection('create_object_with_chinese_object_name', function (err) { - expect(err).to.not.exist; - const collection = db.collection('create_object_with_chinese_object_name'); - collection.insert(object, { writeConcern: { w: 1 } }, function (err) { - expect(err).to.not.exist; - collection.findOne(function (err, item) { - test.equal(object['客家话'], item['客家话']); + it('shouldCreateObjectWithChineseObjectName', async function () { + const object = { 客家话: 'Hello' }; - collection.find().toArray(function (err, items) { - test.equal(object['客家话'], items[0]['客家话']); - client.close(done); - }); - }); - }); - }); - }); - } - }); + const configuration = this.configuration; + const db = client.db(configuration.db); + await db.createCollection('create_object_with_chinese_object_name'); + const collection = db.collection('create_object_with_chinese_object_name'); + await collection.insertOne(object, { writeConcern: { w: 1 } }); + const item = await collection.findOne(); + test.equal(object['客家话'], item['客家话']); - it('shouldCorrectlyHandleUT8KeyNames', { - metadata: { - requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } - }, + const items = await collection.find().toArray(); + test.equal(object['客家话'], items[0]['客家话']); + }); - test: function (done) { - const configuration = this.configuration; - const client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 }); - client.connect(function (err, client) { - const db = client.db(configuration.db); - db.createCollection('test_utf8_key_name', function (err, collection) { - collection.insert({ šđžčćŠĐŽČĆ: 1 }, { writeConcern: { w: 1 } }, function (err) { - expect(err).to.not.exist; - collection - .find({}) - .project({ šđžčćŠĐŽČĆ: 1 }) - .toArray(function (err, items) { - test.equal(1, items[0]['šđžčćŠĐŽČĆ']); - // Let's close the db - client.close(done); - }); - }); - }); - }); - } + it('shouldCorrectlyHandleUT8KeyNames', async function () { + const configuration = this.configuration; + const db = client.db(configuration.db); + const collection = await db.createCollection('test_utf8_key_name'); + await collection.insertOne({ šđžčćŠĐŽČĆ: 1 }, { writeConcern: { w: 1 } }); + const items = await collection.find({}).project({ šđžčćŠĐŽČĆ: 1 }).toArray(); + test.equal(1, items[0]['šđžčćŠĐŽČĆ']); }); }); From 8c9bfde0413810ad6eed6a492a69cdcaad623bbc Mon Sep 17 00:00:00 2001 From: Sergey Zelenov Date: Mon, 13 Oct 2025 13:27:27 +0200 Subject: [PATCH 3/3] test(NODE-7196): use common format for test names --- test/integration/crud/unicode.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/integration/crud/unicode.test.ts b/test/integration/crud/unicode.test.ts index 36ef18df91d..eec67a8c520 100644 --- a/test/integration/crud/unicode.test.ts +++ b/test/integration/crud/unicode.test.ts @@ -19,7 +19,7 @@ describe('Unicode', function () { await client?.close(); }); - it('shouldCorrectlyInsertUnicodeContainingDocument', async function () { + it('should correctly insert unicode containing document', async function () { if (satisfies(process.versions.node, '22.7.0')) { this.skipReason = 'Node.js 22.7.0 has a UTF-8 encoding bug'; this.skip(); @@ -79,7 +79,7 @@ describe('Unicode', function () { test.equal('felixge', document._id); }); - it('should Correctly Insert Unicode Characters', async function () { + it('should correctly insert unicode characters', async function () { const db = client.db(this.configuration.db); const collection = await db.createCollection('unicode_test_collection'); const test_strings = ['ouooueauiOUOOUEAUI', 'öüóőúéáűíÖÜÓŐÚÉÁŰÍ', '本荘由利地域に洪水警報']; @@ -91,7 +91,7 @@ describe('Unicode', function () { expect(documents[1]).property('text').to.equal(test_strings[documents[1].id]); }); - it('shouldCreateObjectWithChineseObjectName', async function () { + it('should create object with Chinese object name', async function () { const object = { 客家话: 'Hello' }; const configuration = this.configuration; @@ -106,7 +106,7 @@ describe('Unicode', function () { test.equal(object['客家话'], items[0]['客家话']); }); - it('shouldCorrectlyHandleUT8KeyNames', async function () { + it('should correctly handle UTF8 key names', async function () { const configuration = this.configuration; const db = client.db(configuration.db); const collection = await db.createCollection('test_utf8_key_name');