11import path from 'node:path' ;
22import vm from 'node:vm' ;
3- import fs from 'node:fs/promises' ;
43import { fileURLToPath } from 'node:url' ;
54import { rollup } from 'rollup' ;
65import lwcRollupPlugin from '@lwc/rollup-plugin' ;
@@ -21,16 +20,6 @@ const ROOT_DIR = path.join(import.meta.dirname, '../..');
2120const COMPONENT_NAME = 'x-main' ;
2221const COMPONENT_ENTRYPOINT = 'x/main/main.js' ;
2322
24- // Like `fs.existsSync` but async
25- async function exists ( path ) {
26- try {
27- await fs . access ( path ) ;
28- return true ;
29- } catch ( _err ) {
30- return false ;
31- }
32- }
33-
3423async function compileModule ( input , targetSSR , format ) {
3524 const modulesDir = path . join ( ROOT_DIR , input . slice ( 0 , - COMPONENT_ENTRYPOINT . length ) ) ;
3625 const bundle = await rollup ( {
@@ -106,15 +95,6 @@ async function getSsrMarkup(componentEntrypoint, configPath) {
10695 return await script . runInContext ( vm . createContext ( { LWC : lwcSsr } ) ) ;
10796}
10897
109- async function existsUp ( dir , file ) {
110- while ( true ) {
111- if ( await exists ( path . join ( dir , file ) ) ) return true ;
112- dir = path . join ( dir , '..' ) ;
113- const basename = path . basename ( dir ) ;
114- if ( basename === '.' ) return false ;
115- }
116- }
117-
11898/**
11999 * Hydration test `index.spec.js` files are actually config files, not spec files.
120100 * This function wraps those configs in the test code to be executed.
@@ -129,8 +109,6 @@ async function wrapHydrationTest(configPath) {
129109
130110 const suiteDir = path . dirname ( configPath ) ;
131111 const componentEntrypoint = path . join ( suiteDir , COMPONENT_ENTRYPOINT ) ;
132- // You can add an `.only` file alongside an `index.spec.js` file to make the test focused
133- const onlyFileExists = await existsUp ( suiteDir , '.only' ) ;
134112 const ssrOutput = await getSsrMarkup ( componentEntrypoint , configPath ) ;
135113
136114 return `
@@ -139,8 +117,7 @@ async function wrapHydrationTest(configPath) {
139117 runTest(
140118 '/${ configPath } ?original=1',
141119 '/${ componentEntrypoint } ',
142- ${ JSON . stringify ( ssrOutput ) /* escape quotes */ } ,
143- ${ onlyFileExists }
120+ ${ JSON . stringify ( ssrOutput ) /* escape quotes */ }
144121 );
145122 ` ;
146123 } finally {
0 commit comments