(apiType: 'classic' | 'composition')
| 6 | const { page, click, count, text, isChecked } = setupPuppeteer() |
| 7 | |
| 8 | async function testCommits(apiType: 'classic' | 'composition') { |
| 9 | const baseUrl = `file://${path.resolve( |
| 10 | __dirname, |
| 11 | `../../examples/${apiType}/commits.html`, |
| 12 | )}` |
| 13 | |
| 14 | // intercept and mock the response to avoid hitting the actual API |
| 15 | await page().setRequestInterception(true) |
| 16 | page().on('request', req => { |
| 17 | const match = req.url().match(/&sha=(.*)$/) |
| 18 | if (!match) { |
| 19 | req.continue() |
| 20 | } else { |
| 21 | req.respond({ |
| 22 | status: 200, |
| 23 | contentType: 'application/json', |
| 24 | headers: { 'Access-Control-Allow-Origin': '*' }, |
| 25 | body: JSON.stringify(mocks[match[1] as 'main' | 'v2-compat']), |
| 26 | }) |
| 27 | } |
| 28 | }) |
| 29 | |
| 30 | await page().goto(baseUrl) |
| 31 | await page().waitForSelector('li') |
| 32 | expect(await count('input')).toBe(2) |
| 33 | expect(await count('label')).toBe(2) |
| 34 | expect(await text('label[for="main"]')).toBe('main') |
| 35 | expect(await text('label[for="v2-compat"]')).toBe('v2-compat') |
| 36 | expect(await isChecked('#main')).toBe(true) |
| 37 | expect(await isChecked('#v2-compat')).toBe(false) |
| 38 | expect(await text('p')).toBe('vuejs/core@main') |
| 39 | expect(await count('li')).toBe(3) |
| 40 | expect(await count('li .commit')).toBe(3) |
| 41 | expect(await count('li .message')).toBe(3) |
| 42 | await click('#v2-compat') |
| 43 | expect(await text('p')).toBe('vuejs/core@v2-compat') |
| 44 | expect(await count('li')).toBe(3) |
| 45 | expect(await count('li .commit')).toBe(3) |
| 46 | expect(await count('li .message')).toBe(3) |
| 47 | } |
| 48 | |
| 49 | test( |
| 50 | 'classic', |
no test coverage detected