diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8edfff05c8c..89da7ec2a4a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -91,6 +91,23 @@ jobs: with: name: coverage path: coverage + + test-deno: + runs-on: ubuntu-latest + name: Deno tests + steps: + - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2 + - name: Setup node + uses: actions/setup-node@2fddd8803e2f5c9604345a0b591c3020ee971a93 # v3.4.1 + with: + node-version: 16 + - name: Setup Deno + uses: actions/setup-deno #v1 + with: + deno-version: v1.25.x + - run: npm install + - name: Run Deno tests + run: npm run test-deno test-replica-sets: needs: diff --git a/lib/schematype.js b/lib/schematype.js index 0cc6c3eea59..837719a32a9 100644 --- a/lib/schematype.js +++ b/lib/schematype.js @@ -56,7 +56,7 @@ function SchemaType(path, options, instance) { const defaultOptionsKeys = Object.keys(defaultOptions); for (const option of defaultOptionsKeys) { - if (defaultOptions.hasOwnProperty(option) && !options.hasOwnProperty(option)) { + if (defaultOptions.hasOwnProperty(option) && !Object.prototype.hasOwnProperty.call(options, option)) { options[option] = defaultOptions[option]; } } diff --git a/package.json b/package.json index 2767c008775..3360a3ccc8c 100644 --- a/package.json +++ b/package.json @@ -94,6 +94,7 @@ "release-legacy": "git pull origin 5.x && git push origin 5.x --tags && npm publish --tag legacy", "mongo": "node ./tools/repl.js", "test": "mocha --exit ./test/*.test.js", + "test-deno": "deno run --allow-env --allow-read --allow-net --allow-run --unstable ./test/deno.js", "test-rs": "START_REPLICA_SET=1 mocha --timeout 30000 --exit ./test/*.test.js", "test-tsd": "node ./test/types/check-types-filename && tsd", "tdd": "mocha ./test/*.test.js --inspect --watch --recursive --watch-files ./**/*.{js,ts}", diff --git a/test/deno.js b/test/deno.js new file mode 100644 index 00000000000..a13618ae410 --- /dev/null +++ b/test/deno.js @@ -0,0 +1,33 @@ +'use strict'; + +import { createRequire } from "https://deno.land/std/node/module.ts"; + +import { parse } from "https://deno.land/std/flags/mod.ts" +const args = parse(Deno.args); + +const require = createRequire(import.meta.url); + +const Mocha = require('mocha'); +const fs = require('fs'); +const path = require('path'); + +const mocha = new Mocha({ + ...(args.g ? { fgrep: '' + args.g } : {}) +}); + +const testDir = 'test'; +const files = fs.readdirSync(testDir); + +const ignoreFiles = new Set(['browser.test.js', 'connection.test.js', 'index.test.js']); + +for (const file of files) { + if (!file.endsWith('.test.js') || ignoreFiles.has(file)) { + continue; + } + + mocha.addFile(path.join(testDir, file)); +} + +mocha.run(function(failures) { + process.exitCode = failures ? 1 : 0; // exit with non-zero status if there were failures +}); \ No newline at end of file diff --git a/test/docs/lean.test.js b/test/docs/lean.test.js index 49cd0c45aad..576d8bcdcf3 100644 --- a/test/docs/lean.test.js +++ b/test/docs/lean.test.js @@ -1,7 +1,6 @@ 'use strict'; const assert = require('assert'); -const v8Serialize = require('v8').serialize; const start = require('../common'); // This file is in `es-next` because it uses async/await for convenience @@ -23,6 +22,12 @@ describe('Lean Tutorial', function() { }); it('compare sizes lean vs not lean', async function() { + // acquit:ignore:start + if (typeof Deno !== 'undefined') { + return this.skip(); // Deno does not support v8.serialize() + } + const v8Serialize = require('v8').serialize; + // acquit:ignore:end const schema = new mongoose.Schema({ name: String }); const MyModel = mongoose.model('Test', schema); diff --git a/test/query.test.js b/test/query.test.js index d357d256001..fc1ad0b4080 100644 --- a/test/query.test.js +++ b/test/query.test.js @@ -2339,6 +2339,13 @@ describe('Query', function() { }); it('throw on sync exceptions in callbacks (gh-6178)', function(done) { + // Deno doesn't support 'uncaughtException', so there's no way to test this in Deno + // without starting a separate process. + // See: https://stackoverflow.com/questions/64871554/deno-how-to-handle-exceptions + if (typeof Deno !== 'undefined') { + return this.skip(); + } + const schema = new Schema({}); const Test = db.model('Test', schema); diff --git a/test/schema.subdocumentpath.test.js b/test/schema.subdocumentpath.test.js index d7a131ab5c3..60d4a1e2f3c 100644 --- a/test/schema.subdocumentpath.test.js +++ b/test/schema.subdocumentpath.test.js @@ -179,7 +179,7 @@ describe('SubdocumentPath', function() { assert.ok(err); assert.ok(err.errors['nested']); - mongoose.Schema.Types.Subdocument.set('required', false); + delete mongoose.Schema.Types.Subdocument.defaultOptions.required; }); it('supports setting _id globally (gh-11541) (gh-8883)', function() { @@ -197,6 +197,5 @@ describe('SubdocumentPath', function() { assert.ok(!doc.nested._id); delete mongoose.Schema.Types.Subdocument.defaultOptions._id; - mongoose.Schema.Types.Subdocument.set('required', false); }); }); diff --git a/test/schema.test.js b/test/schema.test.js index c09895de3b3..0a994b87398 100644 --- a/test/schema.test.js +++ b/test/schema.test.js @@ -1178,6 +1178,11 @@ describe('schema', function() { describe('other contexts', function() { it('work', function(done) { + if (typeof Deno !== 'undefined') { + // Deno throws "Not implemented: Script.prototype.runInNewContext" + return this.skip(); + } + const str = 'code = {' + ' name: String' + ', arr1: Array ' + diff --git a/test/schematype.test.js b/test/schematype.test.js index 6b96bde4377..6e07390a2bc 100644 --- a/test/schematype.test.js +++ b/test/schematype.test.js @@ -224,6 +224,8 @@ describe('schematype', function() { // Assert assert.equal(schema.path('test').options.someRandomOption, true); + + delete type.defaultOptions.someRandomOption; }); }); });