commits.spec.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import path from 'path'
  2. import { setupPuppeteer, E2E_TIMEOUT } from '../../__tests__/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().waitForSelector('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(
  45. 'classic',
  46. async () => {
  47. await testCommits('classic')
  48. },
  49. E2E_TIMEOUT
  50. )
  51. test(
  52. 'composition',
  53. async () => {
  54. await testCommits('composition')
  55. },
  56. E2E_TIMEOUT
  57. )
  58. })