Registry / http-networking / testrail-js-api

testrail-js-api

JSON →
library0.3.2jsnpmunverified

testrail-js-api is a JavaScript and TypeScript library designed to interact with the TestRail API, providing a programmatic interface for managing test cases, runs, results, and other TestRail entities. The current stable version is 0.3.2. Releases are infrequent, primarily focusing on bug fixes, dependency updates to address vulnerabilities, and adding support for newer TestRail API versions. Key differentiators include its promise-based API for asynchronous operations, native TypeScript type definitions for enhanced development experience, and explicit support for TestRail versions 7.2 and higher, having dropped support for older TestRail installations in version 0.3.0. It serves as a direct wrapper around the TestRail REST API, simplifying automation tasks such as creating test runs, updating results, and fetching project data without requiring manual HTTP request management or complex data serialization.

npm install testrail-js-api
INSTALL
IMPORT
SIG · TESTRAIL-JS-API
T
testrail-js-api
http-networkingjavascriptv0.3.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TestRail
import { TestRail } from 'testrail-js-api';
const TestRail = require('testrail-js-api');
The TestRail class is the primary named export for ESM and TypeScript usage. CommonJS users often incorrectly assign the entire module.exports object when a named export is expected.
AddRunPayload
import type { AddRunPayload } from 'testrail-js-api';
import { AddRunPayload } from 'testrail-js-api';
Type imports like `AddRunPayload` should ideally use `import type` for better tree-shaking and clear distinction between runtime values and compile-time types in TypeScript.
TestRailResponse
import type { TestRailResponse } from 'testrail-js-api';
The library methods return a promise that resolves to an object with `response` and `value` properties. `TestRailResponse` is an example of a type that defines this structure.

Demonstrates how to instantiate the TestRail client, create a new test run, and add a test result for a specific test case, including basic error handling.

import { TestRail, AddRunPayload } from 'testrail-js-api'; const host = process.env.TESTRAIL_HOST ?? 'https://your-testrail.com'; const user = process.env.TESTRAIL_USER ?? 'your_username'; const apiKey = process.env.TESTRAIL_API_KEY ?? 'your_api_key'; async function createTestRunAndAddResult() { const testrail = new TestRail(host, user, apiKey); const projectId = 1; // Replace with your TestRail Project ID try { const runPayload: AddRunPayload = { suite_id: 2, // Replace with your Test Suite ID name: `Automated Test Run - ${new Date().toISOString()}`, description: 'Test run created via testrail-js-api', include_all: true, }; console.log('Creating new test run...'); const { value: run } = await testrail.addRun(projectId, runPayload); console.log(`Test Run created: ID ${run?.id}, URL: ${run?.url}`); if (run?.id) { // Example: Add a passing result to a test case in the new run const testCaseId = 3; // Replace with a Test Case ID from your suite const resultPayload = { status_id: 1, comment: 'Test passed successfully via API.' }; // 1 for Passed console.log(`Adding result to Test Case ${testCaseId} in Run ${run.id}...`); await testrail.addResultForCase(run.id, testCaseId, resultPayload); console.log(`Result added for Test Case ${testCaseId}.`); } } catch (error: any) { console.error('An error occurred:', error.message); if (error.response?.data) { console.error('TestRail API Error Details:', error.response.data); } } } createTestRunAndAddResult();
Debug
Known issues
breakingVersion 0.3.0 introduced a breaking change by dropping support for all TestRail versions lower than 7.2. Users on older TestRail instances must remain on `testrail-js-api` versions prior to 0.3.0.
fix
Upgrade your TestRail instance to version 7.2 or higher, or downgrade `testrail-js-api` to a version older than 0.3.0 if an upgrade is not possible.
affects: >=0.3.0
gotchaTo successfully upload attachments to test results using the `add_attachment_to_result` endpoints, the 'ability to edit test results' option must be explicitly enabled under 'Site Settings' in your TestRail instance.
fix
Ensure 'Edit test results' is enabled in TestRail's Site Settings for the corresponding project.
affects: >=0.1.0
gotchaThe package has historically required dependency updates to address vulnerabilities (e.g., in v0.2.1 and v0.3.2). Users should regularly update the library to mitigate potential supply chain risks and ensure they are running secure versions.
fix
Regularly run `npm update testrail-js-api` or `yarn upgrade testrail-js-api` and audit your project dependencies.
affects: >=0.1.0
Errors
Common errors & fixes
TestRail API Error: Authentication failed or Access denied
Incorrect TestRail host URL, invalid username, or an expired/wrong API key used during client initialization. The user may also lack API access permissions.
fix
Verify the `host`, `user`, and `apiKey` credentials against your TestRail site settings. Ensure the user account has 'API access' enabled and correct project permissions.
TestRail API Error: The requested resource does not exist or you do not have the permissions to access it.
An invalid ID (e.g., project ID, suite ID, run ID, case ID) was provided for an API call, or the authenticated user lacks necessary permissions for the specific resource or action.
fix
Double-check all IDs passed to API methods for correctness. Confirm the API user has sufficient permissions within TestRail for the target project and the operations being attempted.
TypeError: testrail.addRun is not a function
The `TestRail` constructor was not properly imported or instantiated. This often happens in CommonJS when attempting `const { TestRail } = require('testrail-js-api')` if `TestRail` is the default export, or `const TestRail = require('testrail-js-api')` if it's a named export.
fix
For ESM/TypeScript, use `import { TestRail } from 'testrail-js-api';`. For CommonJS, use `const { TestRail } = require('testrail-js-api');` and then `new TestRail(...)`.
Upgrade
Version history
0.3.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
43 hits · last 30 days
node
38
OpenAI (training)
1
Resources
testrail-js-api — npm install testrail-js-api · libregistry