@@ -73,39 +73,6 @@ async function compileModule(input, targetSSR, format) {
7373 return output [ 0 ] . code ;
7474}
7575
76- async function throwOnUnexpectedConsoleCalls ( runnable , expectedConsoleCalls = { } ) {
77- // The console is shared between the VM and the main realm. Here we ensure that known warnings
78- // are ignored and any others cause an explicit error.
79- const methods = [ 'error' , 'warn' , 'log' , 'info' ] ;
80- const originals = { } ;
81- for ( const method of methods ) {
82- // eslint-disable-next-line no-console
83- originals [ method ] = console [ method ] ;
84- // eslint-disable-next-line no-console
85- console [ method ] = function ( error ) {
86- if (
87- method === 'warn' &&
88- // This eslint warning is a false positive due to RegExp.prototype.test
89- // eslint-disable-next-line vitest/no-conditional-tests
90- / C a n n o t s e t p r o p e r t y " ( i n n e r | o u t e r ) H T M L " / . test ( error ?. message )
91- ) {
92- return ;
93- } else if (
94- expectedConsoleCalls [ method ] ?. some ( ( matcher ) => error . message . includes ( matcher ) )
95- ) {
96- return ;
97- }
98-
99- throw new Error ( `Unexpected console.${ method } call: ${ error } ` ) ;
100- } ;
101- }
102- try {
103- return await runnable ( ) ;
104- } finally {
105- Object . assign ( console , originals ) ;
106- }
107- }
108-
10976/**
11077 * This is the function that takes SSR bundle code and test config, constructs a script that will
11178 * run in a separate JS runtime environment with its own global scope. The `context` object
@@ -117,7 +84,7 @@ async function throwOnUnexpectedConsoleCalls(runnable, expectedConsoleCalls = {}
11784 * So, script runs, generates markup, & we get that markup out and return it for use
11885 * in client-side tests.
11986 */
120- async function getSsrCode ( moduleCode , filePath , expectedSSRConsoleCalls ) {
87+ async function getSsrCode ( moduleCode , filePath ) {
12188 // LWC itself requires configuration before each test (`setHooks` and
12289 // `setFeatureFlagForTest`). Ideally, this would be done in pure isolation,
12390 // but getting that set up for `vm.Script`/`vm.Module` is non-trivial.
@@ -140,10 +107,7 @@ async function getSsrCode(moduleCode, filePath, expectedSSRConsoleCalls) {
140107 }
141108 ) ;
142109
143- return await throwOnUnexpectedConsoleCalls (
144- ( ) => script . runInContext ( vm . createContext ( { LWC : lwcSsr } ) ) ,
145- expectedSSRConsoleCalls
146- ) ;
110+ return await script . runInContext ( vm . createContext ( { LWC : lwcSsr } ) ) ;
147111}
148112
149113async function existsUp ( dir , file ) {
@@ -160,12 +124,10 @@ async function existsUp(dir, file) {
160124 * This function wraps those configs in the test code to be executed.
161125 */
162126async function wrapHydrationTest ( configPath ) {
163- const {
164- default : { expectedSSRConsoleCalls, requiredFeatureFlags } ,
165- } = await import ( path . join ( ROOT_DIR , configPath ) ) ;
127+ const { default : config } = await import ( path . join ( ROOT_DIR , configPath ) ) ;
166128
167129 try {
168- requiredFeatureFlags ?. forEach ( ( featureFlag ) => {
130+ config . requiredFeatureFlags ?. forEach ( ( featureFlag ) => {
169131 lwcSsr . setFeatureFlagForTest ( featureFlag , true ) ;
170132 } ) ;
171133
@@ -175,7 +137,7 @@ async function wrapHydrationTest(configPath) {
175137 const onlyFileExists = await existsUp ( suiteDir , '.only' ) ;
176138
177139 const componentDefSSR = await compileModule ( componentEntrypoint , ! ENGINE_SERVER , 'iife' ) ;
178- const ssrOutput = await getSsrCode ( componentDefSSR , configPath , expectedSSRConsoleCalls ) ;
140+ const ssrOutput = await getSsrCode ( componentDefSSR , configPath ) ;
179141
180142 return `
181143 import { runTest } from '/helpers/test-hydrate.js';
@@ -187,7 +149,7 @@ async function wrapHydrationTest(configPath) {
187149 );
188150 ` ;
189151 } finally {
190- requiredFeatureFlags ?. forEach ( ( featureFlag ) => {
152+ config . requiredFeatureFlags ?. forEach ( ( featureFlag ) => {
191153 lwcSsr . setFeatureFlagForTest ( featureFlag , false ) ;
192154 } ) ;
193155 }
0 commit comments