@@ -22,15 +22,15 @@ import { setBoxedStackPrefixes, asLocator, createGuid, currentZone, debugMode, i
22
22
23
23
import { currentTestInfo } from './common/globals' ;
24
24
import { rootTestType } from './common/testType' ;
25
- import { stripAnsiEscapes } from './util ' ;
25
+ import { attachErrorPrompts } from './prompt ' ;
26
26
27
- import type { MetadataWithCommitInfo } from './isomorphic/types' ;
28
27
import type { Fixtures , PlaywrightTestArgs , PlaywrightTestOptions , PlaywrightWorkerArgs , PlaywrightWorkerOptions , ScreenshotMode , TestInfo , TestType , VideoMode } from '../types/test' ;
29
28
import type { ContextReuseMode } from './common/config' ;
30
29
import type { TestInfoImpl , TestStepInternal } from './worker/testInfo' ;
31
30
import type { ApiCallData , ClientInstrumentation , ClientInstrumentationListener } from '../../playwright-core/src/client/clientInstrumentation' ;
32
31
import type { Playwright as PlaywrightImpl } from '../../playwright-core/src/client/playwright' ;
33
32
import type { APIRequestContext , Browser , BrowserContext , BrowserContextOptions , LaunchOptions , Page , Tracing , Video } from 'playwright-core' ;
33
+
34
34
export { expect } from './matchers/expect' ;
35
35
export const _baseTest : TestType < { } , { } > = rootTestType . test ;
36
36
@@ -619,6 +619,7 @@ class ArtifactsRecorder {
619
619
620
620
private _screenshotRecorder : SnapshotRecorder ;
621
621
private _pageSnapshot : string | undefined ;
622
+ private _sourceCache : Map < string , string > = new Map ( ) ;
622
623
623
624
constructor ( playwright : PlaywrightImpl , artifactsDir : string , screenshot : ScreenshotOption ) {
624
625
this . _playwright = playwright ;
@@ -701,71 +702,7 @@ class ArtifactsRecorder {
701
702
} ) ) ) ;
702
703
703
704
await this . _screenshotRecorder . persistTemporary ( ) ;
704
- await this . _attachErrorPrompts ( ) ;
705
- }
706
-
707
- private async _attachErrorPrompts ( ) {
708
- if ( process . env . PLAYWRIGHT_NO_COPY_PROMPT )
709
- return ;
710
-
711
- if ( this . _testInfo . errors . length === 0 )
712
- return ;
713
-
714
- const testSources = await fs . promises . readFile ( this . _testInfo . file , 'utf-8' ) ;
715
- for ( const [ index , error ] of this . _testInfo . errors . entries ( ) ) {
716
- if ( this . _testInfo . attachments . find ( a => a . name === `_prompt-${ index } ` ) )
717
- continue ;
718
-
719
- const metadata = this . _testInfo . config . metadata as MetadataWithCommitInfo ;
720
-
721
- const promptParts = [
722
- `My Playwright test failed.` ,
723
- `Explain why, be concise, respect Playwright best practices.` ,
724
- '' ,
725
- `Failed test: ${ this . _testInfo . titlePath . join ( ' >> ' ) } ` ,
726
- '' ,
727
- 'Error:' ,
728
- '' ,
729
- '```' ,
730
- stripAnsiEscapes ( error . stack || error . message || '' ) ,
731
- '```' ,
732
- ] ;
733
-
734
- if ( this . _pageSnapshot ) {
735
- promptParts . push (
736
- '' ,
737
- 'Page snapshot:' ,
738
- '```yaml' ,
739
- this . _pageSnapshot ,
740
- '```' ,
741
- ) ;
742
- }
743
-
744
- if ( metadata . gitDiff ) {
745
- promptParts . push (
746
- '' ,
747
- 'Local changes:' ,
748
- '```diff' ,
749
- metadata . gitDiff ,
750
- '```' ,
751
- ) ;
752
- }
753
-
754
- promptParts . push (
755
- '' ,
756
- 'Test file:' ,
757
- '```ts' ,
758
- `// ${ this . _testInfo . file } ` ,
759
- testSources ,
760
- '```' ,
761
- ) ;
762
-
763
- this . _testInfo . _attach ( {
764
- name : `_prompt-${ index } ` ,
765
- contentType : 'text/markdown' ,
766
- body : Buffer . from ( promptParts . join ( '\n' ) ) ,
767
- } , undefined ) ;
768
- }
705
+ await attachErrorPrompts ( this . _testInfo , this . _sourceCache , this . _pageSnapshot ) ;
769
706
}
770
707
771
708
private async _startTraceChunkOnContextCreation ( tracing : Tracing ) {
0 commit comments