diff --git a/integration/test/ParseCloudTest.js b/integration/test/ParseCloudTest.js index e99845974..ca5a4ae7f 100644 --- a/integration/test/ParseCloudTest.js +++ b/integration/test/ParseCloudTest.js @@ -4,6 +4,16 @@ const assert = require('assert'); const Parse = require('../../node'); const sleep = require('./sleep'); +const waitForJobStatus = async (jobStatusId, status) => { + const checkJobStatus = async () => { + const result = await Parse.Cloud.getJobStatus(jobStatusId); + return result && result.get('status') === status; + }; + while (!(await checkJobStatus())) { + await sleep(100); + } +}; + describe('Parse Cloud', () => { it('run function', done => { const params = { key1: 'value2', key2: 'value1' }; @@ -86,14 +96,8 @@ describe('Parse Cloud', () => { it('run job', async () => { const params = { startedBy: 'Monty Python' }; const jobStatusId = await Parse.Cloud.startJob('CloudJob1', params); + await waitForJobStatus(jobStatusId, 'succeeded'); - const checkJobStatus = async () => { - const result = await Parse.Cloud.getJobStatus(jobStatusId); - return result && result.get('status') === 'succeeded'; - }; - while (!(await checkJobStatus())) { - await sleep(100); - } const jobStatus = await Parse.Cloud.getJobStatus(jobStatusId); assert.equal(jobStatus.get('status'), 'succeeded'); assert.equal(jobStatus.get('params').startedBy, 'Monty Python'); @@ -104,14 +108,8 @@ describe('Parse Cloud', () => { let jobStatus = await Parse.Cloud.getJobStatus(jobStatusId); assert.equal(jobStatus.get('status'), 'running'); + await waitForJobStatus(jobStatusId, 'succeeded'); - const checkJobStatus = async () => { - const result = await Parse.Cloud.getJobStatus(jobStatusId); - return result && result.get('status') === 'succeeded'; - }; - while (!(await checkJobStatus())) { - await sleep(100); - } jobStatus = await Parse.Cloud.getJobStatus(jobStatusId); assert.equal(jobStatus.get('status'), 'succeeded'); }); @@ -126,16 +124,13 @@ describe('Parse Cloud', () => { }); }); - it('run failing job', done => { - Parse.Cloud.startJob('CloudJobFailing') - .then(jobStatusId => { - return Parse.Cloud.getJobStatus(jobStatusId); - }) - .then(jobStatus => { - assert.equal(jobStatus.get('status'), 'failed'); - assert.equal(jobStatus.get('message'), 'cloud job failed'); - done(); - }); + it('run failing job', async () => { + const jobStatusId = await Parse.Cloud.startJob('CloudJobFailing'); + await waitForJobStatus(jobStatusId, 'failed'); + + const jobStatus = await Parse.Cloud.getJobStatus(jobStatusId); + assert.equal(jobStatus.get('status'), 'failed'); + assert.equal(jobStatus.get('message'), 'cloud job failed'); }); it('get jobs data', done => { diff --git a/integration/test/ParseDistTest.js b/integration/test/ParseDistTest.js index 7beb32ab8..d3fa39db5 100644 --- a/integration/test/ParseDistTest.js +++ b/integration/test/ParseDistTest.js @@ -1,12 +1,19 @@ const puppeteer = require('puppeteer'); +let browser = null; let page = null; for (const fileName of ['parse.js', 'parse.min.js']) { - beforeAll(async () => { - const browser = await puppeteer.launch(); - page = await browser.newPage(); - await page.goto(`http://localhost:1337/${fileName}`); - }); describe(`Parse Dist Test ${fileName}`, () => { + beforeEach(async () => { + browser = await puppeteer.launch(); + page = await browser.newPage(); + await page.goto(`http://localhost:1337/${fileName}`); + }); + + afterEach(async () => { + await page.close(); + await browser.close(); + }); + it('can save an object', async () => { const response = await page.evaluate(async () => { const object = await new Parse.Object('TestObject').save(); @@ -17,6 +24,7 @@ for (const fileName of ['parse.js', 'parse.min.js']) { expect(obj).toBeDefined(); expect(obj.id).toEqual(response); }); + it('can query an object', async () => { const obj = await new Parse.Object('TestObject').save(); const response = await page.evaluate(async () => { diff --git a/integration/test/helper.js b/integration/test/helper.js index f2af3020d..61b159d8c 100644 --- a/integration/test/helper.js +++ b/integration/test/helper.js @@ -166,11 +166,14 @@ beforeAll(async () => { afterEach(async () => { await Parse.User.logOut(); + // Connection close events are not immediate on node 10+... wait a bit + await sleep(0); + if (Object.keys(openConnections).length > 0) { + console.warn('There were open connections to the server left after the test finished'); + } Parse.Storage._clear(); await TestUtils.destroyAllDataPermanently(true); destroyAliveConnections(); - // Connection close events are not immediate on node 10+... wait a bit - await sleep(0); if (didChangeConfiguration) { await reconfigureServer(); }