Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@temporalio/testing

Package Overview
Dependencies
Maintainers
7
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@temporalio/testing

Temporal.io SDK Testing sub-package

  • 1.11.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
127K
increased by24.63%
Maintainers
7
Weekly downloads
 
Created

What is @temporalio/testing?

@temporalio/testing is a package designed to facilitate the testing of Temporal workflows and activities. It provides tools to create test environments, mock activities, and validate workflow executions, ensuring that your Temporal-based applications behave as expected.

What are @temporalio/testing's main functionalities?

Test Environment Setup

This feature allows you to set up a test environment for running Temporal workflows. The `TestWorkflowEnvironment.create()` method initializes the environment, making it possible to run and test workflows in isolation.

const { TestWorkflowEnvironment } = require('@temporalio/testing');

async function setupTestEnv() {
  const testEnv = await TestWorkflowEnvironment.create();
  return testEnv;
}

setupTestEnv().then(env => console.log('Test environment setup complete.')).catch(err => console.error(err));

Mock Activities

This feature allows you to mock activities within your workflows. By providing mock implementations of activities, you can test workflows without relying on the actual activity implementations, making tests faster and more reliable.

const { TestWorkflowEnvironment } = require('@temporalio/testing');
const { Worker } = require('@temporalio/worker');

async function mockActivities() {
  const testEnv = await TestWorkflowEnvironment.create();
  const worker = await Worker.create({
    activities: {
      myActivity: async () => 'mocked result'
    },
    taskQueue: 'test-task-queue'
  });
  await worker.run();
}

mockActivities().then(() => console.log('Activities mocked.')).catch(err => console.error(err));

Workflow Execution Validation

This feature allows you to validate the execution of workflows. By using the `WorkflowClient` to execute workflows within the test environment, you can ensure that workflows produce the expected results.

const { TestWorkflowEnvironment } = require('@temporalio/testing');
const { Worker, WorkflowClient } = require('@temporalio/client');

async function validateWorkflowExecution() {
  const testEnv = await TestWorkflowEnvironment.create();
  const client = new WorkflowClient();
  const result = await client.execute('myWorkflow', { taskQueue: 'test-task-queue' });
  console.log('Workflow result:', result);
}

validateWorkflowExecution().then(() => console.log('Workflow execution validated.')).catch(err => console.error(err));

Other packages similar to @temporalio/testing

Keywords

FAQs

Package last updated on 20 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc