Skip to content

Commit

Permalink
update browser exposure
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni committed Jun 25, 2024
1 parent ba61d24 commit 06c0d2c
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 155 deletions.
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,17 @@
"/esm",
"/cjs",
"/browser",
"/browser_new",
"LICENSE",
"README.md"
],
"scripts": {
"build": "npm run build:esm && npm run build:cjs && npm run build:browser && npm run build:browser_new",
"build": "npm run build:esm && npm run build:cjs && npm run build:browser",
"build:esm": "tsc",
"build:cjs": "tsc --project ./tsconfig.cjs.json",
"build:browser": "webpack",
"build:browser_new": "webpack --config ./webpack_new.config.js",
"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": "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\"",
Expand Down
11 changes: 8 additions & 3 deletions test/browser/browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,20 @@ describe('Test browser Parser in the node env', function() {
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/index.js');
const parserScript = path.resolve(__dirname, '../../browser_new/index.js');

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);
Expand All @@ -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();
Expand Down
7 changes: 3 additions & 4 deletions test/browser/sample-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
<script defer>
async function parse() {
try {
const parser = new window.AsyncAPIParser();
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 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) {
Expand Down
66 changes: 0 additions & 66 deletions test/browser_new/browser.spec.ts

This file was deleted.

28 changes: 0 additions & 28 deletions test/browser_new/sample-page.html

This file was deleted.

3 changes: 1 addition & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ module.exports = {
globalObject: '(typeof self !== \'undefined\' ? self : this)',
library: {
name: 'AsyncAPIParser',
type: 'umd',
export: 'default'
type: 'umd'
},
},

Expand Down
48 changes: 0 additions & 48 deletions webpack_new.config.js

This file was deleted.

0 comments on commit 06c0d2c

Please sign in to comment.