vdomInterop.spec.ts 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import path from 'node:path'
  2. import {
  3. E2E_TIMEOUT,
  4. setupPuppeteer,
  5. } from '../../../packages/vue/__tests__/e2e/e2eUtils'
  6. import connect from 'connect'
  7. import sirv from 'sirv'
  8. import { ports } from '../utils'
  9. describe('vdom / vapor interop', () => {
  10. const { page, click, text, enterValue } = setupPuppeteer()
  11. let server: any
  12. const port = ports.vdomInterop
  13. beforeAll(() => {
  14. server = connect()
  15. .use(sirv(path.resolve(import.meta.dirname, '../dist')))
  16. .listen(port)
  17. process.on('SIGTERM', () => server && server.close())
  18. })
  19. afterAll(() => {
  20. server.close()
  21. })
  22. test(
  23. 'should work',
  24. async () => {
  25. const baseUrl = `http://localhost:${port}/interop/`
  26. await page().goto(baseUrl)
  27. expect(await text('.vapor > h2')).toContain('Vapor component in VDOM')
  28. expect(await text('.vapor-prop')).toContain('hello')
  29. const t = await text('.vdom-slot-in-vapor-default')
  30. expect(t).toContain('slot prop: slot prop')
  31. expect(t).toContain('component prop: hello')
  32. await click('.change-vdom-slot-in-vapor-prop')
  33. expect(await text('.vdom-slot-in-vapor-default')).toContain(
  34. 'slot prop: changed',
  35. )
  36. expect(await text('.vdom-slot-in-vapor-test')).toContain('A test slot')
  37. await click('.toggle-vdom-slot-in-vapor')
  38. expect(await text('.vdom-slot-in-vapor-test')).toContain(
  39. 'fallback content',
  40. )
  41. await click('.toggle-vdom-slot-in-vapor')
  42. expect(await text('.vdom-slot-in-vapor-test')).toContain('A test slot')
  43. expect(await text('.vdom > h2')).toContain('VDOM component in Vapor')
  44. expect(await text('.vdom-prop')).toContain('hello')
  45. const tt = await text('.vapor-slot-in-vdom-default')
  46. expect(tt).toContain('slot prop: slot prop')
  47. expect(tt).toContain('component prop: hello')
  48. await click('.change-vapor-slot-in-vdom-prop')
  49. expect(await text('.vapor-slot-in-vdom-default')).toContain(
  50. 'slot prop: changed',
  51. )
  52. expect(await text('.vapor-slot-in-vdom-test')).toContain('fallback')
  53. await click('.toggle-vapor-slot-in-vdom-default')
  54. expect(await text('.vapor-slot-in-vdom-default')).toContain(
  55. 'default slot fallback',
  56. )
  57. await click('.toggle-vapor-slot-in-vdom-default')
  58. await enterValue('input', 'bye')
  59. expect(await text('.vapor-prop')).toContain('bye')
  60. expect(await text('.vdom-slot-in-vapor-default')).toContain('bye')
  61. expect(await text('.vdom-prop')).toContain('bye')
  62. expect(await text('.vapor-slot-in-vdom-default')).toContain('bye')
  63. },
  64. E2E_TIMEOUT,
  65. )
  66. })