@@ -18,6 +18,7 @@ import type { Readable, Writable } from 'node:stream';
1818import { TestSession } from '@salesforce/cli-plugins-testkit' ;
1919import { Connection , Messages , Org } from '@salesforce/core' ;
2020import { expect } from 'chai' ;
21+ import { type Browser , type Page } from 'playwright' ;
2122import { MetaUtils } from '../../../../../src/shared/metaUtils.js' ;
2223import { getSession } from '../helpers/sessionUtils.js' ;
2324import {
@@ -38,6 +39,8 @@ describe('lightning preview component prompts', () => {
3839 let session : TestSession ;
3940 let childProcess : ChildProcessByStdio < Writable , Readable , Readable > | undefined ;
4041 let connection : Connection ;
42+ let browser : Browser ;
43+ let page : Page ;
4144
4245 before ( async ( ) => {
4346 session = await getSession ( ) ;
@@ -51,16 +54,14 @@ describe('lightning preview component prompts', () => {
5154 await MetaUtils . setMyDomainFirstPartyCookieRequirement ( connection , true ) ;
5255 } ) ;
5356
54- afterEach ( ( ) => {
57+ afterEach ( async ( ) => {
58+ if ( page ) await page . close ( ) ;
59+ if ( browser ) await browser . close ( ) ;
5560 if ( childProcess ?. kill ) {
5661 childProcess . kill ( 'SIGKILL' ) ;
5762 }
5863 } ) ;
5964
60- after ( async ( ) => {
61- await session ?. clean ( ) ;
62- } ) ;
63-
6465 it ( 'should error out when local dev is not enabled and AUTO_ENABLE_LOCAL_DEV is false' , async ( ) => {
6566 childProcess = startLightningDevServer ( session . project ?. dir , session . hubOrg . username , {
6667 AUTO_ENABLE_LOCAL_DEV : false ,
@@ -95,14 +96,11 @@ describe('lightning preview component prompts', () => {
9596 childProcess . stdin ?. write ( '\n' ) ;
9697
9798 const previewUrl = await getPreviewURL ( childProcess . stdout ) ;
98- const { browser, page } = await getPreview ( previewUrl , session . hubOrg . accessToken ) ;
99+ ( { browser, page } = await getPreview ( previewUrl , session . hubOrg . accessToken ) ) ;
99100
100- // Assert that it rendered correctly
101101 const greetingLocator = page . getByText ( 'Hello World' ) ;
102+ await greetingLocator . waitFor ( { state : 'visible' } ) ;
102103 expect ( await greetingLocator . textContent ( ) ) . to . equal ( 'Hello World' ) ;
103-
104- if ( page ) await page . close ( ) ;
105- if ( browser ) await browser . close ( ) ;
106104 } ) ;
107105
108106 it ( 'should render without a prompt and disable first party cookies when AUTO_ENABLE_LOCAL_DEV=true' , async ( ) => {
@@ -114,16 +112,13 @@ describe('lightning preview component prompts', () => {
114112 ) ;
115113
116114 const previewUrl = await getPreviewURL ( childProcess . stdout ) ;
117- const { browser, page } = await getPreview ( previewUrl , session . hubOrg . accessToken ) ;
115+ ( { browser, page } = await getPreview ( previewUrl , session . hubOrg . accessToken ) ) ;
118116
119- // Assert that it rendered correctly
120117 const greetingLocator = page . getByText ( 'Hello World' ) ;
118+ await greetingLocator . waitFor ( { state : 'visible' } ) ;
121119 expect ( await greetingLocator . textContent ( ) ) . to . equal ( 'Hello World' ) ;
122120
123121 // Command with AUTO_ENABLE_LOCAL_DEV calls ensureFirstPartyCookiesNotRequired, so requirement is disabled
124122 expect ( await MetaUtils . isFirstPartyCookieRequired ( connection ) ) . to . be . false ;
125-
126- if ( page ) await page . close ( ) ;
127- if ( browser ) await browser . close ( ) ;
128123 } ) ;
129124} ) ;
0 commit comments