2019-12-11 22:51:15 +08:00
|
|
|
import path from 'path'
|
2020-06-26 02:04:23 +08:00
|
|
|
import { setupPuppeteer, E2E_TIMEOUT } from '../../__tests__/e2eUtils'
|
2019-12-11 23:15:52 +08:00
|
|
|
import mocks from './commits.mock'
|
2019-12-11 22:51:15 +08:00
|
|
|
|
|
|
|
describe('e2e: commits', () => {
|
|
|
|
const { page, click, count, text, isChecked } = setupPuppeteer()
|
|
|
|
|
|
|
|
async function testCommits(apiType: 'classic' | 'composition') {
|
|
|
|
const baseUrl = `file://${path.resolve(
|
|
|
|
__dirname,
|
2019-12-11 23:15:52 +08:00
|
|
|
`../${apiType}/commits.html`
|
2019-12-11 22:51:15 +08:00
|
|
|
)}`
|
|
|
|
|
2019-12-11 23:15:52 +08:00
|
|
|
// intercept and mock the response to avoid hitting the actual API
|
|
|
|
await page().setRequestInterception(true)
|
|
|
|
page().on('request', req => {
|
|
|
|
const match = req.url().match(/&sha=(.*)$/)
|
|
|
|
if (!match) {
|
|
|
|
req.continue()
|
|
|
|
} else {
|
|
|
|
req.respond({
|
|
|
|
status: 200,
|
|
|
|
contentType: 'application/json',
|
|
|
|
headers: { 'Access-Control-Allow-Origin': '*' },
|
2022-05-12 08:44:57 +08:00
|
|
|
body: JSON.stringify(mocks[match[1] as 'main' | 'v2-compat'])
|
2019-12-11 23:15:52 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-12-11 22:51:15 +08:00
|
|
|
await page().goto(baseUrl)
|
2021-07-02 01:56:38 +08:00
|
|
|
await page().waitForSelector('li')
|
2019-12-11 22:51:15 +08:00
|
|
|
expect(await count('input')).toBe(2)
|
|
|
|
expect(await count('label')).toBe(2)
|
2022-05-12 08:44:57 +08:00
|
|
|
expect(await text('label[for="main"]')).toBe('main')
|
|
|
|
expect(await text('label[for="v2-compat"]')).toBe('v2-compat')
|
|
|
|
expect(await isChecked('#main')).toBe(true)
|
|
|
|
expect(await isChecked('#v2-compat')).toBe(false)
|
|
|
|
expect(await text('p')).toBe('vuejs/core@main')
|
2019-12-11 22:51:15 +08:00
|
|
|
expect(await count('li')).toBe(3)
|
|
|
|
expect(await count('li .commit')).toBe(3)
|
|
|
|
expect(await count('li .message')).toBe(3)
|
2022-05-12 08:44:57 +08:00
|
|
|
await click('#v2-compat')
|
|
|
|
expect(await text('p')).toBe('vuejs/core@v2-compat')
|
2019-12-11 22:51:15 +08:00
|
|
|
expect(await count('li')).toBe(3)
|
|
|
|
expect(await count('li .commit')).toBe(3)
|
|
|
|
expect(await count('li .message')).toBe(3)
|
|
|
|
}
|
|
|
|
|
2020-02-06 10:10:43 +08:00
|
|
|
test(
|
|
|
|
'classic',
|
|
|
|
async () => {
|
|
|
|
await testCommits('classic')
|
|
|
|
},
|
|
|
|
E2E_TIMEOUT
|
|
|
|
)
|
2019-12-11 22:51:15 +08:00
|
|
|
|
2020-02-06 10:10:43 +08:00
|
|
|
test(
|
|
|
|
'composition',
|
|
|
|
async () => {
|
|
|
|
await testCommits('composition')
|
|
|
|
},
|
|
|
|
E2E_TIMEOUT
|
|
|
|
)
|
2019-12-11 22:51:15 +08:00
|
|
|
})
|