Skip to content
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

Add End 2 End tests #477

Merged
merged 9 commits into from
Jul 18, 2018
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ test_script:
- node --version
- npm --version
# Make sure build works on Windows
- npm run package
- yarn package
# run tests
- set PHANTOMJS_BIN=C:\ProgramData\chocolatey\bin\phantomjs.exe
- appveyor-retry call npm test
- appveyor-retry call yarn test
- appveyor-retry call yarn e2e

# Don't actually build.
build: off
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/fixtures.json
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ before_install:
before_script:
- git diff --exit-code # make sure that yarn.lock didn't change
- ./packages/blob-reader/scripts/update-fixtures.sh
- npm run package
- yarn package
script:
- travis_retry npm test
- travis_retry yarn test
- yarn e2e
deploy:
- provider: releases
api_key: "$GH_DEPLOY"
Expand All @@ -32,7 +33,7 @@ deploy:
on:
tags: true
- provider: script
script: npm run release
script: yarn release
skip_cleanup: true
on:
branch: master
Expand Down
5 changes: 5 additions & 0 deletions e2e/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
globals: {
page: true
}
}
25 changes: 25 additions & 0 deletions e2e/automated.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const fixtures = require('./fixtures.json'); // eslint-disable-line import/no-unresolved

async function executeTest(url, lineNumber, targetUrl) {
const selector = `#LC${lineNumber} .octolinker-link`;

await page.goto(url);

await page.waitForSelector(selector);

await Promise.all([
page.waitForNavigation(),
// page.click(selector), for some reason page.click is not working
page.$eval(selector, el => el.click()),
]);

await expect(page.url()).toEqual(expect.stringMatching(targetUrl));
}

describe('End to End tests', () => {
fixtures.forEach(({ url, content, lineNumber, targetUrl }) => {
it(`resolves ${content} to ${targetUrl}`, async () => {
await executeTest(url, lineNumber, targetUrl);
});
});
});
4 changes: 4 additions & 0 deletions e2e/jest-e2e.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
preset: 'jest-puppeteer',
testMatch: ['<rootDir>/**/?(*.)test?(s).js'],
};
15 changes: 15 additions & 0 deletions jest-puppeteer.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const path = require('path');

const extPath = path.join(__dirname, './dist');

module.exports = {
launch: {
dumpio: true,
headless: false,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puppeteer headless doesn't support extensions, right now.

puppeteer/puppeteer#2819 (comment)

args: [
'--no-sandbox',
`--disable-extensions-except=${extPath}`,
`--load-extension=${extPath}`,
],
},
};
7 changes: 7 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
testPathIgnorePatterns: ['<rootDir>/e2e/'],
setupFiles: ['<rootDir>/_jestsetup.js'],
moduleNameMapper: {
'\\.css$': '<rootDir>/__mocks__/styleMock.js',
},
};
11 changes: 3 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"lint": "eslint .",
"pretest": "yarn lint",
"test": "jest",
"e2e": "curl https://raw.githubusercontent.com/OctoLinker/e2e/master/resource.json > e2e/fixtures.json && jest --config=e2e/jest-e2e.config.js",
"postinstall": "yarn lerna bootstrap",
"test:watch": "jest --watch",
"version": "json -I -f assets/manifest.json -e \"this.version='`json -f package.json version`'\" && git add assets/manifest.json",
Expand All @@ -20,14 +21,6 @@
"firefox-open": "yarn build && yarn firefox-launch --",
"firefox-launch": "web-ext run --source-dir dist --pref startup.homepage_welcome_url=https://github.com/OctoLinker/OctoLinker/blob/master/package.json"
},
"jest": {
"moduleNameMapper": {
"\\.css$": "<rootDir>/__mocks__/styleMock.js"
},
"setupFiles": [
"./_jestsetup.js"
]
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
Expand All @@ -47,12 +40,14 @@
"eslint-plugin-prettier": "^2.3.1",
"eslint-plugin-react": "^7.4.0",
"jest": "^22.0.6",
"jest-puppeteer": "^3.2.1",
"json": "^9.0.4",
"json-loader": "^0.5.7",
"lerna": "^2.7.0",
"mkdirp": "^0.5.1",
"npm-run-all": "^4.1.1",
"prettier": "^1.7.4",
"puppeteer": "^1.5.0",
"sinon": "^4.0.1",
"style-loader": "^0.19.0",
"web-ext": "^2.0.0",
Expand Down
Loading