Skip to content

Commit 9a51f27

Browse files
authored
chore: Update AVA to 4.3 (#989)
1 parent c0d86ce commit 9a51f27

16 files changed

+1169
-2559
lines changed

package-lock.json

Lines changed: 1054 additions & 2459 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"@typescript-eslint/eslint-plugin": "^5.29.0",
6767
"@typescript-eslint/parser": "^5.29.0",
6868
"arg": "^5.0.2",
69-
"ava": "^3.15.0",
69+
"ava": "^4.3.1",
7070
"chalk": "^4.1.2",
7171
"dedent": "^0.7.0",
7272
"eslint": "^8.18.0",

packages/test/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
},
1515
"ava": {
1616
"timeout": "60s",
17-
"concurrency": 1
17+
"concurrency": 1,
18+
"workerThreads": false
1819
},
1920
"keywords": [
2021
"temporal",
@@ -43,7 +44,7 @@
4344
"@temporalio/workflow": "file:../workflow",
4445
"arg": "^5.0.2",
4546
"async-retry": "^1.3.3",
46-
"ava": "^3.15.0",
47+
"ava": "^4.3.1",
4748
"long": "^5.2.0",
4849
"ramda": "^0.28.0",
4950
"rxjs": "7.5.6",

packages/test/src/helpers.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,22 @@ export function cleanOptionalStackTrace(stackTrace: string | undefined | null):
3030
/**
3131
* Relativize paths and remove line and column numbers from stack trace
3232
*/
33-
export function cleanStackTrace(stack: string): string {
33+
export function cleanStackTrace(ostack: string): string {
34+
// For some reason, a code snippet with carret on error location is sometime prepended before the actual stacktrace.
35+
// If there is such a snippet, get rid of it.
36+
const stack = ostack.replace(/^.*\n[ ]*\^[ ]*\n+/gms, '');
37+
3438
const su = new StackUtils({ cwd: path.join(__dirname, '../..') });
35-
const cleaned = su.clean(stack).trimEnd();
36-
return stack.split('\n')[0] + '\n' + (cleaned && cleaned.replace(/:\d+:\d+/g, '').replace(/^/gms, ' at '));
39+
const firstLine = stack.split('\n')[0];
40+
const cleanedStack = su.clean(stack).trimEnd();
41+
const normalizedStack =
42+
cleanedStack &&
43+
cleanedStack
44+
.replace(/:\d+:\d+/g, '')
45+
.replace(/^\s*/gms, ' at ')
46+
.replace(/\[as fn\] /, '');
47+
48+
return normalizedStack ? `${firstLine}\n${normalizedStack}` : firstLine;
3749
}
3850

3951
/**

packages/test/src/integration-tests.ts

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import v8 from 'v8';
44
import { readFileSync } from 'node:fs';
55
import * as grpc from '@grpc/grpc-js';
66
import asyncRetry from 'async-retry';
7-
import anyTest, { Implementation, TestInterface } from 'ava';
7+
import anyTest, { Implementation, TestFn } from 'ava';
88
import dedent from 'dedent';
99
import ms from 'ms';
1010
import { v4 as uuid4 } from 'uuid';
@@ -66,10 +66,10 @@ export interface Context {
6666
runPromise: Promise<void>;
6767
}
6868

69-
const _test = anyTest as TestInterface<Context>;
69+
const _test = anyTest as TestFn<Context>;
7070

7171
export function runIntegrationTests(codec?: PayloadCodec): void {
72-
const test = (name: string, fn: Implementation<Context>) => _test(codec ? 'With codec—' + name : name, fn);
72+
const test = (name: string, fn: Implementation<[], Context>) => _test(codec ? 'With codec—' + name : name, fn);
7373
const dataConverter = { payloadCodecs: codec ? [codec] : [] };
7474
const loadedDataConverter = {
7575
payloadConverter: defaultPayloadConverter,
@@ -236,7 +236,7 @@ export function runIntegrationTests(codec?: PayloadCodec): void {
236236

237237
test('activity-failure with Error', async (t) => {
238238
const { client } = t.context;
239-
const err: WorkflowFailedError = await t.throwsAsync(
239+
const err: WorkflowFailedError | undefined = await t.throwsAsync(
240240
client.execute(workflows.activityFailure, {
241241
taskQueue: 'test',
242242
workflowId: uuid4(),
@@ -246,8 +246,8 @@ export function runIntegrationTests(codec?: PayloadCodec): void {
246246
instanceOf: WorkflowFailedError,
247247
}
248248
);
249-
t.is(err.message, 'Workflow execution failed');
250-
if (!(err.cause instanceof ActivityFailure)) {
249+
t.is(err?.message, 'Workflow execution failed');
250+
if (!(err?.cause instanceof ActivityFailure)) {
251251
t.fail('Expected err.cause to be an instance of ActivityFailure');
252252
return;
253253
}
@@ -260,14 +260,14 @@ export function runIntegrationTests(codec?: PayloadCodec): void {
260260
cleanOptionalStackTrace(err.cause.cause.stack),
261261
dedent`
262262
Error: Fail me
263-
at Activity.throwAnError [as fn] (test/src/activities/index.ts)
263+
at Activity.throwAnError (test/src/activities/index.ts)
264264
`
265265
);
266266
});
267267

268268
test('activity-failure with ApplicationFailure', async (t) => {
269269
const { client } = t.context;
270-
const err: WorkflowFailedError = await t.throwsAsync(
270+
const err: WorkflowFailedError | undefined = await t.throwsAsync(
271271
client.execute(workflows.activityFailure, {
272272
taskQueue: 'test',
273273
workflowId: uuid4(),
@@ -277,8 +277,8 @@ export function runIntegrationTests(codec?: PayloadCodec): void {
277277
instanceOf: WorkflowFailedError,
278278
}
279279
);
280-
t.is(err.message, 'Workflow execution failed');
281-
if (!(err.cause instanceof ActivityFailure)) {
280+
t.is(err?.message, 'Workflow execution failed');
281+
if (!(err?.cause instanceof ActivityFailure)) {
282282
t.fail('Expected err.cause to be an instance of ActivityFailure');
283283
return;
284284
}
@@ -294,7 +294,7 @@ export function runIntegrationTests(codec?: PayloadCodec): void {
294294
dedent`
295295
ApplicationFailure: Fail me
296296
at Function.nonRetryable (common/src/failure.ts)
297-
at Activity.throwAnError [as fn] (test/src/activities/index.ts)
297+
at Activity.throwAnError (test/src/activities/index.ts)
298298
`
299299
);
300300
});
@@ -314,7 +314,7 @@ export function runIntegrationTests(codec?: PayloadCodec): void {
314314

315315
test('child-workflow-failure', async (t) => {
316316
const { client } = t.context;
317-
const err: WorkflowFailedError = await t.throwsAsync(
317+
const err: WorkflowFailedError | undefined = await t.throwsAsync(
318318
client.execute(workflows.childWorkflowFailure, {
319319
taskQueue: 'test',
320320
workflowId: uuid4(),
@@ -323,7 +323,7 @@ export function runIntegrationTests(codec?: PayloadCodec): void {
323323
instanceOf: WorkflowFailedError,
324324
}
325325
);
326-
if (!(err.cause instanceof ChildWorkflowFailure)) {
326+
if (!(err?.cause instanceof ChildWorkflowFailure)) {
327327
return t.fail('Expected err.cause to be an instance of ChildWorkflowFailure');
328328
}
329329
if (!(err.cause.cause instanceof ApplicationFailure)) {
@@ -354,10 +354,10 @@ export function runIntegrationTests(codec?: PayloadCodec): void {
354354
}
355355
const child = client.getHandle(childExecution.workflowId!, childExecution.runId!);
356356
await child.terminate();
357-
const err: WorkflowFailedError = await t.throwsAsync(workflow.result(), {
357+
const err: WorkflowFailedError | undefined = await t.throwsAsync(workflow.result(), {
358358
instanceOf: WorkflowFailedError,
359359
});
360-
if (!(err.cause instanceof ChildWorkflowFailure)) {
360+
if (!(err?.cause instanceof ChildWorkflowFailure)) {
361361
return t.fail('Expected err.cause to be an instance of ChildWorkflowFailure');
362362
}
363363
t.is(err.cause.retryState, RetryState.RETRY_STATE_NON_RETRYABLE_FAILURE);
@@ -368,7 +368,7 @@ export function runIntegrationTests(codec?: PayloadCodec): void {
368368

369369
test('child-workflow-timeout', async (t) => {
370370
const { client } = t.context;
371-
const err: WorkflowFailedError = await t.throwsAsync(
371+
const err: WorkflowFailedError | undefined = await t.throwsAsync(
372372
client.execute(workflows.childWorkflowTimeout, {
373373
taskQueue: 'test',
374374
workflowId: uuid4(),
@@ -377,7 +377,7 @@ export function runIntegrationTests(codec?: PayloadCodec): void {
377377
instanceOf: WorkflowFailedError,
378378
}
379379
);
380-
if (!(err.cause instanceof ChildWorkflowFailure)) {
380+
if (!(err?.cause instanceof ChildWorkflowFailure)) {
381381
return t.fail('Expected err.cause to be an instance of ChildWorkflowFailure');
382382
}
383383
t.is(err.cause.retryState, RetryState.RETRY_STATE_TIMEOUT);
@@ -451,10 +451,10 @@ export function runIntegrationTests(codec?: PayloadCodec): void {
451451
workflowId: uuid4(),
452452
});
453453
await workflow.signal(workflows.interruptSignal, 'just because');
454-
const err: WorkflowFailedError = await t.throwsAsync(workflow.result(), {
454+
const err: WorkflowFailedError | undefined = await t.throwsAsync(workflow.result(), {
455455
instanceOf: WorkflowFailedError,
456456
});
457-
if (!(err.cause instanceof ApplicationFailure)) {
457+
if (!(err?.cause instanceof ApplicationFailure)) {
458458
return t.fail('Expected err.cause to be an instance of ApplicationFailure');
459459
}
460460
t.is(err.cause.message, 'just because');
@@ -467,10 +467,10 @@ export function runIntegrationTests(codec?: PayloadCodec): void {
467467
workflowId: uuid4(),
468468
});
469469
await workflow.signal(workflows.failSignal);
470-
const err: WorkflowFailedError = await t.throwsAsync(workflow.result(), {
470+
const err: WorkflowFailedError | undefined = await t.throwsAsync(workflow.result(), {
471471
instanceOf: WorkflowFailedError,
472472
});
473-
if (!(err.cause instanceof ApplicationFailure)) {
473+
if (!(err?.cause instanceof ApplicationFailure)) {
474474
return t.fail('Expected err.cause to be an instance of ApplicationFailure');
475475
}
476476
t.is(err.cause.message, 'Signal failed');
@@ -483,10 +483,10 @@ export function runIntegrationTests(codec?: PayloadCodec): void {
483483
workflowId: uuid4(),
484484
});
485485
await workflow.signal(workflows.failSignal);
486-
const err: WorkflowFailedError = await t.throwsAsync(workflow.result(), {
486+
const err: WorkflowFailedError | undefined = await t.throwsAsync(workflow.result(), {
487487
instanceOf: WorkflowFailedError,
488488
});
489-
if (!(err.cause instanceof ApplicationFailure)) {
489+
if (!(err?.cause instanceof ApplicationFailure)) {
490490
return t.fail('Expected err.cause to be an instance of ApplicationFailure');
491491
}
492492
t.is(err.cause.message, 'Signal failed');
@@ -952,21 +952,21 @@ export function runIntegrationTests(codec?: PayloadCodec): void {
952952
signalArgs: ['interrupted from signalWithStart'],
953953
});
954954
{
955-
const err: WorkflowFailedError = await t.throwsAsync(ogWF.result(), {
955+
const err: WorkflowFailedError | undefined = await t.throwsAsync(ogWF.result(), {
956956
instanceOf: WorkflowFailedError,
957957
});
958-
if (!(err.cause instanceof ApplicationFailure)) {
958+
if (!(err?.cause instanceof ApplicationFailure)) {
959959
return t.fail('Expected err.cause to be an instance of ApplicationFailure');
960960
}
961961
t.is(err.cause.message, 'interrupted from signalWithStart');
962962
}
963963
// Test returned runId
964964
const workflow = client.getHandle<typeof workflows.interruptableWorkflow>(ogWF.workflowId, ogWF.signaledRunId);
965965
{
966-
const err: WorkflowFailedError = await t.throwsAsync(workflow.result(), {
966+
const err: WorkflowFailedError | undefined = await t.throwsAsync(workflow.result(), {
967967
instanceOf: WorkflowFailedError,
968968
});
969-
if (!(err.cause instanceof ApplicationFailure)) {
969+
if (!(err?.cause instanceof ApplicationFailure)) {
970970
return t.fail('Expected err.cause to be an instance of ApplicationFailure');
971971
}
972972
t.is(err.cause.message, 'interrupted from signalWithStart');

packages/test/src/test-async-completion.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import anyTest, { TestInterface, ExecutionContext } from 'ava';
1+
import anyTest, { TestFn, ExecutionContext } from 'ava';
22
import { Observable, Subject, firstValueFrom } from 'rxjs';
33
import { filter } from 'rxjs/operators';
44
import { v4 as uuid4 } from 'uuid';
@@ -28,7 +28,7 @@ const NOT_FOUND_TASK_TOKEN = new Uint8Array([
2828
]);
2929

3030
const taskQueue = 'async-activity-completion';
31-
const test = anyTest as TestInterface<Context>;
31+
const test = anyTest as TestFn<Context>;
3232

3333
async function activityStarted(t: ExecutionContext<Context>, workflowId: string): Promise<Info> {
3434
return await firstValueFrom(

packages/test/src/test-ephemeral-server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import anyTest, { ExecutionContext, TestInterface } from 'ava';
1+
import anyTest, { ExecutionContext, TestFn } from 'ava';
22
import { v4 as uuid4 } from 'uuid';
33
import { TestWorkflowEnvironment } from '@temporalio/testing';
44
import { bundleWorkflowCode, Worker, WorkflowBundle } from '@temporalio/worker';
@@ -7,7 +7,7 @@ interface Context {
77
bundle: WorkflowBundle;
88
}
99

10-
const test = anyTest as TestInterface<Context>;
10+
const test = anyTest as TestFn<Context>;
1111

1212
test.before(async (t) => {
1313
t.context.bundle = await bundleWorkflowCode({ workflowsPath: require.resolve('./workflows') });

0 commit comments

Comments
 (0)