Skip to content

Commit bfd4a57

Browse files
authored
fix(NODE-6772): bson-bench no longer depends on [email protected] (#31)
1 parent 28c334f commit bfd4a57

File tree

9 files changed

+30
-54
lines changed

9 files changed

+30
-54
lines changed

package-lock.json

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/bson-bench/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# bson-bench
22

3-
This library provides functionality to install and run benchmarks against bson and bson-ext.
3+
This library provides functionality to install and run benchmarks against bson.
44

55
> [!IMPORTANT]
66
> This library is **NOT** an official MongoDB product and is meant for internal use only

packages/bson-bench/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
"keywords": [],
1717
"author": "The MongoDB NodeJS Team <[email protected]>",
1818
"license": "Apache-2.0",
19-
"dependencies": {
20-
"bson": "4.7"
21-
},
2219
"directories": {
2320
"lib": "lib",
2421
"test": "test"
22+
},
23+
"devDependencies": {
24+
"bson": "4.7"
2525
}
2626
}

packages/bson-bench/src/base.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as BSON from 'bson';
21
import { readFileSync } from 'fs';
32
import { join } from 'path';
43
import { performance } from 'perf_hooks';
@@ -56,10 +55,7 @@ function run(bson: BSONLib | ConstructibleBSON, config: BenchmarkSpecification)
5655

5756
try {
5857
if (bson.EJSON) doc = bson.EJSON.parse(readFileSync(config.documentPath, 'utf8'));
59-
// NOTE: The BSON version used here is bson@4. This is for compatibility with bson-ext as it is
60-
// the only version of the js-bson library explicitly compatible with bson-ext and which does
61-
// not result in bson-ext throwing an error when running deserialization tests.
62-
else doc = BSON.EJSON.parse(readFileSync(config.documentPath, 'utf8'));
58+
else throw new Error('No EJSON parser found');
6359
} catch (cause) {
6460
reportErrorAndQuit(new Error('Failed to read test document', { cause }));
6561
return;

packages/bson-bench/src/common.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ import { join } from 'path';
55
import { exists } from './utils';
66

77
// handle normal npm package regex
8-
export const NPM_PACKAGE_REGEX = /(bson-ext|bson)@((\d+(\.\d+)?(\.\d+)?)|latest)/;
8+
export const NPM_PACKAGE_REGEX = /(bson)@((\d+(\.\d+)?(\.\d+)?)|latest)/;
99
// handle git tags/commits
10-
export const GIT_PACKAGE_REGEX = /(bson-ext|bson)#(.+)/;
10+
export const GIT_PACKAGE_REGEX = /(bson)#(.+)/;
1111
// handle local package
12-
export const LOCAL_PACKAGE_REGEX = /(bson-ext|bson):(.+)/;
12+
export const LOCAL_PACKAGE_REGEX = /(bson):(.+)/;
1313

1414
/**
15-
* The Package class represents the bson or bson-ext package to be tested
15+
* The Package class represents the bson package to be tested
1616
* This package can be an npm package, a git repository or a local package
1717
**/
1818
export class Package {
1919
type: 'npm' | 'git' | 'local';
2020
// bson library to install
21-
library: 'bson' | 'bson-ext';
21+
library: 'bson';
2222
computedModuleName: string;
2323
// semver version specification
2424
npmVersion?: string;
@@ -33,17 +33,17 @@ export class Package {
3333
let match: RegExpExecArray | null;
3434
if ((match = NPM_PACKAGE_REGEX.exec(libSpec))) {
3535
this.type = 'npm';
36-
this.library = match[1] as 'bson' | 'bson-ext';
36+
this.library = match[1] as 'bson';
3737
this.npmVersion = match[2];
3838
this.computedModuleName = `${this.library}-${this.npmVersion}`;
3939
} else if ((match = GIT_PACKAGE_REGEX.exec(libSpec))) {
4040
this.type = 'git';
41-
this.library = match[1] as 'bson' | 'bson-ext';
41+
this.library = match[1] as 'bson';
4242
this.gitCommitish = match[2];
4343
this.computedModuleName = `${this.library}-git-${this.gitCommitish}`;
4444
} else if ((match = LOCAL_PACKAGE_REGEX.exec(libSpec))) {
4545
this.type = 'local';
46-
this.library = match[1] as 'bson' | 'bson-ext';
46+
this.library = match[1] as 'bson';
4747

4848
this.localPath = match[2];
4949
const cleanedLocalPath = this.localPath.replaceAll('/', '_').replaceAll('\\', '_');
@@ -81,9 +81,6 @@ export class Package {
8181
case 'bson':
8282
source = `git://github.com/mongodb/js-bson#${this.gitCommitish}`;
8383
break;
84-
case 'bson-ext':
85-
source = `git://github.com/mongodb-js/bson-ext#${this.gitCommitish}`;
86-
break;
8784
}
8885
break;
8986
case 'local':
@@ -130,7 +127,7 @@ export type BenchmarkSpecification = {
130127
iterations: number;
131128
/** Number of iterations that will be run to warm up the V8 engine */
132129
warmup: number;
133-
/** Specifier of the bson or bson-ext library to be used. Can be an npm package, git repository or
130+
/** Specifier of the bson library to be used. Can be an npm package, git repository or
134131
* local package */
135132
library: string;
136133
installLocation?: string;

packages/bson-bench/src/task.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,8 @@ export class Task {
9898
break;
9999
// special cases
100100
case 'validation':
101-
// utf8 validation is always on for bson-ext
102-
output['utf8Validation'] = /^bson-ext/.test(this.benchmark.library)
103-
? 1
104-
: // if value of boolean for js-bson, convert to number, otherwise assume true
105-
typeof o[key]['utf8'] === 'boolean'
106-
? Number(o[key]['utf8'])
107-
: 1;
101+
output.utf8Validation =
102+
typeof o[key]['utf8'] === 'boolean' ? Number(o[key]['utf8']) : 1;
108103
break;
109104
default:
110105
output[key] =

packages/bson-bench/test/unit/common.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('common functionality', function () {
4444
});
4545
});
4646

47-
context('when trying to install an npm package apart from bson or bson-ext', function () {
47+
context('when trying to install an npm package apart from bson', function () {
4848
it('throws an error', function () {
4949
expect(() => new Package('[email protected]', installDir)).to.throw(
5050
Error,
@@ -53,7 +53,7 @@ describe('common functionality', function () {
5353
});
5454
});
5555

56-
context('when trying to install a git package apart from bson or bson-ext', function () {
56+
context('when trying to install a git package apart from bson', function () {
5757
it('throws an error', function () {
5858
expect(() => new Package('notBson#abcdabcdabcd', installDir)).to.throw(
5959
Error,
@@ -96,7 +96,7 @@ describe('common functionality', function () {
9696

9797
context('#install()', function () {
9898
context('when given a correctly formatted npm package that exists', function () {
99-
for (const lib of ['[email protected]', 'bson[email protected]', 'bson@latest', 'bson-ext@latest']) {
99+
for (const lib of ['[email protected]', 'bson@latest']) {
100100
it(`installs ${lib} successfully to the specified install directory`, async function () {
101101
const pack = new Package(lib, installDir);
102102
await pack.install();

packages/bson-bench/test/unit/task.test.ts

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,7 @@ describe('Task', function () {
2020

2121
const BSON_PATH = process.env.BSON_PATH;
2222
const BSON_EXT_PATH = process.env.BSON_EXT_PATH;
23-
const versions = [
24-
25-
26-
27-
28-
'bson#v6.1.0',
29-
`bson:${LOCAL_BSON}`,
30-
31-
'bson-ext#c1284d1'
32-
];
23+
const versions = ['[email protected]', '[email protected]', '[email protected]', 'bson#v6.1.0', `bson:${LOCAL_BSON}`];
3324
const operations: ('serialize' | 'deserialize')[] = ['serialize', 'deserialize'];
3425
if (BSON_PATH) versions.push(`bson:${BSON_PATH}`);
3526
if (BSON_EXT_PATH) versions.push(`bson:${BSON_EXT_PATH}`);
@@ -59,14 +50,6 @@ describe('Task', function () {
5950
});
6051

6152
it('completes successfully', async function () {
62-
if (
63-
Number(process.versions.node.split('.')[0]) >= 20 &&
64-
/bson-ext#.*/.test(test.library)
65-
) {
66-
console.log('Skipping installing bson-ext via git tag on Node 20');
67-
this.skip();
68-
}
69-
7053
await task.run();
7154
for (const child of task.children) {
7255
expect(child.exitCode).to.not.be.null;
@@ -76,7 +59,7 @@ describe('Task', function () {
7659

7760
it('strips the tag or commit from the test name', function () {
7861
expect(task.testName).to.not.include(test.library);
79-
expect(task.testName).to.match(/bson|bson-ext/);
62+
expect(task.testName).to.match(/bson/);
8063
});
8164
});
8265
}
@@ -323,7 +306,7 @@ describe('Task', function () {
323306
before(async () => {
324307
task = new Task({
325308
documentPath: 'test/documents/long_largeArray.json',
326-
library: 'bson[email protected]',
309+
library: 'bson@4',
327310
operation: 'deserialize',
328311
warmup: 100,
329312
iterations: 100,

packages/bson-bench/test/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import { exists } from '../src/utils';
66
export { exists } from '../src/utils';
77

88
/**
9-
* Remove all installed bson and bson-ext versions that have been installed by tests
9+
* Remove all installed bson versions that have been installed by tests
1010
*/
1111
export async function clearTestedDeps(installDir: string) {
1212
const targetDir = path.join(installDir, 'node_modules');
1313
if (await exists(targetDir))
1414
for await (const dirent of await fs.opendir(targetDir)) {
15-
if (/^(bson-ext|bson)-(git|local)?.*$/.test(dirent.name)) {
15+
if (/^(bson)-(git|local)?.*$/.test(dirent.name)) {
1616
await fs.rm(path.join(targetDir, dirent.name), {
1717
recursive: true,
1818
force: true

0 commit comments

Comments
 (0)