Skip to content

Commit 1967515

Browse files
authored
test(NODE-3187): port unified test runner (#2783)
Adds typescript compilation for unified runner. Modified package scripts to align with 4.0 branch. CI steps needed to compile the runner. Fixes to bulk result to conform to spec.
1 parent 5d8f649 commit 1967515

File tree

320 files changed

+14377
-1627
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

320 files changed

+14377
-1627
lines changed

.eslintignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
test/functional/unified-spec-runner/*.js
2+
!test/functional/unified-spec-runner/unified-runner.test.js
3+
docs

.evergreen/install-dependencies.sh

+3
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ if [[ "$OS" == "Windows_NT" ]]; then
7575
root: $NVM_HOME
7676
path: $NVM_SYMLINK
7777
EOT
78+
nvm install 12
7879
nvm install $NODE_VERSION
7980
nvm use $NODE_VERSION
8081
which node || echo "node not found, PATH=$PATH"
@@ -86,7 +87,9 @@ EOT
8687
else
8788
curl -o- $NVM_URL | bash
8889
[ -s "${NVM_DIR}/nvm.sh" ] && \. "${NVM_DIR}/nvm.sh"
90+
nvm install --no-progress 12
8991
nvm install --no-progress $NODE_VERSION
92+
nvm use $NODE_VERSION
9093

9194
# setup npm cache in a local directory
9295
cat <<EOT > .npmrc

.evergreen/run-atlas-tests.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY}/node-artifacts"
77
export NVM_DIR="${NODE_ARTIFACTS_PATH}/nvm"
88
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
99

10-
npm run atlas
10+
npm run check:atlas

.evergreen/run-checks.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY}/node-artifacts"
66
export NVM_DIR="${NODE_ARTIFACTS_PATH}/nvm"
77
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
88

9-
npm run lint
9+
npm run check:lint

.evergreen/run-tests.sh

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ set -o errexit # Exit the script with error if any of the commands fail
88
# UNIFIED Set to enable the Unified SDAM topology for the node driver
99
# MONGODB_URI Set the suggested connection MONGODB_URI (including credentials and topology info)
1010
# MARCH Machine Architecture. Defaults to lowercase uname -m
11-
# TEST_NPM_SCRIPT Script to npm run. Defaults to "test-nolint"
11+
# TEST_NPM_SCRIPT Script to npm run. Defaults to "check:test"
1212
# SKIP_DEPS Skip installing dependencies
1313
# NO_EXIT Don't exit early from tests that leak resources
1414

1515
AUTH=${AUTH:-noauth}
1616
UNIFIED=${UNIFIED:-0}
1717
MONGODB_URI=${MONGODB_URI:-}
18-
TEST_NPM_SCRIPT=${TEST_NPM_SCRIPT:-test-nolint}
18+
TEST_NPM_SCRIPT=${TEST_NPM_SCRIPT:-"check:test"}
1919
if [[ -z "${NO_EXIT}" ]]; then
2020
TEST_NPM_SCRIPT="$TEST_NPM_SCRIPT -- --exit"
2121
fi
@@ -55,4 +55,8 @@ else
5555
npm install mongodb-client-encryption@latest
5656
fi
5757

58+
nvm use 12
59+
npm run build:unified
60+
nvm use "$NODE_VERSION"
61+
5862
MONGODB_UNIFIED_TOPOLOGY=${UNIFIED} MONGODB_URI=${MONGODB_URI} npm run ${TEST_NPM_SCRIPT}

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,7 @@ yarn.lock
5252

5353
.vscode
5454
output
55+
56+
# Unified Runner
57+
test/functional/unified-spec-runner/*.js
58+
!test/functional/unified-spec-runner/unified-runner.test.js

lib/bulk/common.js

+68
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,45 @@ class BulkWriteResult {
7171
this.result = bulkResult;
7272
}
7373

74+
/** Number of documents inserted. */
75+
get insertedCount() {
76+
return typeof this.result.nInserted !== 'number' ? 0 : this.result.nInserted;
77+
}
78+
/** Number of documents matched for update. */
79+
get matchedCount() {
80+
return typeof this.result.nMatched !== 'number' ? 0 : this.result.nMatched;
81+
}
82+
/** Number of documents modified. */
83+
get modifiedCount() {
84+
return typeof this.result.nModified !== 'number' ? 0 : this.result.nModified;
85+
}
86+
/** Number of documents deleted. */
87+
get deletedCount() {
88+
return typeof this.result.nRemoved !== 'number' ? 0 : this.result.nRemoved;
89+
}
90+
/** Number of documents upserted. */
91+
get upsertedCount() {
92+
return !this.result.upserted ? 0 : this.result.upserted.length;
93+
}
94+
95+
/** Upserted document generated Id's, hash key is the index of the originating operation */
96+
get upsertedIds() {
97+
const upserted = {};
98+
for (const doc of !this.result.upserted ? [] : this.result.upserted) {
99+
upserted[doc.index] = doc._id;
100+
}
101+
return upserted;
102+
}
103+
104+
/** Inserted document generated Id's, hash key is the index of the originating operation */
105+
get insertedIds() {
106+
const inserted = {};
107+
for (const doc of !this.result.insertedIds ? [] : this.result.insertedIds) {
108+
inserted[doc.index] = doc._id;
109+
}
110+
return inserted;
111+
}
112+
74113
/**
75114
* Evaluates to true if the bulk operation correctly executes
76115
* @type {boolean}
@@ -572,6 +611,35 @@ class BulkWriteError extends MongoError {
572611
this.name = 'BulkWriteError';
573612
this.result = result;
574613
}
614+
615+
/** Number of documents inserted. */
616+
get insertedCount() {
617+
return this.result.insertedCount;
618+
}
619+
/** Number of documents matched for update. */
620+
get matchedCount() {
621+
return this.result.matchedCount;
622+
}
623+
/** Number of documents modified. */
624+
get modifiedCount() {
625+
return this.result.modifiedCount;
626+
}
627+
/** Number of documents deleted. */
628+
get deletedCount() {
629+
return this.result.deletedCount;
630+
}
631+
/** Number of documents upserted. */
632+
get upsertedCount() {
633+
return this.result.upsertedCount;
634+
}
635+
/** Inserted document generated Id's, hash key is the index of the originating operation */
636+
get insertedIds() {
637+
return this.result.insertedIds;
638+
}
639+
/** Upserted document generated Id's, hash key is the index of the originating operation */
640+
get upsertedIds() {
641+
return this.result.upsertedIds;
642+
}
575643
}
576644

577645
/**

0 commit comments

Comments
 (0)