Skip to content

Commit 9fc27d1

Browse files
clean up
1 parent aa1bf79 commit 9fc27d1

12 files changed

Lines changed: 37 additions & 83 deletions

File tree

packages/ai-sdk/src/__tests__/test-ai-sdk.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -542,11 +542,8 @@ test('callToolActivity awaits tool.execute before closing MCP client', async (t)
542542
}) as Record<string, (args: unknown) => Promise<unknown>>;
543543

544544
// Get the callTool activity
545-
const callToolActivity = activities['testServer-callTool'];
546-
if (!callToolActivity) {
547-
t.fail('callToolActivity should exist');
548-
return;
549-
}
545+
const callToolActivity = activities['testServer-callTool']!;
546+
t.truthy(callToolActivity, 'callToolActivity should exist');
550547

551548
// Call the activity
552549
const result = await callToolActivity({

packages/interceptors-opentelemetry/src/__tests__/test-otel.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import {
2727
import { WorkflowInboundCallsInterceptor, WorkflowOutboundCallsInterceptor } from '@temporalio/workflow';
2828

2929
import {
30-
isSet,
3130
RUN_INTEGRATION_TESTS,
3231
loadHistory as loadHistoryBase,
3332
createTestWorkflowBundle,

packages/interceptors-opentelemetry/src/__tests__/workflows/signal-start-otel.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ import {
77

88
export const startSignal = workflow.defineSignal('startSignal');
99

10-
interface LocalActivities {
11-
a(): Promise<string>;
12-
b(): Promise<string>;
13-
c(): Promise<string>;
14-
}
15-
16-
const { a, b, c } = workflow.proxyLocalActivities<LocalActivities>({
10+
const { a, b, c } = workflow.proxyLocalActivities<{
11+
a: () => Promise<string>;
12+
b: () => Promise<string>;
13+
c: () => Promise<string>;
14+
}>({
1715
scheduleToCloseTimeout: '1m',
1816
});
1917

packages/test-helpers/src/ava-helpers.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import ava, { TestFn } from 'ava';
22
import { inWorkflowContext } from '@temporalio/workflow';
3-
import { RUN_TIME_SKIPPING_TESTS } from './flags';
43

54
function noopTest(): void {
65
// eslint: this function body is empty and it's okay.
@@ -20,6 +19,4 @@ noopTest.skip = () => noopTest;
2019
*/
2120
export const test: TestFn<unknown> = inWorkflowContext() ? (noopTest as any) : ava;
2221

23-
export const testTimeSkipping = RUN_TIME_SKIPPING_TESTS ? test : noopTest;
24-
2522
export { noopTest };

packages/test-helpers/src/bundler.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import type { BundleOptions } from '@temporalio/worker';
55
* These are modules that should be ignored when bundling workflow code.
66
*/
77
export const baseBundlerIgnoreModules = [
8+
// This is a bit ugly but it does the trick, when a test that includes workflow code tries to import a forbidden
9+
// workflow module, add it to this list:
810
'@temporalio/common/lib/internal-non-workflow',
911
'@temporalio/activity',
1012
'@temporalio/client',

packages/test-helpers/src/flags.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { inWorkflowContext } from '@temporalio/workflow';
22

3-
/**
4-
* Parse a boolean environment variable
5-
*/
63
export function isSet(env: string | undefined, def: boolean): boolean {
74
if (env === undefined) return def;
85
env = env.toLocaleLowerCase();

packages/test-helpers/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export { baseBundlerIgnoreModules, createBaseBundlerOptions } from './bundler';
2727
export { ByteSkewerPayloadCodec } from './codecs';
2828

2929
// AVA helpers
30-
export { test, testTimeSkipping, noopTest } from './ava-helpers';
30+
export { test, noopTest } from './ava-helpers';
3131

3232
// Wrappers
3333
export { Worker, TestWorkflowEnvironment } from './wrappers';

packages/test/src/helpers.ts

Lines changed: 12 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import * as fs from 'fs/promises';
21
import path from 'path';
32
import * as grpc from '@grpc/grpc-js';
43
import asyncRetry from 'async-retry';
54
import { v4 as uuid4 } from 'uuid';
65
import { Client, Connection } from '@temporalio/client';
7-
import { historyToJSON } from '@temporalio/common/lib/proto-utils';
86
import * as iface from '@temporalio/proto';
97

108
// Re-export from test-helpers
@@ -13,53 +11,32 @@ export {
1311
waitUntil,
1412
u8,
1513
approximatelyEqual,
16-
isSet,
1714
RUN_INTEGRATION_TESTS,
1815
REUSE_V8_CONTEXT,
1916
RUN_TIME_SKIPPING_TESTS,
20-
TESTS_CLI_VERSION,
21-
TESTS_TIME_SKIPPING_SERVER_VERSION,
2217
cleanStackTrace,
2318
cleanOptionalStackTrace,
2419
compareStackTrace,
2520
getRandomPort,
2621
ByteSkewerPayloadCodec,
2722
test,
28-
testTimeSkipping,
23+
noopTest,
2924
Worker,
3025
TestWorkflowEnvironment,
31-
baseBundlerIgnoreModules,
26+
} from '@temporalio/test-helpers';
27+
import {
28+
createBaseBundlerOptions,
29+
loadHistory as loadHistoryBase,
30+
saveHistory as saveHistoryBase,
3231
} from '@temporalio/test-helpers';
3332

3433
/**
3534
* Package-specific bundler options that include local activity and mock-native-worker modules.
3635
*/
37-
export const bundlerOptions = {
38-
// This is a bit ugly but it does the trick, when a test that includes workflow code tries to import a forbidden
39-
// workflow module, add it to this list:
40-
ignoreModules: [
41-
'@temporalio/common/lib/internal-non-workflow',
42-
'@temporalio/activity',
43-
'@temporalio/client',
44-
'@temporalio/testing',
45-
'@temporalio/nexus',
46-
'@temporalio/worker',
47-
'ava',
48-
'crypto',
49-
'module',
50-
'path',
51-
'stack-utils',
52-
'@grpc/grpc-js',
53-
'async-retry',
54-
'uuid',
55-
'net',
56-
'fs/promises',
57-
'timers',
58-
'timers/promises',
59-
require.resolve('./activities'),
60-
require.resolve('./mock-native-worker'),
61-
],
62-
};
36+
export const bundlerOptions = createBaseBundlerOptions([
37+
require.resolve('./activities'),
38+
require.resolve('./mock-native-worker'),
39+
]);
6340

6441
// Some of our tests expect "default custom search attributes" to exists, which used to be the case
6542
// in all deployment with support for advanced visibility. However, this might no longer be true in
@@ -119,24 +96,16 @@ export async function registerDefaultCustomSearchAttributes(connection: Connecti
11996

12097
/**
12198
* Load a history file from the history_files directory.
122-
* This is kept here for backward compatibility with existing tests.
12399
*/
124100
export async function loadHistory(fname: string): Promise<iface.temporal.api.history.v1.History> {
125-
const isJson = fname.endsWith('json');
126101
const fpath = path.resolve(__dirname, `../history_files/${fname}`);
127-
if (isJson) {
128-
const hist = await fs.readFile(fpath, 'utf8');
129-
return JSON.parse(hist);
130-
} else {
131-
const hist = await fs.readFile(fpath);
132-
return iface.temporal.api.history.v1.History.decode(hist);
133-
}
102+
return loadHistoryBase(fpath);
134103
}
135104

136105
/**
137106
* Save a history file to the history_files directory.
138107
*/
139108
export async function saveHistory(fname: string, history: iface.temporal.api.history.v1.IHistory): Promise<void> {
140109
const fpath = path.resolve(__dirname, `../history_files/${fname}`);
141-
await fs.writeFile(fpath, historyToJSON(history));
110+
return saveHistoryBase(fpath, history);
142111
}

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,22 @@ import { v4 as uuid4 } from 'uuid';
44
import { bundleWorkflowCode, WorkflowBundle } from '@temporalio/worker';
55
import { Connection } from '@temporalio/client';
66
import { TestWorkflowEnvironment as RealTestWorkflowEnvironment } from '@temporalio/testing';
7-
import { Worker, TestWorkflowEnvironment, testTimeSkipping as anyTestTimeSkipping, getRandomPort } from './helpers';
7+
import {
8+
Worker,
9+
TestWorkflowEnvironment,
10+
RUN_TIME_SKIPPING_TESTS,
11+
noopTest,
12+
test as testFromHelpers,
13+
getRandomPort,
14+
} from './helpers';
815

916
interface Context {
1017
bundle: WorkflowBundle;
1118
taskQueue: string;
1219
}
1320

1421
const test = anyTest as TestFn<Context>;
15-
const testTimeSkipping = anyTestTimeSkipping as TestFn<Context>;
22+
const testTimeSkipping = (RUN_TIME_SKIPPING_TESTS ? testFromHelpers : noopTest) as TestFn<Context>;
1623

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

packages/testing/src/__tests__/test-testenvironment.ts renamed to packages/test/src/test-testenvironment-timeskipping.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import * as process from 'process';
2-
import ava, { TestFn } from 'ava';
2+
import { TestFn } from 'ava';
33
import { v4 as uuid4 } from 'uuid';
44
import { WorkflowFailedError } from '@temporalio/client';
5-
import { bundleWorkflowCode, Worker, WorkflowBundleWithSourceMap } from '@temporalio/worker';
6-
import { TestWorkflowEnvironment, workflowInterceptorModules } from '..';
5+
import { bundleWorkflowCode, WorkflowBundleWithSourceMap } from '@temporalio/worker';
6+
import { workflowInterceptorModules } from '@temporalio/testing';
7+
import { RUN_TIME_SKIPPING_TESTS, test, noopTest, Worker, TestWorkflowEnvironment } from './helpers';
78
import {
89
assertFromWorkflow,
910
asyncChildStarter,
@@ -13,17 +14,6 @@ import {
1314
waitOnSignalWithTimeout,
1415
} from './workflows/testenv-test-workflows';
1516

16-
// Time-skipping tests are not supported on Linux ARM64
17-
const RUN_TIME_SKIPPING_TESTS = !(process.platform === 'linux' && process.arch === 'arm64');
18-
19-
function noopTest(): void {
20-
// eslint: this function body is empty and it's okay.
21-
}
22-
noopTest.serial = () => undefined;
23-
noopTest.before = () => undefined;
24-
noopTest.after = Object.assign(() => undefined, { always: () => undefined });
25-
26-
const test: TestFn<unknown> = ava;
2717
const testTimeSkipping = RUN_TIME_SKIPPING_TESTS ? test : (noopTest as unknown as typeof test);
2818

2919
interface Context {

0 commit comments

Comments
 (0)