diff --git a/package-lock.json b/package-lock.json index ddbe60a9e4d..b4f702f3880 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8328,6 +8328,15 @@ "integrity": "sha512-nCeAiw37MIMA9w9IXso7bRaLl+c/ef3wnxsoSAlYrzS+Ot0zTG6nU8G/cIfGkqpkjX2wNaIW9RFG0TwIFnG6bA==", "dev": true }, + "jasmine-spec-reporter": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/jasmine-spec-reporter/-/jasmine-spec-reporter-7.0.0.tgz", + "integrity": "sha512-OtC7JRasiTcjsaCBPtMO0Tl8glCejM4J4/dNuOJdA8lBjz4PmWjYQ6pzb0uzpBNAWJMDudYuj9OdXJWqM2QTJg==", + "dev": true, + "requires": { + "colors": "1.4.0" + } + }, "jmespath": { "version": "0.15.0", "resolved": "https://registry.npmjs.org/jmespath/-/jmespath-0.15.0.tgz", diff --git a/package.json b/package.json index d69f97d4254..5b1da0c3463 100644 --- a/package.json +++ b/package.json @@ -84,6 +84,7 @@ "form-data": "3.0.0", "husky": "4.2.5", "jasmine": "3.5.0", + "jasmine-spec-reporter": "7.0.0", "jsdoc": "3.6.7", "jsdoc-babel": "0.5.0", "lint-staged": "10.2.3", diff --git a/spec/ParseLiveQuery.spec.js b/spec/ParseLiveQuery.spec.js index e4ace5045f8..08f047b4a55 100644 --- a/spec/ParseLiveQuery.spec.js +++ b/spec/ParseLiveQuery.spec.js @@ -310,14 +310,10 @@ describe('ParseLiveQuery', function () { Parse.Cloud.afterLiveQueryEvent('TestObject', req => { const current = req.object; const original = req.original; - - setTimeout(() => { - done(); - }, 2000); - if (current.get('foo') != original.get('foo')) { req.sendEvent = false; } + setTimeout(done, 1000); }); const query = new Parse.Query(TestObject); @@ -733,9 +729,7 @@ describe('ParseLiveQuery', function () { }); object.set({ foo: 'bar' }); await object.save(); - setTimeout(async () => { - done(); - }, 1000); + setTimeout(done, 1000); }); it('can return a new beforeSubscribe query', async done => { @@ -922,9 +916,9 @@ describe('ParseLiveQuery', function () { }); await obj1.save(); await Parse.User.logOut(); - await new Promise(resolve => setTimeout(resolve, 200)); + await new Promise(resolve => setTimeout(resolve, 100)); await obj2.save(); - await new Promise(resolve => setTimeout(resolve, 200)); + await new Promise(resolve => setTimeout(resolve, 100)); done(); }); @@ -949,7 +943,7 @@ describe('ParseLiveQuery', function () { const response = (obj, prev) => { expect(obj.get('sessionToken')).toBeUndefined(); expect(obj.sessionToken).toBeUndefined(); - expect(prev?.sessionToken).toBeUndefined(); + expect(prev && prev.sessionToken).toBeUndefined(); if (prev && prev.get) { expect(prev.get('sessionToken')).toBeUndefined(); } @@ -968,7 +962,7 @@ describe('ParseLiveQuery', function () { user.set('yolo', 'bar'); await user.save(); await user.destroy(); - await new Promise(resolve => process.nextTick(resolve)); + await new Promise(resolve => setTimeout(resolve, 10)); for (const key of events) { expect(calls[key]).toHaveBeenCalled(); } @@ -978,8 +972,6 @@ describe('ParseLiveQuery', function () { const client = await Parse.CoreManager.getLiveQueryController().getDefaultLiveQueryClient(); client.close(); // Wait for live query client to disconnect - setTimeout(() => { - done(); - }, 1000); + setTimeout(done, 10); }); }); diff --git a/spec/ParseUser.spec.js b/spec/ParseUser.spec.js index 18ab1657b7b..6c02cae7cf3 100644 --- a/spec/ParseUser.spec.js +++ b/spec/ParseUser.spec.js @@ -3948,7 +3948,7 @@ describe('Parse.User testing', () => { const response = (obj, prev) => { expect(obj.get('authData')).toBeUndefined(); expect(obj.authData).toBeUndefined(); - expect(prev?.authData).toBeUndefined(); + expect(prev && prev.authData).toBeUndefined(); if (prev && prev.get) { expect(prev.get('authData')).toBeUndefined(); } @@ -3960,7 +3960,6 @@ describe('Parse.User testing', () => { subscription.on(key, calls[key]); } const user = await Parse.User._logInWith('facebook'); - user.set('foo', 'bar'); await user.save(); user.unset('foo'); @@ -3968,10 +3967,14 @@ describe('Parse.User testing', () => { user.set('yolo', 'bar'); await user.save(); await user.destroy(); - await new Promise(resolve => process.nextTick(resolve)); + await new Promise(resolve => setTimeout(resolve, 10)); for (const key of events) { expect(calls[key]).toHaveBeenCalled(); } + subscription.unsubscribe(); + const client = await Parse.CoreManager.getLiveQueryController().getDefaultLiveQueryClient(); + client.close(); + await new Promise(resolve => setTimeout(resolve, 10)); }); describe('issue #4897', () => { diff --git a/spec/helper.js b/spec/helper.js index a7f6cf22805..d9e9b77797c 100644 --- a/spec/helper.js +++ b/spec/helper.js @@ -1,6 +1,11 @@ 'use strict'; +const CurrentSpecReporter = require('./support/CurrentSpecReporter.js'); +const { SpecReporter } = require('jasmine-spec-reporter'); + // Sets up a Parse API server for testing. jasmine.DEFAULT_TIMEOUT_INTERVAL = process.env.PARSE_SERVER_TEST_TIMEOUT || 5000; +jasmine.getEnv().addReporter(new CurrentSpecReporter()); +jasmine.getEnv().addReporter(new SpecReporter()); global.on_db = (db, callback, elseCallback) => { if (process.env.PARSE_SERVER_TEST_DB == db) { diff --git a/spec/support/CurrentSpecReporter.js b/spec/support/CurrentSpecReporter.js new file mode 100644 index 00000000000..3158e21eae2 --- /dev/null +++ b/spec/support/CurrentSpecReporter.js @@ -0,0 +1,15 @@ +// Sets a global variable to the current test spec +// ex: global.currentSpec.description + +global.currentSpec = null; + +class CurrentSpecReporter { + specStarted(spec) { + global.currentSpec = spec; + } + specDone() { + global.currentSpec = null; + } +} + +module.exports = CurrentSpecReporter;