forked from temporalio/samples-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkflows.test.ts
More file actions
49 lines (41 loc) · 1.42 KB
/
Copy pathworkflows.test.ts
File metadata and controls
49 lines (41 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { TestWorkflowEnvironment } from '@temporalio/testing';
import { Worker, Runtime, DefaultLogger, LogEntry } from '@temporalio/worker';
import { v4 as uuid4 } from 'uuid';
import { httpWorkflow } from './workflows';
import { WorkflowCoverage } from '@temporalio/nyc-test-coverage';
let testEnv: TestWorkflowEnvironment;
const workflowCoverage = new WorkflowCoverage();
beforeAll(async () => {
// Use console.log instead of console.error to avoid red output
// Filter INFO log messages for clearer test output
Runtime.install({
logger: new DefaultLogger('WARN', (entry: LogEntry) => console.log(`[${entry.level}]`, entry.message)),
});
testEnv = await TestWorkflowEnvironment.createTimeSkipping();
});
afterAll(async () => {
await testEnv?.teardown();
});
afterAll(() => {
workflowCoverage.mergeIntoGlobalCoverage();
});
test('httpWorkflow with mock activity', async () => {
const { client, nativeConnection } = testEnv;
const worker = await Worker.create(
workflowCoverage.augmentWorkerOptions({
connection: nativeConnection,
taskQueue: 'test',
workflowsPath: require.resolve('./workflows'),
activities: {
makeHTTPRequest: async () => '99',
},
})
);
await worker.runUntil(async () => {
const result = await client.workflow.execute(httpWorkflow, {
workflowId: uuid4(),
taskQueue: 'test',
});
expect(result).toEqual('The answer is 99');
});
});