From 065facdc536fe041f2a2944b484381faa39234d1 Mon Sep 17 00:00:00 2001 From: Frans Bouwmeester Date: Sat, 30 Oct 2021 19:19:54 +0200 Subject: [PATCH] test: fix failing tests on 4.x LTS branch (#7661) --- package-lock.json | 9 +++++++++ package.json | 1 + spec/ParseLiveQuery.spec.js | 4 ++-- spec/ParseUser.spec.js | 9 ++++++--- spec/helper.js | 5 +++++ spec/support/CurrentSpecReporter.js | 15 +++++++++++++++ 6 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 spec/support/CurrentSpecReporter.js diff --git a/package-lock.json b/package-lock.json index 96fcc70b41..887686a2d5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8338,6 +8338,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 12874fce61..83e9fd4651 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 e4ace5045f..906d5daf02 100644 --- a/spec/ParseLiveQuery.spec.js +++ b/spec/ParseLiveQuery.spec.js @@ -949,7 +949,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 +968,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(); } diff --git a/spec/ParseUser.spec.js b/spec/ParseUser.spec.js index 18ab1657b7..6c02cae7cf 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 a7f6cf2280..d9e9b77797 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 0000000000..3158e21eae --- /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;