2023-04-06 11:51:32 +00:00
import { fileURLToPath } from 'node:url'
2023-04-07 16:02:47 +00:00
import { describe , expect , it } from 'vitest'
2024-06-25 06:48:39 +00:00
import { $fetch , createPage , setup } from '@nuxt/test-utils/e2e'
2023-08-12 07:18:58 +00:00
import { isWindows } from 'std-env'
2024-06-25 06:48:39 +00:00
import { expectNoClientErrors } from './utils'
2024-04-05 18:08:32 +00:00
2024-10-09 13:57:54 +00:00
const isWebpack = process . env . TEST_BUILDER === 'webpack' || process . env . TEST_BUILDER === 'rspack'
2023-04-06 11:51:32 +00:00
await setup ( {
rootDir : fileURLToPath ( new URL ( './fixtures/runtime-compiler' , import . meta . url ) ) ,
dev : process.env.TEST_ENV === 'dev' ,
server : true ,
browser : true ,
2023-08-12 07:18:58 +00:00
setupTimeout : ( isWindows ? 360 : 120 ) * 1000 ,
2023-04-06 11:51:32 +00:00
nuxtConfig : {
2024-04-05 18:08:32 +00:00
builder : isWebpack ? 'webpack' : 'vite' ,
} ,
2023-04-06 11:51:32 +00:00
} )
describe ( 'test basic config' , ( ) = > {
it ( 'expect render page without any error or logs' , async ( ) = > {
await expectNoClientErrors ( '/' )
} )
it ( 'test HelloWorld.vue' , async ( ) = > {
const html = await $fetch ( '/' )
2024-06-25 06:48:39 +00:00
const page = await createPage ( '/' )
await page . waitForFunction ( ( ) = > window . useNuxtApp ? . ( ) && ! window . useNuxtApp ? . ( ) . isHydrating )
2023-04-06 11:51:32 +00:00
expect ( html ) . toContain ( '<div id="hello-world">hello, Helloworld.vue here ! </div>' )
expect ( await page . locator ( 'body' ) . innerHTML ( ) ) . toContain ( '<div id="hello-world">hello, Helloworld.vue here ! </div>' )
2024-06-25 06:48:39 +00:00
await page . close ( )
2023-04-06 11:51:32 +00:00
} )
it ( 'test Name.ts' , async ( ) = > {
const html = await $fetch ( '/' )
2024-06-25 06:48:39 +00:00
const page = await createPage ( '/' )
await page . waitForFunction ( ( ) = > window . useNuxtApp ? . ( ) && ! window . useNuxtApp ? . ( ) . isHydrating )
2023-04-06 11:51:32 +00:00
expect ( html ) . toContain ( '<div id="name">I am the Name.ts component</div>' )
expect ( await page . locator ( 'body' ) . innerHTML ( ) ) . toContain ( '<div id="name">I am the Name.ts component</div>' )
2024-06-25 06:48:39 +00:00
await page . close ( )
2023-04-06 11:51:32 +00:00
} )
it ( 'test ShowTemplate.ts' , async ( ) = > {
const html = await $fetch ( '/' )
2024-06-25 06:48:39 +00:00
const page = await createPage ( '/' )
await page . waitForFunction ( ( ) = > window . useNuxtApp ? . ( ) && ! window . useNuxtApp ? . ( ) . isHydrating )
2023-04-06 11:51:32 +00:00
expect ( html ) . toContain ( '<div id="show-template">Hello my name is : John, i am defined by ShowTemplate.vue and my template is retrieved from the API</div>' )
expect ( await page . locator ( 'body' ) . innerHTML ( ) ) . toContain ( '<div id="show-template">Hello my name is : John, i am defined by ShowTemplate.vue and my template is retrieved from the API</div>' )
2024-06-25 06:48:39 +00:00
await page . close ( )
2023-04-06 11:51:32 +00:00
} )
it ( 'test Interactive component.ts' , async ( ) = > {
const html = await $fetch ( '/' )
2024-06-25 06:48:39 +00:00
const page = await createPage ( '/' )
await page . waitForFunction ( ( ) = > window . useNuxtApp ? . ( ) && ! window . useNuxtApp ? . ( ) . isHydrating )
2023-04-06 11:51:32 +00:00
expect ( html ) . toContain ( 'I am defined by Interactive in the setup of App.vue. My full component definition is retrieved from the api' )
expect ( await page . locator ( '#interactive' ) . innerHTML ( ) ) . toContain ( 'I am defined by Interactive in the setup of App.vue. My full component definition is retrieved from the api' )
const button = page . locator ( '#inc-interactive-count' )
await button . click ( )
const count = page . locator ( '#interactive-count' )
expect ( await count . innerHTML ( ) ) . toBe ( '1' )
2024-06-25 06:48:39 +00:00
await page . close ( )
2023-04-06 11:51:32 +00:00
} )
} )