-
-
Notifications
You must be signed in to change notification settings - Fork 109
fix!: expose all functions for browser #937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
649bbe2
update impl
jonaslagoni f9e72af
update config
jonaslagoni 165ef88
update config
jonaslagoni 7684893
update config
jonaslagoni 592e691
Merge branch 'master' into update_browser_export
smoya ba61d24
Merge branch 'master' into update_browser_export
smoya 06c0d2c
update browser exposure
jonaslagoni 25b4ea4
update browser exposure
jonaslagoni 0459e6d
update browser exposure
jonaslagoni 333ae36
Merge branch 'master' into update_browser_export
jonaslagoni bec5d5d
update browser exposure
jonaslagoni 6f7d525
add migration
jonaslagoni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ node_modules | |
/esm | ||
/cjs | ||
/browser | ||
/browser_new | ||
*.tgz |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import fs from 'fs'; | ||
import http from 'http'; | ||
import path from 'path'; | ||
import url from 'url'; | ||
import puppeteer from 'puppeteer'; | ||
|
||
describe('Test browser Parser in the node env', function() { | ||
let server: http.Server; | ||
let browser: puppeteer.Browser; | ||
let page: puppeteer.Page; | ||
|
||
beforeAll(async function() { | ||
const __dirname = url.fileURLToPath(new URL('.', import.meta.url)); | ||
const htmlPath = path.resolve(__dirname, 'sample-page.html'); | ||
const parserScript = path.resolve(__dirname, '../../browser_new/index.js'); | ||
|
||
console.info('start server'); | ||
server = http.createServer((req, res) => { | ||
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); | ||
|
||
//use this in case you want to troubleshoot in a real chrome window => browser = await puppeteer.launch({headless: false}); | ||
console.info('starting browser'); | ||
browser = await puppeteer.launch(); | ||
|
||
console.info('opening new page'); | ||
page = await browser.newPage(); | ||
|
||
page.on('console', msg => { | ||
msg.args().forEach((arg, index) => { | ||
console.error(`Browser console content ${index}: ${JSON.stringify(arg.remoteObject().value, null, 2)}`); | ||
}); | ||
}); | ||
|
||
console.info('navigating to localhost'); | ||
await page.goto('http://localhost:8080', { waitUntil: 'networkidle0' }); | ||
}, 5000); | ||
|
||
afterAll(async function() { | ||
await browser.close(); | ||
server.close(); | ||
}); | ||
|
||
it('should parse spec in the browser', async function() { | ||
console.info('getting content element'); | ||
const contentDiv = await page.$('#content'); | ||
const content = await page.evaluate(element => element && element.textContent, contentDiv); | ||
expect(content).toEqual('2.0.0'); | ||
|
||
console.info('getting number of warnings'); | ||
const diagnosticsDiv = await page.$('#diagnostics'); | ||
const diagnostics = await page.evaluate(element => element && element.textContent, diagnosticsDiv); | ||
expect(Number(diagnostics)).toBeGreaterThanOrEqual(0); | ||
}, 5000); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>Sample page</title> | ||
<meta charset="utf-8" /> | ||
</head> | ||
|
||
<body> | ||
<div id="content"></div> | ||
<div id="diagnostics"></div> | ||
</body> | ||
|
||
<script src="./parser.js"></script> | ||
<script defer> | ||
async function parse() { | ||
try { | ||
const parser = new window.AsyncAPIParser.Parser(); | ||
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) { | ||
console.error(error) | ||
} | ||
} | ||
parse(); | ||
</script> | ||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* eslint-disable */ | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
entry: './src/index.ts', | ||
target: 'web', | ||
mode: 'production', | ||
|
||
output: { | ||
path: path.resolve(__dirname, 'browser_new'), | ||
filename: 'index.js', | ||
globalObject: '(typeof self !== \'undefined\' ? self : this)', | ||
library: { | ||
name: 'AsyncAPIParser', | ||
type: 'umd' | ||
}, | ||
}, | ||
|
||
module: { | ||
rules: [ | ||
{ | ||
test: /\.tsx?$/, | ||
loader: 'ts-loader', | ||
exclude: /node_modules/, | ||
options: { | ||
configFile: 'tsconfig.json', | ||
transpileOnly: true, | ||
}, | ||
}, | ||
], | ||
}, | ||
resolve: { | ||
extensions: ['.ts', '.tsx', '.js'], | ||
fallback: { | ||
fs: false, | ||
path: false, | ||
util: false, | ||
buffer: require.resolve('buffer/'), | ||
} | ||
}, | ||
|
||
plugins: [ | ||
/** | ||
* Uncomment plugin when you wanna see dependency map of bundled package | ||
*/ | ||
// (require('webpack-bundle-analyzer').BundleAnalyzerPlugin()), | ||
], | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.