Skip to content

Commit

Permalink
fix: testing on mac and windows (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
derberg authored Feb 4, 2021
1 parent 376c8d9 commit b4d01bf
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 110 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ rules:
space-in-parens: [2, never]
space-unary-ops: [2, {words: true, nonwords: false}]
wrap-regex: 2
linebreak-style: [2, unix]
linebreak-style: 0
semi: [2, always]
arrow-spacing: [2, {before: true, after: true}]
no-class-assign: 2
Expand Down
77 changes: 25 additions & 52 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
},
"scripts": {
"test": "npm run test:lib && npm run test:browser",
"bundle": "browserify lib/browser.js | uglifyjs > dist/bundle.js",
"docs": "jsdoc2md lib/parser.js -f lib/**/*.js > API.md",
"types": "jsdoc -t node_modules/tsd-jsdoc/dist -r lib -d ./ && node ./scripts/fix-ts-types.js",
"bundle": "browserify \"lib/browser.js\" | uglifyjs > \"dist/bundle.js\"",
"docs": "jsdoc2md \"lib/parser.js\" -f \"lib/**/*.js\" > API.md",
"types": "jsdoc -t \"node_modules/tsd-jsdoc/dist\" -r lib -d \"./\" && node \"./scripts/fix-ts-types.js\"",
"prepublishOnly": "npm run bundle && npm run docs && npm run types",
"release": "semantic-release",
"get:version": "echo $npm_package_version",
"get:name": "echo $npm_package_name",
"lint": "eslint --max-warnings 0 --config .eslintrc .",
"test:lib": "nyc --reporter=html --reporter=text mocha --exclude test/browser_test.js --recursive",
"test:browser": "npm run test:browser:cleanup && npm run bundle && cp dist/bundle.js test/sample_browser/ && start-server-and-test 'http-server test/sample_browser --cors -s' 8080 'mocha --timeout 3000 test/browser_test.js' && npm run test:browser:cleanup",
"test:browser:cleanup": "rimraf test/sample_browser/bundle.js",
"generate:readme:toc": "markdown-toc -i README.md",
"lint": "eslint --max-warnings 0 --config \".eslintrc\" \".\"",
"test:lib": "nyc --reporter=html --reporter=text mocha --exclude \"test/browser_test.js\" --recursive",
"test:browser": "npm run test:browser:cleanup && npm run bundle && cp \"dist/bundle.js\" \"test/sample_browser/\" && start-server-and-test \"http-server test/sample_browser --cors -s\" 8080 \"mocha --timeout 6000 test/browser_test.js\" && npm run test:browser:cleanup",
"test:browser:cleanup": "rimraf \"test/sample_browser/bundle.js\"",
"generate:readme:toc": "markdown-toc -i \"README.md\"",
"generate:assets": "npm run docs && npm run generate:readme:toc && npm run types && npm run bundle",
"bump:version": "npm --no-git-tag-version --allow-same-version version $VERSION"
},
Expand Down Expand Up @@ -56,7 +56,7 @@
"markdown-toc": "^1.2.0",
"mocha": "^6.1.4",
"nyc": "^15.1.0",
"puppeteer": "^5.2.1",
"puppeteer": "^7.0.1",
"rimraf": "^3.0.2",
"semantic-release": "^17.0.4",
"start-server-and-test": "^1.11.3",
Expand Down
65 changes: 43 additions & 22 deletions test/browser_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,58 @@ let page;

describe('Check Parser in the browser', function() {
before(async function() {
//use this in case you want to troubleshoot in a real chrome window => browser = await puppeteer.launch({headless: false});
browser = await puppeteer.launch();
page = await browser.newPage();
page.on('console', msg => {
for (let i = 0; i < msg.args().length; ++i)
console.error(`Browser console content ${i}: ${JSON.stringify(msg.args()[i]._remoteObject, null, 2)}`);
});
await page.goto('http://localhost:8080', { waitUntil: 'networkidle0' });
try {
//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 => {
for (let i = 0; i < msg.args().length; ++i)
console.error(`Browser console content ${i}: ${JSON.stringify(msg.args()[i]._remoteObject, null, 2)}`);
});
console.info('navigating to localhost');
await page.goto('http://localhost:8080', { waitUntil: 'networkidle0' });
} catch (e) {
throw new Error(e);
}
});

it('parsing spec as string should complete successfully', async function() {
const specString = await page.$('#fromString');
const content = await page.evaluate(element => element.textContent, specString);

expect(content).to.be.equal('2.0.0');
}).timeout(1000);
try {
console.info('getting fromString element');
const specString = await page.$('#fromString');
const content = await page.evaluate(element => element.textContent, specString);
expect(content).to.be.equal('2.0.0');
} catch (e) {
throw new Error(e);
}
}).timeout(3000);

it('parsing spec from remote should complete successfully', async function() {
//making sure the div element is visible as this is how test script works, that it shows element only when fetching and parsing is done
//this way we are 100% sure test will not go faster than the script in the browser
await page.waitForSelector('#fromUrl', {
visible: true,
});
const specUrl = await page.$('#fromUrl');
const content = await page.evaluate(element => element.textContent, specUrl);
try {
//making sure the div element is visible as this is how test script works, that it shows element only when fetching and parsing is done
//this way we are 100% sure test will not go faster than the script in the browser
console.info('waiting for fromUrl element that shows up after spec fetch');
await page.waitForSelector('#fromUrl', {
visible: true,
});
console.info('getting fromUrl element');
const specUrl = await page.$('#fromUrl');
const content = await page.evaluate(element => element.textContent, specUrl);

expect(content).to.be.equal('2.0.0');
expect(content).to.be.equal('2.0.0');
} catch (e) {
throw new Error(e);
}
}).timeout(5000);

after(async function() {
await browser.close();
try {
await browser.close();
} catch (e) {
throw new Error(e);
}
});
});

Loading

0 comments on commit b4d01bf

Please sign in to comment.