Skip to content

Commit

Permalink
Run e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Buck committed Jun 18, 2018
1 parent 403143c commit 16e99ea
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ lerna-debug.log

dist/
out/
e2e/urls.json
35 changes: 23 additions & 12 deletions e2e/automated.test.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
const baseUrl = 'https://github.com/OctoLinker/e2e';
const urls = require('./urls.json'); // eslint-disable-line import/no-unresolved

async function insertResolveUrlsIntoDom() {
return page.evaluate(() => {
document.querySelectorAll('.octolinker-link').forEach(node => {
const resolveto = node
.closest('tr')
.previousElementSibling.textContent.trim()
.replace('// Should resolve to: ', '');
node.dataset.e2eResult = resolveto;
});
});
}

async function goto(url) {
await page.goto(url);
await page.waitForSelector('.octolinker-link');

// TODO Allow annotations beyond the first line
const annotation = await page.$eval('#LC1', el => el.textContent);
const targetPath = annotation
.replace('// Should resolve to: ', '')
.replace('<root>', '');
await insertResolveUrlsIntoDom();

await page.click('.octolinker-link');
const result = await page.$eval(
'.octolinker-link',
el => el.dataset.e2eResult,
);
await page.waitForNavigation();

await expect(page.url()).toEqual(expect.stringMatching(targetPath));
// TODO remove double slash fix
await expect(page.url().replace(/\/\//g, '/')).toEqual(
expect.stringMatching(result.replace('<root>', '')),
);
}

describe('End to End tests', () => {
// TODO scrape https://github.com/OctoLinker/e2e/ for those urls
[
`${baseUrl}/blob/master/javascript/nodejs/index.js`,
`${baseUrl}/blob/master/javascript/nodejs/gentle-resonance-3436.js`,
].forEach(url => {
urls.forEach(url => {
it(`resolves ${url}`, async () => {
await goto(url);
});
Expand Down

0 comments on commit 16e99ea

Please sign in to comment.