11#!/usr/bin/env node
22const express = require ( 'express' ) ;
33const Playwright = require ( 'codeceptjs/lib/helper/Playwright' ) ;
4+ const path = require ( 'path' ) ;
45const app = express ( ) ;
56const port = 8191 ;
67app . use ( express . json ( ) ) ;
@@ -47,13 +48,6 @@ app.get('/test/:id', async (req, res) => {
4748 res . status ( 200 ) . json ( tests [ id ] ) ;
4849} ) ;
4950
50- app . post ( '/test' , async ( req , res ) => {
51- const { id, title } = req . body ;
52-
53- if ( ! tests [ id ] ) tests [ id ] = { title }
54-
55- } ) ;
56-
5751app . post ( '/hook' , async ( req , res ) => {
5852 const { command, arguments } = req . body ;
5953
@@ -73,16 +67,19 @@ app.post('/hook', async (req, res) => {
7367 const fileName = `${ id } _failed.png` ;
7468 try {
7569 await playwright . saveScreenshot ( fileName ) ;
76- tests [ id ] . artifacts ||= { }
77- tests [ id ] . artifacts . screenshot = fileName ;
70+ if ( ! tests [ id ] ) tests [ id ] = { title }
71+ if ( ! tests [ id ] . artifacts ) tests [ id ] . artifacts = { }
72+ tests [ id ] . artifacts . screenshot = path . join ( output_dir , fileName ) ;
7873 } catch ( err ) {
74+ console . error ( 'Error saving screenshot: ' , err ) ;
7975 // not matter
8076 }
8177 default :
8278 result = await playwright [ `_${ hook } ` ] ( tests [ id ] ) ;
8379 }
8480
85- res . status ( 200 ) . json ( { result, test : tests [ id ] } ) ;
81+ const test = tests [ id ] ;
82+ res . status ( 200 ) . json ( { result, test } ) ;
8683 } catch ( error ) {
8784 const message = error . inspect ? error . inspect ( ) : error . message ;
8885 res . status ( 500 ) . json ( { message } ) ;
0 commit comments