commits.spec.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // @vitest-environment node
  2. import { setupPuppeteer, getExampleUrl, E2E_TIMEOUT } 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. // intercept and mock the response to avoid hitting the actual API
  8. await page().setRequestInterception(true)
  9. page().on('request', req => {
  10. const match = req.url().match(/&sha=(.*)$/)
  11. if (!match) {
  12. req.continue()
  13. } else {
  14. const ret = JSON.stringify(mocks[match[1] as 'main' | 'dev'])
  15. req.respond({
  16. status: 200,
  17. contentType: 'application/json',
  18. headers: { 'Access-Control-Allow-Origin': '*' },
  19. body: ret
  20. })
  21. }
  22. })
  23. await page().goto(getExampleUrl('commits', apiType))
  24. await page().waitForSelector('li')
  25. expect(await count('input')).toBe(2)
  26. expect(await count('label')).toBe(2)
  27. expect(await text('label[for="main"]')).toBe('main')
  28. expect(await text('label[for="dev"]')).toBe('dev')
  29. expect(await isChecked('#main')).toBe(true)
  30. expect(await isChecked('#dev')).toBe(false)
  31. expect(await text('p')).toBe('vuejs/vue@main')
  32. expect(await count('li')).toBe(3)
  33. expect(await count('li .commit')).toBe(3)
  34. expect(await count('li .message')).toBe(3)
  35. await click('#dev')
  36. expect(await text('p')).toBe('vuejs/vue@dev')
  37. expect(await count('li')).toBe(3)
  38. expect(await count('li .commit')).toBe(3)
  39. expect(await count('li .message')).toBe(3)
  40. }
  41. test(
  42. 'classic',
  43. async () => {
  44. await testCommits('classic')
  45. },
  46. E2E_TIMEOUT
  47. )
  48. test(
  49. 'composition',
  50. async () => {
  51. await testCommits('composition')
  52. },
  53. E2E_TIMEOUT
  54. )
  55. })