Skip to content

Commit 4f7a62b

Browse files
authored
test: migrate e2e test to puppeteer from nightwatch (vuejs#1778)
1 parent 1188bb8 commit 4f7a62b

14 files changed

+707
-1190
lines changed

jest.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = {
77
'^@/(.*)$': '<rootDir>/src/$1',
88
'^test/(.*)$': '<rootDir>/test/$1'
99
},
10-
testMatch: ['<rootDir>/test/unit/**/*.spec.js'],
10+
testMatch: ['<rootDir>/test/**/*.spec.js'],
1111
testPathIgnorePatterns: ['/node_modules/'],
1212
setupFilesAfterEnv: [
1313
'./test/setup.js'

package.json

+3-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"lint": "eslint src test",
2323
"test": "npm run lint && npm run test:types && npm run test:unit && npm run test:ssr && npm run test:e2e",
2424
"test:unit": "jest --testPathIgnorePatterns test/e2e",
25-
"test:e2e": "node test/e2e/runner.js",
25+
"test:e2e": "start-server-and-test dev http://localhost:8080 'jest --testPathIgnorePatterns test/unit'",
2626
"test:ssr": "cross-env VUE_ENV=server jest --testPathIgnorePatterns test/e2e",
2727
"test:types": "tsc -p types/test",
2828
"coverage": "jest --testPathIgnorePatterns test/e2e --coverage",
@@ -56,23 +56,21 @@
5656
"babel-loader": "^8.1.0",
5757
"brotli": "^1.3.2",
5858
"chalk": "^4.0.0",
59-
"chromedriver": "^83.0.0",
6059
"conventional-changelog-cli": "^2.0.31",
6160
"cross-env": "^5.2.0",
62-
"cross-spawn": "^6.0.5",
6361
"css-loader": "^2.1.0",
6462
"enquirer": "^2.3.5",
6563
"eslint": "^6.8.0",
6664
"eslint-plugin-vue-libs": "^4.0.0",
6765
"execa": "^4.0.0",
6866
"express": "^4.17.1",
6967
"jest": "^26.0.1",
70-
"nightwatch": "^1.3.1",
71-
"nightwatch-helpers": "^1.2.0",
68+
"puppeteer": "^4.0.0",
7269
"regenerator-runtime": "^0.13.5",
7370
"rollup": "^2.8.2",
7471
"rollup-plugin-terser": "^5.3.0",
7572
"semver": "^7.3.2",
73+
"start-server-and-test": "^1.11.0",
7674
"todomvc-app-css": "^2.1.0",
7775
"typescript": "^3.8.3",
7876
"vue": "^2.5.22",

test/e2e/cart.spec.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { setupPuppeteer, E2E_TIMEOUT } from 'test/helpers'
2+
3+
describe('e2e/cart', () => {
4+
const { page, text, count, click, sleep } = setupPuppeteer()
5+
6+
test('cart app', async () => {
7+
await page().goto('http://localhost:8080/shopping-cart/')
8+
9+
await sleep(120) // api simulation
10+
11+
expect(await count('li')).toBe(3)
12+
expect(await count('.cart button[disabled]')).toBe(1)
13+
expect(await text('li:nth-child(1)')).toContain('iPad 4 Mini')
14+
expect(await text('.cart')).toContain('Please add some products to cart')
15+
expect(await text('.cart')).toContain('Total: $0.00')
16+
17+
await click('li:nth-child(1) button')
18+
expect(await text('.cart')).toContain('iPad 4 Mini - $500.01 x 1')
19+
expect(await text('.cart')).toContain('Total: $500.01')
20+
21+
await click('li:nth-child(1) button')
22+
expect(await text('.cart')).toContain('iPad 4 Mini - $500.01 x 2')
23+
expect(await text('.cart')).toContain('Total: $1,000.02')
24+
expect(await count('li:nth-child(1) button[disabled]')).toBe(1)
25+
26+
await click('li:nth-child(2) button')
27+
expect(await text('.cart')).toContain('H&M T-Shirt White - $10.99 x 1')
28+
expect(await text('.cart')).toContain('Total: $1,011.01')
29+
30+
await click('.cart button')
31+
await sleep(200)
32+
expect(await text('.cart')).toContain('Please add some products to cart')
33+
expect(await text('.cart')).toContain('Total: $0.00')
34+
expect(await text('.cart')).toContain('Checkout successful')
35+
expect(await count('.cart button[disabled]')).toBe(1)
36+
}, E2E_TIMEOUT)
37+
})

test/e2e/chat.spec.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { setupPuppeteer, E2E_TIMEOUT } from 'test/helpers'
2+
3+
describe('e2e/chat', () => {
4+
const { page, text, count, click, enterValue, sleep } = setupPuppeteer()
5+
6+
test('chat app', async () => {
7+
await page().goto('http://localhost:8080/chat/')
8+
9+
expect(await text('.thread-count')).toContain('Unread threads: 2')
10+
expect(await count('.thread-list-item')).toBe(3)
11+
expect(await text('.thread-list-item.active')).toContain('Functional Heads')
12+
expect(await text('.message-thread-heading')).toContain('Functional Heads')
13+
expect(await count('.message-list-item')).toBe(2)
14+
expect(await text('.message-list-item:nth-child(1) .message-author-name')).toContain('Bill')
15+
expect(await text('.message-list-item:nth-child(1) .message-text')).toContain('Hey Brian')
16+
17+
await enterValue('.message-composer', 'hi')
18+
await sleep(50) // fake api
19+
expect(await count('.message-list-item')).toBe(3)
20+
expect(await text('.message-list-item:nth-child(3)')).toContain('hi')
21+
22+
await click('.thread-list-item:nth-child(2)')
23+
expect(await text('.thread-list-item.active')).toContain('Dave and Bill')
24+
expect(await text('.message-thread-heading')).toContain('Dave and Bill')
25+
expect(await count('.message-list-item')).toBe(2)
26+
expect(await text('.message-list-item:nth-child(1) .message-author-name')).toContain('Bill')
27+
expect(await text('.message-list-item:nth-child(1) .message-text')).toContain('Hey Dave')
28+
29+
await enterValue('.message-composer', 'hi')
30+
await sleep(50) // fake api
31+
expect(await count('.message-list-item')).toBe(3)
32+
expect(await text('.message-list-item:nth-child(3)')).toContain('hi')
33+
}, E2E_TIMEOUT)
34+
})

test/e2e/counter.spec.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { setupPuppeteer, E2E_TIMEOUT } from 'test/helpers'
2+
3+
describe('e2e/counter', () => {
4+
const { page, text, click, sleep } = setupPuppeteer()
5+
6+
test('counter app', async () => {
7+
await page().goto('http://localhost:8080/counter/')
8+
expect(await text('#app')).toContain('Clicked: 0 times')
9+
10+
await click('button:nth-child(1)')
11+
expect(await text('#app')).toContain('Clicked: 1 times')
12+
13+
await click('button:nth-child(2)')
14+
expect(await text('#app')).toContain('Clicked: 0 times')
15+
16+
await click('button:nth-child(3)')
17+
expect(await text('#app')).toContain('Clicked: 0 times')
18+
19+
await click('button:nth-child(1)')
20+
expect(await text('#app')).toContain('Clicked: 1 times')
21+
22+
await click('button:nth-child(3)')
23+
expect(await text('#app')).toContain('Clicked: 2 times')
24+
25+
await click('button:nth-child(4)')
26+
expect(await text('#app')).toContain('Clicked: 2 times')
27+
await sleep(1000)
28+
expect(await text('#app')).toContain('Clicked: 3 times')
29+
}, E2E_TIMEOUT)
30+
})

test/e2e/nightwatch.config.js

-36
This file was deleted.

test/e2e/runner.js

-31
This file was deleted.

test/e2e/specs/cart.js

-30
This file was deleted.

test/e2e/specs/chat.js

-28
This file was deleted.

test/e2e/specs/counter.js

-23
This file was deleted.

0 commit comments

Comments
 (0)