commits.spec.ts 1.7 KB

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