diff --git a/package.json b/package.json index 6fbbd8933..526356609 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "test": "npm run test:unit && npm run test:browser", "test:unit": "cross-env CI=true jest --coverage --testPathIgnorePatterns=test/browser/*", "test:browser": "npm run build:browser && cross-env CI=true jest -- ./test/browser/*", - "test:browser_new": "npm run build:browser_new && cross-env CI=true jest -- ./test/browser_new/*", + "test:browser_new": "cross-env CI=true jest -- ./test/browser_new/*", "lint": "eslint --max-warnings 0 --config .eslintrc .", "lint:fix": "eslint --max-warnings 0 --config .eslintrc . --fix", "generate:readme:toc": "markdown-toc -i \"README.md\"", diff --git a/test/browser_new/browser.spec.ts b/test/browser_new/browser.spec.ts index 74b9dbccd..2272c485c 100644 --- a/test/browser_new/browser.spec.ts +++ b/test/browser_new/browser.spec.ts @@ -16,11 +16,16 @@ describe('Test browser Parser in the node env', function() { console.info('start server'); server = http.createServer((req, res) => { - res.writeHead(200, { 'content-type': 'text/html' }); if (req.url === '/') { + res.writeHead(200, { 'content-type': 'text/html' }); return fs.createReadStream(htmlPath).pipe(res); } else if (req.url === '/parser.js') { + res.writeHead(200, { 'content-type': 'text/html' }); return fs.createReadStream(parserScript).pipe(res); + } else if (req.url === '/asyncapi.json') { + res.writeHead(200, { 'content-type': 'application/json' }); + res.write(JSON.stringify({ asyncapi: '2.0.0', info: { title: 'My API', version: '1.0.0' }, channels: { '/test/tester': { subscribe: { operationId: 'subscribeOperation', message: { } } } } })); + res.end(); } }); server.listen(8080); @@ -40,7 +45,7 @@ describe('Test browser Parser in the node env', function() { console.info('navigating to localhost'); await page.goto('http://localhost:8080', { waitUntil: 'networkidle0' }); - }); + }, 5000); afterAll(async function() { await browser.close(); diff --git a/test/browser_new/sample-page.html b/test/browser_new/sample-page.html index 06bd893fe..b03ab84e5 100644 --- a/test/browser_new/sample-page.html +++ b/test/browser_new/sample-page.html @@ -15,9 +15,8 @@ async function parse() { try { const parser = new window.AsyncAPIParser.Parser(); - const spec = '{ "asyncapi": "2.0.0", "info": { "title": "My API", "version": "1.0.0" }, "channels": { "/test/tester": { "subscribe": { "operationId": "subscribeOperation", "message": { } } } } }'; - const { document: parsedDocument, diagnostics } = await parser.parse(spec); - + const result = window.AsyncAPIParser.fromURL(parser, 'http://localhost:8080/asyncapi.json'); + const {document: parsedDocument, diagnostics} = await result.parse(); document.getElementById('content').innerHTML = parsedDocument.version(); document.getElementById('diagnostics').innerHTML = String(diagnostics.length); } catch (error) {