@@ -41,6 +41,8 @@ import { getTags } from "./environment-helpers";
4141
4242import { ensureIsAbsolute } from "./helpers" ;
4343
44+ import { createTimestamp } from "./messages-helpers" ;
45+
4446/**
4547 * Work-around for the fact that some Cypress versions pre v10 were missing this property in their types.
4648 */
@@ -84,12 +86,26 @@ export async function beforeRunHandler(config: Cypress.PluginConfigOptions) {
8486 ) ;
8587
8688 await fs . rm ( messagesPath , { force : true } ) ;
89+
90+ const testRunStarted : messages . Envelope = {
91+ testRunStarted : {
92+ timestamp : createTimestamp ( ) ,
93+ } ,
94+ } ;
95+
96+ await fs . mkdir ( path . dirname ( messagesPath ) , { recursive : true } ) ;
97+
98+ await fs . writeFile ( messagesPath , JSON . stringify ( testRunStarted ) + "\n" ) ;
8799}
88100
89101export async function afterRunHandler ( config : Cypress . PluginConfigOptions ) {
90102 const preprocessor = await resolve ( config , config . env , "/" ) ;
91103
92- if ( ! preprocessor . json . enabled && ! preprocessor . html . enabled ) {
104+ if (
105+ ! preprocessor . messages . enabled &&
106+ ! preprocessor . json . enabled &&
107+ ! preprocessor . html . enabled
108+ ) {
93109 return ;
94110 }
95111
@@ -104,6 +120,22 @@ export async function afterRunHandler(config: Cypress.PluginConfigOptions) {
104120 return ;
105121 }
106122
123+ if ( preprocessor . messages . enabled ) {
124+ const testRunFinished : messages . Envelope = {
125+ testRunFinished : {
126+ /**
127+ * We're missing a "success" attribute here, but cucumber-js doesn't output it, so I won't.
128+ * Mostly because I don't want to look into the semantics of it right now.
129+ */
130+ timestamp : createTimestamp ( ) ,
131+ } as messages . TestRunFinished ,
132+ } ;
133+
134+ await fs . writeFile ( messagesPath , JSON . stringify ( testRunFinished ) + "\n" , {
135+ flag : "a" ,
136+ } ) ;
137+ }
138+
107139 if ( preprocessor . json . enabled ) {
108140 const jsonPath = ensureIsAbsolute (
109141 config . projectRoot ,
@@ -213,8 +245,6 @@ export async function afterSpecHandler(
213245 )
214246 ) ;
215247 } else {
216- await fs . mkdir ( path . dirname ( messagesPath ) , { recursive : true } ) ;
217-
218248 await fs . writeFile (
219249 messagesPath ,
220250 currentSpecMessages . map ( ( message ) => JSON . stringify ( message ) ) . join ( "\n" ) +
0 commit comments