From dcd5823a17f21a932d36317f25dd3b91d37710c5 Mon Sep 17 00:00:00 2001 From: Christian Walther Date: Mon, 23 Sep 2019 11:47:53 +0200 Subject: [PATCH 1/2] Fix concurrent tests. Running jest runs the two test suites in parallel. If both try to run a server on port 3000, only one of them will succeed and supply files for both, however when that suite finishes first, it will take down the server and leave the other one hanging. Fix this by running the servers on different ports. --- integration/widget.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integration/widget.test.js b/integration/widget.test.js index dd838ac..2362b9a 100644 --- a/integration/widget.test.js +++ b/integration/widget.test.js @@ -3,14 +3,14 @@ const express = require('express'); const puppeteer = require('puppeteer') -const rootUrl = "http://localhost:3000/"; +const rootUrl = "http://localhost:3001/"; jest.setTimeout(500000); const server = new Promise( resolve => { let app = require( '../src/server' )({ directory: path.join( __dirname, '..' ) }); let server; - server = app.listen( 3000, () => resolve(server) ); + server = app.listen( 3001, () => resolve(server) ); }).catch( e => console.log(e) ); const browser = puppeteer.launch({ headless: false }); From 07e4c13530099658866ae069092aa79014567e33 Mon Sep 17 00:00:00 2001 From: Christian Walther Date: Tue, 24 Sep 2019 14:50:17 +0200 Subject: [PATCH 2/2] Make tests faster by avoiding unnecessary waiting. Puppeteer allows us to wait for the specific element we want to check instead of waiting for a fixed time and hoping it will be there by then. This reduces the total testing time from 26s to 7s for me. --- integration/basic.test.js | 8 ++++---- integration/widget.test.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/integration/basic.test.js b/integration/basic.test.js index 11b01de..2f6a8e8 100644 --- a/integration/basic.test.js +++ b/integration/basic.test.js @@ -40,7 +40,7 @@ test('resolve #definitions in non-root schema', async () => { await page.goto( rootUrl + "#/integration/schemas/def-non-root/User.json"); - await page.waitFor(5000); + await page.waitFor('#doc .box .box .box .signature:nth-child(6) .property-name'); await expect( page.evaluate( () => Array.from(document.querySelectorAll('.property-name').values()).map( s => s.innerText ) ) @@ -55,7 +55,7 @@ test('local schema, absolute path', async () => { await page.goto( rootUrl + "#/integration/schemas/local-absolute/main.json"); - await page.waitFor(5000); + await page.waitFor('#doc .box .box .desc'); await expect( page.evaluate( () => Array.from(document.querySelectorAll('.desc').values()).map( s => s.innerText ) ) @@ -70,7 +70,7 @@ test('recursive schemas', async () => { await page.goto( rootUrl + "#/integration/schemas/recursive/circle.json"); - await page.waitFor(5000); + await page.waitFor('#doc .box .box .box .desc'); await expect( page.evaluate( () => Array.from(document.querySelectorAll('.desc').values()).map( s => s.innerText ) ) @@ -84,7 +84,7 @@ test('recursive schemas, part II', async () => { const page = await ( await browser ).newPage(); await page.goto( rootUrl + "#/integration/schemas/recursive/within_schema.json"); - await page.waitFor(5000); + await page.waitFor('#doc .box .desc p'); let results = await page.evaluate( () => Array.from(document.querySelectorAll('p').values()).map( s => s.innerText ) ); diff --git a/integration/widget.test.js b/integration/widget.test.js index 2362b9a..7aea0bf 100644 --- a/integration/widget.test.js +++ b/integration/widget.test.js @@ -31,7 +31,7 @@ test( 'basic', async () => { let frames = await page.frames(); - await page.waitFor(2000); + await frames[1].waitFor('.title'); let title = await frames[1].evaluate( () => document.querySelector('.title').innerText