@@ -22,19 +22,37 @@ function setFeatureFlags(requiredFeatureFlags, value) {
2222 } ) ;
2323}
2424
25+ // Must be sync to properly register tests; async behavior can happen in before/after blocks
2526export function runTest ( configPath , componentPath , ssrRendered , focused ) {
2627 const test = focused ? it . only : it ;
27- test ( configPath , async ( ) => {
28- const testConfig = await import ( configPath ) ;
29- const Component = await import ( componentPath ) ;
28+ const description = new URL ( configPath , location . href ) . pathname ;
29+ let consoleSpy ;
30+ let testConfig ;
31+ let Component ;
32+
33+ beforeAll ( async ( ) => {
34+ testConfig = await import ( configPath ) ;
35+ Component = await import ( componentPath ) ;
36+ setFeatureFlags ( testConfig . requiredFeatureFlags , true ) ;
37+ } ) ;
38+
39+ beforeEach ( async ( ) => {
40+ consoleSpy = spyConsole ( ) ;
41+ } ) ;
42+
43+ afterEach ( ( ) => {
44+ consoleSpy . reset ( ) ;
45+ } ) ;
46+
47+ afterAll ( ( ) => {
48+ setFeatureFlags ( testConfig . requiredFeatureFlags , false ) ;
49+ } ) ;
50+
51+ test ( description , async ( ) => {
3052 const container = appendTestTarget ( ssrRendered ) ;
3153 const selector = container . firstChild . tagName . toLowerCase ( ) ;
3254 let target = container . querySelector ( selector ) ;
3355
34- let testResult ;
35- const consoleSpy = spyConsole ( ) ;
36- setFeatureFlags ( testConfig . requiredFeatureFlags , true ) ;
37-
3856 if ( testConfig . test ) {
3957 const snapshot = testConfig . snapshot ? testConfig . snapshot ( target ) : { } ;
4058
@@ -45,19 +63,15 @@ export function runTest(configPath, componentPath, ssrRendered, focused) {
4563
4664 // let's select again the target, it should be the same elements as in the snapshot
4765 target = container . querySelector ( selector ) ;
48- testResult = await testConfig . test ( target , snapshot , consoleSpy . calls ) ;
66+ await testConfig . test ( target , snapshot , consoleSpy . calls ) ;
4967 } else if ( testConfig . advancedTest ) {
50- testResult = await testConfig . advancedTest ( target , {
68+ await testConfig . advancedTest ( target , {
5169 Component,
5270 hydrateComponent : LWC . hydrateComponent . bind ( LWC ) ,
5371 consoleSpy,
5472 container,
5573 selector,
5674 } ) ;
5775 }
58-
59- consoleSpy . reset ( ) ;
60-
61- return testResult ;
6276 } ) ;
6377}
0 commit comments