diff --git a/integration/basic.test.js b/integration/basic.test.js index 11b01de..14ee919 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 .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 dd838ac..7aea0bf 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 }); @@ -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 diff --git a/src/index.js b/src/index.js index 5e40ba4..7425060 100644 --- a/src/index.js +++ b/src/index.js @@ -53,7 +53,7 @@ const highlight = false; try { content = JSON.parse(content); } catch(e) { - console.error("Unable to parse "+segments[0], e); + console.error("Unable to parse "+url, e, content); content = {}; } } @@ -540,8 +540,10 @@ const highlight = false; uri.normalize(); - // use the normalized uri - parentObject.update( uri.toString() ); + // use the normalized uri, unless it's empty (which happens when item == "#" and baseUrl is empty) + if (uri.toString()) { + parentObject.update( uri.toString() ); + } debug(get_ref(uri)); get_ref( uri ).finally( () => { @@ -572,6 +574,7 @@ const highlight = false; return Promise.all(p).finally(); }; + schemaDocuments[baseUrl] = Promise.resolve(schema); resolveRefsReentrant(schema).finally( throttled_render ).then( resolve_d ).catch( e => console.log('oops', e ) ); }) return d.finally( throttled_render );