Skip to content

Commit 65b2d12

Browse files
authored
Merge pull request #15400 from hasezoey/lintChanges
General minor test and lint changes
2 parents dc536d1 + 8032f3b commit 65b2d12

18 files changed

+64
-180
lines changed

.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ module.exports = {
77
ignorePatterns: [
88
'tools',
99
'dist',
10-
'website.js',
1110
'test/files/*',
1211
'benchmarks',
1312
'*.min.js',

.github/workflows/documentation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
- 'website.js'
1111
- 'CHANGELOG.md'
1212
push:
13-
branches:ubuntu
13+
branches:
1414
- master
1515
paths:
1616
- '.github/workflows/documentation.yml'

.github/workflows/test.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,7 @@ jobs:
8787
- name: Setup node
8888
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
8989
with:
90-
<<<<<<< HEAD
9190
node-version: 22
92-
=======
93-
node-version: 20
94-
>>>>>>> 7.x
9591
- name: Load MongoDB binary cache
9692
id: cache-mongodb-binaries
9793
uses: actions/cache@v4
@@ -119,11 +115,7 @@ jobs:
119115
- name: Setup node
120116
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
121117
with:
122-
<<<<<<< HEAD
123118
node-version: 22
124-
=======
125-
node-version: 20
126-
>>>>>>> 7.x
127119
- run: npm install
128120
- name: Test
129121
run: npm run test-rs

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ index.html
5959
# yarn package-lock
6060
yarn.lock
6161

62+
# deno lock
63+
deno.lock
64+
6265
# npm pack output
6366
mongoose.tgz
6467
mongoose-*.tgz

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
"mongo": "node ./tools/repl.js",
102102
"publish-7x": "npm publish --tag 7x",
103103
"test": "mocha --exit ./test/*.test.js",
104-
"test-deno": "deno run --allow-env --allow-read --allow-net --allow-run --allow-sys --allow-write ./test/deno.js",
104+
"test-deno": "deno run --allow-env --allow-read --allow-net --allow-run --allow-sys --allow-write ./test/deno.mjs",
105105
"test-rs": "START_REPLICA_SET=1 mocha --timeout 30000 --exit ./test/*.test.js",
106106
"test-tsd": "node ./test/types/check-types-filename && tsd",
107107
"setup-test-encryption": "bash scripts/configure-cluster-with-encryption.sh",

scripts/website.js

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const path = require('path');
99
const pug = require('pug');
1010
const pkg = require('../package.json');
1111
const transform = require('acquit-require');
12-
const childProcess = require("child_process");
12+
const childProcess = require('child_process');
1313

1414
// using "__dirname" and ".." to have a consistent CWD, this script should not be runnable, even when not being in the root of the project
1515
// also a consistent root path so that it is easy to change later when the script should be moved
@@ -183,8 +183,8 @@ function parseVersion(str) {
183183

184184
const match = versionReg.exec(str);
185185

186-
if (!!match) {
187-
const parsed = [parseInt(match[1]), parseInt(match[2]), parseInt(match[3])]
186+
if (match) {
187+
const parsed = [parseInt(match[1]), parseInt(match[2]), parseInt(match[3])];
188188

189189
// fallback just in case some number did not parse
190190
if (Number.isNaN(parsed[0]) || Number.isNaN(parsed[1]) || Number.isNaN(parsed[2])) {
@@ -195,7 +195,7 @@ function parseVersion(str) {
195195
}
196196

197197
// special case, to not log a warning
198-
if (str === "test") {
198+
if (str === 'test') {
199199
return undefined;
200200
}
201201

@@ -210,27 +210,27 @@ function parseVersion(str) {
210210
function getVersions() {
211211
// get all tags from git
212212
// "trim" is used to remove the ending new-line
213-
const res = childProcess.execSync("git tag").toString().trim();
213+
const res = childProcess.execSync('git tag').toString().trim();
214214

215215
filteredTags = res.split('\n')
216216
// map all gotten tags if they match the regular expression
217-
.map(parseVersion)
217+
.map(parseVersion)
218218
// filter out all null / undefined / falsy values
219-
.filter(v => !!v)
219+
.filter(v => !!v)
220220
// sort tags with latest (highest) first
221-
.sort((a, b) => {
222-
if (a[0] === b[0]) {
223-
if (a[1] === b[1]) {
224-
return b[2] - a[2];
221+
.sort((a, b) => {
222+
if (a[0] === b[0]) {
223+
if (a[1] === b[1]) {
224+
return b[2] - a[2];
225+
}
226+
return b[1] - a[1];
225227
}
226-
return b[1] - a[1];
227-
}
228-
return b[0] - a[0];
229-
});
228+
return b[0] - a[0];
229+
});
230230

231231
if (filteredTags.length === 0) {
232-
console.error("no tags found!");
233-
filteredTags.push([0,0,0]);
232+
console.error('no tags found!');
233+
filteredTags.push([0, 0, 0]);
234234
}
235235
}
236236

@@ -269,7 +269,7 @@ function getLatestVersionOf(version) {
269269
foundVersion = [0, 0, 0];
270270
}
271271

272-
return {listed: stringifySemverNumber(foundVersion), path: stringifySemverNumber(foundVersion, true)};
272+
return { listed: stringifySemverNumber(foundVersion), path: stringifySemverNumber(foundVersion, true) };
273273
}
274274

275275
/**
@@ -281,11 +281,11 @@ function getCurrentVersion() {
281281

282282
// i dont think this will ever happen, but just in case
283283
if (!pkg.version) {
284-
console.log("no version from package?");
284+
console.log('no version from package?');
285285
versionToUse = getLatestVersion();
286286
}
287287

288-
return {listed: versionToUse, path: stringifySemverNumber(parseVersion(versionToUse), true) };
288+
return { listed: versionToUse, path: stringifySemverNumber(parseVersion(versionToUse), true) };
289289
}
290290

291291
// execute function to get all tags from git
@@ -314,7 +314,7 @@ const versionObj = (() => {
314314
getLatestVersionOf(6)
315315
]
316316
};
317-
const versionedDeploy = !!process.env.DOCS_DEPLOY ? !(base.currentVersion.listed === base.latestVersion.listed) : false;
317+
const versionedDeploy = process.env.DOCS_DEPLOY ? !(base.currentVersion.listed === base.latestVersion.listed) : false;
318318

319319
const versionedPath = versionedDeploy ? `/docs/${base.currentVersion.path}` : '';
320320

@@ -380,20 +380,20 @@ function mapURLs(block, currentUrl) {
380380
while ((match = mongooseComRegex.exec(block)) !== null) {
381381
// console.log("match", match);
382382
// cant just use "match.index" byitself, because of the extra "href=\"" condition, which is not factored in in "match.index"
383-
let startIndex = match.index + match[0].length - match[1].length;
383+
const startIndex = match.index + match[0].length - match[1].length;
384384
out += block.slice(lastIndex, startIndex);
385385
lastIndex = startIndex + match[1].length;
386386

387387
// somewhat primitive gathering of the url, but should be enough for now
388-
let fullUrl = /^\/[^"]+/.exec(block.slice(lastIndex-1));
388+
const fullUrl = /^\/[^"]+/.exec(block.slice(lastIndex - 1));
389389

390390
let noPrefix = false;
391391

392392
if (fullUrl) {
393393
// extra processing to only use "#otherId" instead of using full url for the same page
394394
// at least firefox does not make a difference between a full path and just "#", but it makes debugging paths easier
395395
if (fullUrl[0].startsWith(currentUrl)) {
396-
let indexMatch = /#/.exec(fullUrl);
396+
const indexMatch = /#/.exec(fullUrl);
397397

398398
if (indexMatch) {
399399
lastIndex += indexMatch.index - 1;
@@ -404,10 +404,10 @@ function mapURLs(block, currentUrl) {
404404

405405
if (!noPrefix) {
406406
// map all to the versioned-path, unless a explicit version is given
407-
if (!versionedDocs.test(block.slice(lastIndex, lastIndex+10))) {
408-
out += versionObj.versionedPath + "/";
407+
if (!versionedDocs.test(block.slice(lastIndex, lastIndex + 10))) {
408+
out += versionObj.versionedPath + '/';
409409
} else {
410-
out += "/";
410+
out += '/';
411411
}
412412
}
413413
}
@@ -429,7 +429,7 @@ async function pugify(filename, options, isReload = false) {
429429
let newfile = undefined;
430430
options = options || {};
431431
options.package = pkg;
432-
const isAPI = options.api && !filename.endsWith('docs/api.pug');
432+
// const isAPI = options.api && !filename.endsWith('docs/api.pug');
433433

434434
const _editLink = 'https://github.com/Automattic/mongoose/blob/master' +
435435
filename.replace(cwd, '');
@@ -443,7 +443,7 @@ async function pugify(filename, options, isReload = false) {
443443
if (isReload) {
444444
apiReq.parseFile(options.file);
445445
// overwrite original options because of reload
446-
options = {...options, ...apiReq.docs.get(options.file)};
446+
options = { ...options, ...apiReq.docs.get(options.file) };
447447
}
448448
inputFile = path.resolve(cwd, 'docs/api_split.pug');
449449
}
@@ -453,7 +453,7 @@ async function pugify(filename, options, isReload = false) {
453453
if (options.acquit) {
454454
contents = transform(contents, getTests());
455455

456-
contents = contents.replaceAll(/^```acquit$/gmi, "```javascript");
456+
contents = contents.replaceAll(/^```acquit$/gmi, '```javascript');
457457
}
458458
if (options.markdown) {
459459
const lines = contents.split('\n');
@@ -486,7 +486,7 @@ async function pugify(filename, options, isReload = false) {
486486

487487
if (versionObj.versionedDeploy) {
488488
newfile = path.resolve(cwd, path.join('.', versionObj.versionedPath), path.relative(cwd, newfile));
489-
await fs.promises.mkdir(path.dirname(newfile), {recursive:true});
489+
await fs.promises.mkdir(path.dirname(newfile), { recursive: true });
490490
}
491491

492492
options.outputUrl = newfile.replace(cwd, '');
@@ -497,11 +497,11 @@ async function pugify(filename, options, isReload = false) {
497497

498498
let str = await pugRender(contents, options).catch(console.error);
499499

500-
if (typeof str !== "string") {
500+
if (typeof str !== 'string') {
501501
return;
502502
}
503503

504-
str = mapURLs(str, '/' + path.relative(cwd, docsPath))
504+
str = mapURLs(str, '/' + path.relative(cwd, docsPath));
505505

506506
await fs.promises.writeFile(newfile, str).catch((err) => {
507507
console.error('could not write', err.stack);
@@ -534,20 +534,20 @@ function startWatch() {
534534
}
535535
});
536536

537-
fs.watchFile(path.join(cwd, 'docs/api_split.pug'), {interval: 1000}, (cur, prev) => {
537+
fs.watchFile(path.join(cwd, 'docs/api_split.pug'), { interval: 1000 }, (cur, prev) => {
538538
if (cur.mtime > prev.mtime) {
539539
console.log('docs/api_split.pug modified, reloading all api files');
540-
Promise.all(files.filter(v=> v.startsWith('docs/api')).map(async (file) => {
540+
Promise.all(files.filter(v => v.startsWith('docs/api')).map(async(file) => {
541541
const filename = path.join(cwd, file);
542542
await pugify(filename, docsFilemap.fileMap[file], true);
543543
}));
544544
}
545545
});
546546

547-
fs.watchFile(path.join(cwd, 'docs/api_split.pug'), {interval: 1000}, (cur, prev) => {
547+
fs.watchFile(path.join(cwd, 'docs/api_split.pug'), { interval: 1000 }, (cur, prev) => {
548548
if (cur.mtime > prev.mtime) {
549549
console.log('docs/api_split.pug modified, reloading all api files');
550-
Promise.all(files.filter(v=> v.startsWith('docs/api')).map(async (file) => {
550+
Promise.all(files.filter(v => v.startsWith('docs/api')).map(async(file) => {
551551
const filename = path.join(cwd, file);
552552
await pugify(filename, docsFilemap.fileMap[file]);
553553
}));
@@ -561,7 +561,7 @@ function startWatch() {
561561
* @param {Boolean} isReload Indicate this is a reload of all files
562562
*/
563563
async function pugifyAllFiles(noWatch, isReload = false) {
564-
await Promise.all(files.map(async (file) => {
564+
await Promise.all(files.map(async(file) => {
565565
const filename = path.join(cwd, file);
566566
await pugify(filename, docsFilemap.fileMap[file], isReload);
567567
}));
@@ -590,7 +590,7 @@ async function copyAllRequiredFiles() {
590590
await Promise.all(pathsToCopy.map(async v => {
591591
const resultPath = path.resolve(cwd, path.join('.', versionObj.versionedPath, v));
592592
await fsextra.copy(v, resultPath);
593-
}))
593+
}));
594594
}
595595

596596
exports.default = pugify;
@@ -626,7 +626,10 @@ if (isMain) {
626626
}
627627

628628
console.log('Done Processing');
629-
})();
629+
})().catch((err) => {
630+
console.error('Website Generation failed:', err);
631+
process.exit(-1);
632+
});
630633
}
631634

632635
// Modified from github-slugger

test/.eslintrc.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ rules:
44
# In `document.test.js` we sometimes use self assignment to test setters
55
no-self-assign: off
66
ignorePatterns:
7-
- deno.js
8-
- deno*.js
7+
- deno*.mjs

test/aggregate.test.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -817,12 +817,6 @@ describe('aggregate: ', function() {
817817

818818
it('explain()', async function() {
819819
const aggregate = new Aggregate([], db.model('Employee'));
820-
const version = await start.mongodVersion();
821-
822-
const mongo26 = version[0] > 2 || (version[0] === 2 && version[1] >= 6);
823-
if (!mongo26) {
824-
return;
825-
}
826820

827821
const output = await aggregate.
828822
match({ sal: { $lt: 16000 } }).
@@ -868,16 +862,13 @@ describe('aggregate: ', function() {
868862
const match = { $match: { sal: { $gt: 15000 } } };
869863
const pref = 'primaryPreferred';
870864
const aggregate = m.aggregate([match]).read(pref);
871-
const mongo26_or_greater = version[0] > 2 || (version[0] === 2 && version[1] >= 6);
872865
const mongo32_or_greater = version[0] > 3 || (version[0] === 3 && version[1] >= 2);
873866

874867
assert.equal(aggregate.options.readPreference.mode, pref);
875-
if (mongo26_or_greater) {
876-
aggregate.allowDiskUse(true);
877-
aggregate.option({ maxTimeMS: 1000 });
878-
assert.equal(aggregate.options.allowDiskUse, true);
879-
assert.equal(aggregate.options.maxTimeMS, 1000);
880-
}
868+
aggregate.allowDiskUse(true);
869+
aggregate.option({ maxTimeMS: 1000 });
870+
assert.equal(aggregate.options.allowDiskUse, true);
871+
assert.equal(aggregate.options.maxTimeMS, 1000);
881872

882873
if (mongo32_or_greater) {
883874
aggregate.readConcern('m');

test/browser/.eslintrc.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/deno.js renamed to test/deno.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ await fixtures.mochaGlobalSetup();
1717

1818
const child_args = [
1919
...Deno.args,
20-
resolve(fileURLToPath(import.meta.url), '../deno_mocha.js')
20+
resolve(fileURLToPath(import.meta.url), '../deno_mocha.mjs')
2121
];
2222

2323
const child = spawn(process.execPath, child_args, { stdio: 'inherit' });

0 commit comments

Comments
 (0)