Skip to content

Commit

Permalink
add a simple e2e test and enable pwa
Browse files Browse the repository at this point in the history
  • Loading branch information
superlbr committed Sep 16, 2018
1 parent 2044beb commit 58f62d8
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 3 deletions.
1 change: 1 addition & 0 deletions .umirc.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default {
},
hardSource: /* isMac */ process.platform === 'darwin',
polyfills: ['ie9'],
pwa: true
},
],
],
Expand Down
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
testURL: 'http://localhost:8000',
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
"umi": "^2.0.3",
"umi-plugin-react": "^1.0.3"
},
"optionalDependencies": {
"puppeteer": "^1.6.0"
},
"lint-staged": {
"src/**/*.js": [
"eslint --ext .js --fix",
Expand Down
41 changes: 41 additions & 0 deletions src/e2e/login.e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import puppeteer from 'puppeteer'

describe('Login', () => {
let browser
let page

beforeAll(async () => {
browser = await puppeteer.launch({ args: ['--no-sandbox'] })
})

beforeEach(async () => {
page = await browser.newPage()
await page.goto('http://localhost:8000/en/login', {
waitUntil: 'networkidle2',
})
})

afterEach(() => page.close())

it('should login with failure', async () => {
await page.waitFor(selector => !!document.querySelector('#username'), {
timeout: 3000,
})
await page.type('#username', 'wrong_user')
await page.type('#password', 'wrong_password')
await page.click('button[type="button"]')
await page.waitForSelector('.anticon-close-circle') // should display error
})

it('should login successfully', async () => {
await page.waitForSelector('#username', { timeout: 3000 })
await page.type('#username', 'admin')
await page.type('#password', 'admin')
await page.click('button[type="button"]')
await page.waitForSelector('.ant-layout-footer')
const text = await page.evaluate(() => document.body.innerHTML)
expect(text).toContain('Ant Design Admin')
})

afterAll(() => browser.close())
})
44 changes: 41 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2917,7 +2917,7 @@ [email protected]:
readable-stream "~2.0.0"
typedarray "~0.0.5"

concat-stream@^1.5.0:
concat-stream@1.6.2, concat-stream@^1.5.0:
version "1.6.2"
resolved "https://registry.yarnpkg.com/concat-stream/-/concat-stream-1.6.2.tgz#904bdf194cd3122fc675c77fc4ac3d4ff0fd1a34"
dependencies:
Expand Down Expand Up @@ -4704,6 +4704,15 @@ extglob@^2.0.2, extglob@^2.0.4:
snapdragon "^0.8.1"
to-regex "^3.0.1"

extract-zip@^1.6.6:
version "1.6.7"
resolved "http://registry.npm.taobao.org/extract-zip/download/extract-zip-1.6.7.tgz#a840b4b8af6403264c8db57f4f1a74333ef81fe9"
dependencies:
concat-stream "1.6.2"
debug "2.6.9"
mkdirp "0.5.1"
yauzl "2.4.1"

[email protected]:
version "1.3.0"
resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.3.0.tgz#96918440e3041a7a414f8c52e3c574eb3c3e1e05"
Expand Down Expand Up @@ -4777,6 +4786,12 @@ fbjs@^0.8.0, fbjs@^0.8.15, fbjs@^0.8.16, fbjs@^0.8.3, fbjs@^0.8.9:
setimmediate "^1.0.5"
ua-parser-js "^0.7.18"

fd-slicer@~1.0.1:
version "1.0.1"
resolved "http://registry.npm.taobao.org/fd-slicer/download/fd-slicer-1.0.1.tgz#8b5bcbd9ec327c5041bf9ab023fd6750f1177e65"
dependencies:
pend "~1.2.0"

fecha@~2.3.3:
version "2.3.3"
resolved "https://registry.yarnpkg.com/fecha/-/fecha-2.3.3.tgz#948e74157df1a32fd1b12c3a3c3cdcb6ec9d96cd"
Expand Down Expand Up @@ -7868,7 +7883,7 @@ mixin-deep@^1.2.0:
for-in "^1.0.2"
is-extendable "^1.0.1"

[email protected], mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1:
[email protected].1, [email protected].x, mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1:
version "0.5.1"
resolved "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
dependencies:
Expand Down Expand Up @@ -8756,6 +8771,10 @@ pbkdf2@^3.0.3:
safe-buffer "^5.0.1"
sha.js "^2.4.8"

pend@~1.2.0:
version "1.2.0"
resolved "http://registry.npm.taobao.org/pend/download/pend-1.2.0.tgz#7a57eb550a6783f9115331fcf4663d5c8e007a50"

performance-now@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
Expand Down Expand Up @@ -9492,6 +9511,19 @@ punycode@^1.2.4, punycode@^1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.4.1.tgz#c0d5a63b2718800ad8e1eb0fa5269c84dd41845e"

puppeteer@^1.6.0:
version "1.8.0"
resolved "http://registry.npm.taobao.org/puppeteer/download/puppeteer-1.8.0.tgz#9e8bbd2f5448cc19cac220efc0512837104877ad"
dependencies:
debug "^3.1.0"
extract-zip "^1.6.6"
https-proxy-agent "^2.2.1"
mime "^2.0.3"
progress "^2.0.0"
proxy-from-env "^1.0.0"
rimraf "^2.6.1"
ws "^5.1.1"

q@^1.1.2:
version "1.5.1"
resolved "https://registry.yarnpkg.com/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7"
Expand Down Expand Up @@ -13370,7 +13402,7 @@ ws@^4.0.0:
async-limiter "~1.0.0"
safe-buffer "~5.1.0"

ws@^5.2.0:
ws@^5.1.1, ws@^5.2.0:
version "5.2.2"
resolved "https://registry.yarnpkg.com/ws/-/ws-5.2.2.tgz#dffef14866b8e8dc9133582514d1befaf96e980f"
dependencies:
Expand Down Expand Up @@ -13495,6 +13527,12 @@ yargs@~3.10.0:
decamelize "^1.0.0"
window-size "0.1.0"

[email protected]:
version "2.4.1"
resolved "http://registry.npm.taobao.org/yauzl/download/yauzl-2.4.1.tgz#9528f442dab1b2284e58b4379bb194e22e0c4005"
dependencies:
fd-slicer "~1.0.1"

yeoman-environment@^2.0.5:
version "2.3.3"
resolved "https://registry.yarnpkg.com/yeoman-environment/-/yeoman-environment-2.3.3.tgz#1bd9720714cc49036e901503a789d809df8f51bf"
Expand Down

0 comments on commit 58f62d8

Please sign in to comment.