Skip to content

Commit 5a29387

Browse files
committed
test: migrate e2e test to puppeteer
1 parent 0fea8c4 commit 5a29387

14 files changed

+710
-1174
lines changed

jest.config.js

Lines changed: 1 addition & 1 deletion
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: ['./test/setup.js'],
1313
transform: {

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"lint": "eslint src test",
2424
"test": "npm run lint && npm run test:types && npm run test:unit && npm run test:ssr && npm run test:e2e",
2525
"test:unit": "jest --testPathIgnorePatterns test/e2e",
26-
"test:e2e": "node test/e2e/runner.js",
26+
"test:e2e": "start-server-and-test dev http://localhost:8080 'jest --testPathIgnorePatterns test/unit'",
2727
"test:ssr": "cross-env VUE_ENV=server jest --testPathIgnorePatterns test/e2e",
2828
"test:types": "tsc -p types/test",
2929
"coverage": "jest --testPathIgnorePatterns test/e2e --coverage",
@@ -58,7 +58,6 @@
5858
"babel-loader": "^8.1.0",
5959
"brotli": "^1.3.2",
6060
"chalk": "^4.0.0",
61-
"chromedriver": "^80.0.1",
6261
"conventional-changelog-cli": "^2.0.31",
6362
"cross-env": "^5.2.0",
6463
"cross-spawn": "^6.0.5",
@@ -69,12 +68,12 @@
6968
"execa": "^4.0.0",
7069
"express": "^4.17.1",
7170
"jest": "^26.0.1",
72-
"nightwatch": "^1.3.1",
73-
"nightwatch-helpers": "^1.2.0",
71+
"puppeteer": "^4.0.0",
7472
"regenerator-runtime": "^0.13.5",
7573
"rollup": "^2.8.2",
7674
"rollup-plugin-terser": "^5.3.0",
7775
"semver": "^7.3.2",
76+
"start-server-and-test": "^1.11.0",
7877
"todomvc-app-css": "^2.1.0",
7978
"typescript": "^3.8.3",
8079
"vue": "^3.0.0-beta.10",

test/e2e/cart.spec.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { setupPuppeteer, E2E_TIMEOUT } from 'test/helpers'
2+
3+
describe('e2e/cart', () => {
4+
const { page, text, count, click, sleep } = setupPuppeteer()
5+
6+
async function testCart (url) {
7+
await page().goto(url)
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+
}
37+
38+
test('classic', async () => {
39+
await testCart('http://localhost:8080/classic/shopping-cart/')
40+
}, E2E_TIMEOUT)
41+
42+
test('composition', async () => {
43+
await testCart('http://localhost:8080/composition/shopping-cart/')
44+
}, E2E_TIMEOUT)
45+
})

test/e2e/chat.spec.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { setupPuppeteer, E2E_TIMEOUT } from 'test/helpers'
2+
3+
describe('e2e/chat', () => {
4+
const { page, text, count, click, enterValue, sleep } = setupPuppeteer()
5+
6+
async function testChat (url) {
7+
await page().goto(url)
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+
}
34+
35+
test('classic', async () => {
36+
await testChat('http://localhost:8080/classic/chat/')
37+
}, E2E_TIMEOUT)
38+
39+
test('composition', async () => {
40+
await testChat('http://localhost:8080/composition/chat/')
41+
}, E2E_TIMEOUT)
42+
})

test/e2e/counter.spec.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { setupPuppeteer, E2E_TIMEOUT } from 'test/helpers'
2+
3+
describe('e2e/counter', () => {
4+
const { page, text, click, sleep } = setupPuppeteer()
5+
6+
async function testCounter (url) {
7+
await page().goto(url)
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+
}
30+
31+
test('classic', async () => {
32+
await testCounter('http://localhost:8080/classic/counter/')
33+
}, E2E_TIMEOUT)
34+
35+
test('composition', async () => {
36+
await testCounter('http://localhost:8080/composition/counter/')
37+
}, E2E_TIMEOUT)
38+
})

test/e2e/nightwatch.config.js

Lines changed: 0 additions & 36 deletions
This file was deleted.

test/e2e/runner.js

Lines changed: 0 additions & 31 deletions
This file was deleted.

test/e2e/specs/cart.js

Lines changed: 0 additions & 37 deletions
This file was deleted.

test/e2e/specs/chat.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

test/e2e/specs/counter.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)