@@ -3,7 +3,7 @@ import * as net from 'net';
33import path from 'path' ;
44import * as grpc from '@grpc/grpc-js' ;
55import asyncRetry from 'async-retry' ;
6- import ava , { TestFn } from 'ava' ;
6+ import ava , { TestFn , ExecutionContext } from 'ava' ;
77import StackUtils from 'stack-utils' ;
88import { v4 as uuid4 } from 'uuid' ;
99import { Client , Connection } from '@temporalio/client' ;
@@ -54,7 +54,7 @@ export async function waitUntil(
5454 intervalMs : number = 100
5555) : Promise < void > {
5656 const endTime = Date . now ( ) + timeoutMs ;
57- for ( ; ; ) {
57+ for ( ; ; ) {
5858 if ( await condition ( ) ) {
5959 return ;
6060 } else if ( Date . now ( ) >= endTime ) {
@@ -98,6 +98,21 @@ export function cleanStackTrace(ostack: string): string {
9898 return normalizedStack ? `${ firstLine } \n${ normalizedStack } ` : firstLine ;
9999}
100100
101+ /**
102+ * Compare stack traces using $CLASS keyword to match any inconsistent identifiers
103+ *
104+ * As of Node 24.6.0 type names are now present on source mapped stack traces which leads
105+ * to different stack traces depending on Node version.
106+ * See [f33e0fcc83954f728fcfd2ef6ae59435bc4af059](https://github.com/nodejs/node/commit/f33e0fcc83954f728fcfd2ef6ae59435bc4af059)
107+ */
108+ export function compareFailureStackTrace < T > ( t : ExecutionContext < T > , actual : string , expected : string ) {
109+ const escapedTrace = expected
110+ . replace ( / [ | \\ { } ( ) [ \] ^ $ + * ? . ] / g, '\\$&' )
111+ . replace ( / - / g, '\\x2d' )
112+ . replaceAll ( '\\$CLASS' , '(?:[A-Za-z]+)' ) ;
113+ t . regex ( actual , RegExp ( `^${ escapedTrace } $` ) ) ;
114+ }
115+
101116function noopTest ( ) : void {
102117 // eslint: this function body is empty and it's okay.
103118}
@@ -168,11 +183,11 @@ export class ByteSkewerPayloadCodec implements PayloadCodec {
168183if ( inWorkflowContext ( ) ) {
169184 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
170185 // @ts -ignore
171- worker . Worker = class { } ; // eslint-disable-line import/namespace
186+ worker . Worker = class { } ; // eslint-disable-line import/namespace
172187
173188 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
174189 // @ts -ignore
175- RealTestWorkflowEnvironment = class { } ; // eslint-disable-line import/namespace
190+ RealTestWorkflowEnvironment = class { } ; // eslint-disable-line import/namespace
176191}
177192
178193export class Worker extends worker . Worker {
@@ -190,15 +205,15 @@ export class TestWorkflowEnvironment extends RealTestWorkflowEnvironment {
190205 ...opts ,
191206 ...( TESTS_CLI_VERSION
192207 ? {
193- server : {
194- ...opts ?. server ,
195- executable : {
196- ...opts ?. server ?. executable ,
197- type : 'cached-download' ,
198- version : TESTS_CLI_VERSION ,
199- } ,
208+ server : {
209+ ...opts ?. server ,
210+ executable : {
211+ ...opts ?. server ?. executable ,
212+ type : 'cached-download' ,
213+ version : TESTS_CLI_VERSION ,
200214 } ,
201- }
215+ } ,
216+ }
202217 : undefined ) ,
203218 } ) ;
204219 }
@@ -208,15 +223,15 @@ export class TestWorkflowEnvironment extends RealTestWorkflowEnvironment {
208223 ...opts ,
209224 ...( TESTS_TIME_SKIPPING_SERVER_VERSION
210225 ? {
211- server : {
212- ...opts ?. server ,
213- executable : {
214- ...opts ?. server ?. executable ,
215- type : 'cached-download' ,
216- version : TESTS_TIME_SKIPPING_SERVER_VERSION ,
217- } ,
226+ server : {
227+ ...opts ?. server ,
228+ executable : {
229+ ...opts ?. server ?. executable ,
230+ type : 'cached-download' ,
231+ version : TESTS_TIME_SKIPPING_SERVER_VERSION ,
218232 } ,
219- }
233+ } ,
234+ }
220235 : undefined ) ,
221236 } ) ;
222237 }
0 commit comments