-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[WIP] test(e2e): added jest env and puppeteer for e2e #986
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 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
be2dadd
test(e2e): added jest env and puppeteer for e2e
anikethsaha 3c5ef67
test(e2e): added image snapshot assertion
anikethsaha 6e09fa2
chore(tests): more tests and env refactore
anikethsaha 8df94b3
chore(CI): refactored the .travis.yml
anikethsaha bb08447
chore(tests): enabled headless for puppeteer
anikethsaha a334a0d
chore: rebase
anikethsaha b7a849a
chore: refactore
anikethsaha 36c1209
test(search): added tests for searching input bar
anikethsaha 06f50a4
test(cover): added tests for cover pages
anikethsaha cc98244
chore(CI): added github actions
anikethsaha e47b832
Merge pull request #1 from anikethsaha/gh-CI-actions
anikethsaha 1ff6c43
chore: removed repeated running of live server for each tests
anikethsaha 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
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,12 @@ | ||
module.exports = { | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
targets: { | ||
node: 'current' | ||
} | ||
} | ||
] | ||
] | ||
} |
Binary file added
BIN
+181 KB
...e_snapshots__/index-spec-js-should-take-snapshots-of-home-page-cover-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,30 @@ | ||
import puppeteer from 'puppeteer' | ||
import { toMatchImageSnapshot } from 'jest-image-snapshot' | ||
var browser | ||
var page | ||
|
||
jest.setTimeout(30000) | ||
expect.extend({ toMatchImageSnapshot }) | ||
beforeAll(async () => { | ||
browser = await puppeteer.launch() | ||
page = await browser.newPage() | ||
await page.goto('https://www.google.com') | ||
}) | ||
|
||
afterAll(async () => { | ||
await browser.close() | ||
// SetTimeout(() => process.exit(0), 5000) | ||
}) | ||
|
||
test('should take snapshots of home page (cover) ', async done => { | ||
expect(Object.keys(page).length).toBeGreaterThan(0) | ||
|
||
await page.goto('http://127.0.0.1:3000') | ||
const ss = await page.screenshot() | ||
|
||
expect(ss).toMatchImageSnapshot({ | ||
failureThreshold: 10, | ||
failureThresholdType: 'percent' | ||
}) | ||
done() | ||
}) |
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,4 @@ | ||
require('@babel/register')({ | ||
extensions: ['.ts', '.js'] | ||
}) | ||
module.exports = require('./testEnvironment.js') |
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,125 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>docsify-e2e-tests</title> | ||
<link rel="icon" href="_media/favicon.ico" /> | ||
<meta | ||
name="google-site-verification" | ||
content="6t0LoIeFksrjF4c9sqUEsVXiQNxLp2hgoqo0KryT-sE" | ||
/> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> | ||
<meta | ||
name="keywords" | ||
content="doc,docs,documentation,gitbook,creator,generator,github,jekyll,github-pages" | ||
/> | ||
<meta name="description" content="A magical documentation generator." /> | ||
<meta | ||
name="viewport" | ||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" | ||
/> | ||
<link rel="stylesheet" href="lib/themes/vue.css" title="vue" /> | ||
<link rel="stylesheet" href="lib/themes/dark.css" title="dark" disabled /> | ||
<link rel="stylesheet" href="lib/themes/buble.css" title="buble" disabled /> | ||
<link rel="stylesheet" href="lib/themes/pure.css" title="pure" disabled /> | ||
<script src="//unpkg.com/docsify-plugin-codefund/index.js"></script> | ||
<style> | ||
nav.app-nav li ul { | ||
min-width: 100px; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div id="app">Loading Docsify e2e tests suite...</div> | ||
<script> | ||
window.$docsify = { | ||
alias: { | ||
'.*?/awesome': | ||
'https://raw.githubusercontent.com/docsifyjs/awesome-docsify/master/README.md', | ||
'.*?/changelog': | ||
'https://raw.githubusercontent.com/docsifyjs/docsify/master/CHANGELOG.md', | ||
'/.*/_navbar.md': '/_navbar.md', | ||
'/zh-cn/(.*)': | ||
'https://raw.githubusercontent.com/docsifyjs/docs-zh/master/$1', | ||
'/de-de/(.*)': | ||
'https://raw.githubusercontent.com/docsifyjs/docs-de/master/$1', | ||
'/ru/(.*)': | ||
'https://raw.githubusercontent.com/docsifyjs/docs-ru/master/$1', | ||
'/es/(.*)': | ||
'https://raw.githubusercontent.com/docsifyjs/docs-es/master/$1' | ||
}, | ||
auto2top: true, | ||
coverpage: true, | ||
executeScript: true, | ||
loadSidebar: true, | ||
loadNavbar: true, | ||
mergeNavbar: true, | ||
maxLevel: 4, | ||
subMaxLevel: 2, | ||
ga: 'UA-106147152-1', | ||
matomo: { | ||
host: '//matomo.thunderwave.de', | ||
id: 6 | ||
}, | ||
name: 'docsify', | ||
search: { | ||
noData: { | ||
'/de-de/': 'Keine Ergebnisse!', | ||
'/zh-cn/': '没有结果!', | ||
'/': 'No results!' | ||
}, | ||
paths: 'auto', | ||
placeholder: { | ||
'/de-de/': 'Suche', | ||
'/zh-cn/': '搜索', | ||
'/': 'Search' | ||
} | ||
}, | ||
formatUpdated: '{MM}/{DD} {HH}:{mm}', | ||
plugins: [ | ||
function(hook, vm) { | ||
hook.beforeEach(function(html) { | ||
if (/githubusercontent\.com/.test(vm.route.file)) { | ||
url = vm.route.file | ||
.replace('raw.githubusercontent.com', 'github.com') | ||
.replace(/\/master/, '/blob/master') | ||
} else { | ||
url = | ||
'https://github.com/docsifyjs/docsify/blob/master/docs/' + | ||
vm.route.file | ||
} | ||
var editHtml = '[:memo: Edit Document](' + url + ')\n' | ||
|
||
return ( | ||
editHtml + | ||
html + | ||
'\n\n----\n\n' + | ||
'<a href="https://docsify.js.org" target="_blank" style="color: inherit; font-weight: normal; text-decoration: none;">Powered by docsify</a>' | ||
) | ||
}) | ||
}, | ||
DocsifyCodefund.create('fae1f9a4-870c-4c25-b8e0-c80464f7a95c') | ||
] | ||
} | ||
</script> | ||
<script src="lib/docsify.min.js"></script> | ||
<script src="lib/plugins/search.min.js"></script> | ||
<script src="lib/plugins/ga.min.js"></script> | ||
<script src="lib/plugins/matomo.min.js"></script> | ||
<script src="//unpkg.com/prismjs/components/prism-bash.min.js"></script> | ||
<script src="//unpkg.com/prismjs/components/prism-markdown.min.js"></script> | ||
<script src="//unpkg.com/prismjs/components/prism-nginx.min.js"></script> | ||
|
||
<script> | ||
;((window.gitter = {}).chat = {}).options = { | ||
room: 'docsifyjs/Lobby' | ||
} | ||
</script> | ||
<script | ||
src="https://sidecar.gitter.im/dist/sidecar.v1.js" | ||
async | ||
defer | ||
></script> | ||
</body> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import NodeEnvironment from 'jest-environment-node' | ||
import copyDir from 'copy-dir' | ||
import path from 'path' | ||
import fs from 'fs' | ||
import liveServer from 'live-server' | ||
|
||
export default class CustomEnvironment extends NodeEnvironment { | ||
constructor(config, context) { | ||
super(config, context) | ||
this.PORT = this.global.PORT || 3000 | ||
global.__LIVESERVER__ = null | ||
} | ||
|
||
async setup() { | ||
/** | ||
* IN this test suite, we are going to test our docs site with all the css,js linked to our local build packages | ||
* | ||
* 1.1 Copy ../docs --> ./fixtures/docs | ||
* 1.2 copy lib,themes --> ./fixtures/ | ||
* 2. change the content of fixtures/docs/index.html to use all the links from our local build | ||
* 3. run the local-server (localhost:3000) | ||
* 4. now jest runner will run to test all the *.spec.js files | ||
* | ||
* Scripts | ||
* pretest:e2e : babel-node e2e/setup | ||
* test:e2e : jest e2e | ||
* posttest:e2e : del-cli e2e/fixtures/docs #removing the docs from the fixture in order to always test with latest docs to match with the PR | ||
* | ||
*/ | ||
|
||
const shippedDirs = ['lib', 'themes'] | ||
|
||
// 1 | ||
const docsPath = path.join(process.cwd(), './docs') | ||
const fixtureDocsPath = path.join(__dirname, './fixtures/docs') | ||
|
||
// 1.1 | ||
console.log('[e2e test docs] Copying the docs --> e2e/fixtures/docs') | ||
copyDir.sync(docsPath, fixtureDocsPath) | ||
|
||
// 1.2 | ||
shippedDirs.forEach(dir => { | ||
const fromPath = path.join(process.cwd(), dir) | ||
const toPath = path.join(__dirname, `./fixtures/docs/${dir}`) | ||
console.log( | ||
`[e2e test docs] Copying ${dir} --> e2e/fixtures/docs/${dir}` | ||
) | ||
copyDir.sync(fromPath, toPath) | ||
}) | ||
|
||
// 2 | ||
console.log( | ||
'[e2e test docs] Replacing content the tpl/index.html --> e2e/fixtures/docs/index.html' | ||
) | ||
const indexHTMLtplPath = path.join(__dirname, './fixtures/tpl/index.html') | ||
const fixtureIndexPath = path.join(__dirname, './fixtures/docs/index.html') | ||
const data = fs.readFileSync(indexHTMLtplPath, 'utf8') | ||
fs.writeFileSync(fixtureIndexPath, data, 'utf8') | ||
|
||
// 3 | ||
const fixturePath = path.join(__dirname, './fixtures/docs') | ||
|
||
const params = { | ||
port: this.PORT, | ||
root: fixturePath, | ||
open: false | ||
// NoBrowser: true | ||
} | ||
console.log(params) | ||
liveServer.start(params) | ||
global.__LIVESERVER__ = liveServer | ||
} | ||
|
||
async teardown() { | ||
console.log( | ||
'[e2e test docs] Shutting down the server', | ||
this.global.__LIVESERVER__ | ||
) | ||
global.__LIVESERVER__.shutdown() | ||
await super.teardown() | ||
} | ||
|
||
runScript(script) { | ||
return super.runScript(script) | ||
} | ||
} |
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,8 @@ | ||
module.exports = { | ||
// GlobalSetup: '<rootDir>/e2e/setup.js', | ||
// globalTeardown: '<rootDir>/e2e/teardown.js' | ||
transform: { | ||
'^.+\\.[t|j]sx?$': 'babel-jest' | ||
}, | ||
testEnvironment: '<rootDir>/e2e/babel_testEnvironment.js' | ||
} |
Oops, something went wrong.
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.