温馨提示:本站仅提供公开网络链接索引服务,不存储、不篡改任何第三方内容,所有内容版权归原作者所有
AI智能索引来源:http://www.bun.com/reference/node/test/default/TestContext/workerId
点击访问原文链接

property workerId | Node.js node:test module | Bun

property workerId | Node.js node:test module | Bun { // Worker ID is available via context console.log(`Running in worker ${t.workerId}`); // Or via environment variable (available at import time) const workerId = process.env.NODE_TEST_WORKER_ID; // Use workerId to allocate separate resources per worker }); ```"/> { // Worker ID is available via context console.log(`Running in worker ${t.workerId}`); // Or via environment variable (available at import time) const workerId = process.env.NODE_TEST_WORKER_ID; // Use workerId to allocate separate resources per worker }); ```"/>BuildDocsReferenceGuidesBlogDiscord/node:test/default/TestContext/workerIdPworkerId

Search the reference...

/

BuildDocsReferenceGuidesBlogDiscord/node:test/default/TestContext/workerIdPworkerId

property

test.default.TestContext.workerId { // Worker ID is available via context console.log(`Running in worker ${t.workerId}`); // Or via environment variable (available at import time) const workerId = process.env.NODE_TEST_WORKER_ID; // Use workerId to allocate separate resources per worker }); ```" data-algolia-static="false" data-algolia-merged="false" data-type="Property">readonly workerId: undefined | number

The unique identifier of the worker running the current test file. This value is derived from the NODE_TEST_WORKER_ID environment variable. When running tests with --test-isolation=process (the default), each test file runs in a separate child process and is assigned a worker ID from 1 to N, where N is the number of concurrent workers. When running with --test-isolation=none, all tests run in the same process and the worker ID is always 1. This value is undefined when not running in a test context.

This property is useful for splitting resources (like database connections or server ports) across concurrent test files:

import { test } from 'node:test';
import { process } from 'node:process';

test('database operations', async (t) => {
// Worker ID is available via context
console.log(`Running in worker ${t.workerId}`);

// Or via environment variable (available at import time)
const workerId = process.env.NODE_TEST_WORKER_ID;
// Use workerId to allocate separate resources per worker
});

Resources

ReferenceDocsGuidesDiscordMerch StoreGitHubBlog 

Toolkit

RuntimePackage managerTest runnerBundlerPackage runner

Project

Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicense

Baked with ❤️ in San Francisco

We're hiring →

property workerId | Node.js node:test module | Bun,AI智能索引,全网链接索引,智能导航,网页索引

    The unique identifier of the worker running the current test file. This value is derived from the `NODE_TEST_WORKER_ID` environment variable. When running tests with `--test-isolation=process` (the default), each test file runs in a separate child process and is assigned a worker ID from 1 to N, where N is the number of concurrent workers. When running with `--test-isolation=none`, all tests run in the same process and the worker ID is always 1. This value is `undefined` when not running in a test context. This property is useful for splitting resources (like database connections or server ports) across concurrent test files: ```js import { test } from