Tesults API Library
Tesults is a reporting service for test automation results, providing a centralized dashboard to visualize and manage test outcomes. The `tesults` npm package, currently stable at version 1.2.1, offers an API client for Node.js applications to upload test data. This version was published in 2017, and while the package itself has not seen recent updates, the Tesults service continually evolves. Its key differentiators include comprehensive test result management, support for aggregating results from various test frameworks and languages, release record keeping for auditable history, and features like release checklists that consolidate automated and manual test tasks. It aids in identifying flaky tests and managing associated bugs, fostering better release readiness.
Common errors
-
Error: Cannot find module 'tesults'
cause The 'tesults' package is not installed or not resolvable in the current Node.js environment or project.fixRun `npm install tesults` in your project's root directory to install the package. -
TypeError: tesults.results is not a function
cause The `tesults` object was not correctly imported or initialized, or a variable named `tesults` was inadvertently overwritten before calling the `results` method.fixEnsure that `const tesults = require('tesults');` (for CommonJS) or `import tesults from 'tesults';` (for ESM with appropriate configuration) is at the top of your file and that `tesults` has not been reassigned. -
SyntaxError: Cannot use import statement outside a module (or similar ERR_REQUIRE_ESM)
cause You are attempting to use an `import` statement for `tesults` in a CommonJS module file (e.g., a `.js` file without `"type": "module"` in `package.json`), or attempting to `require()` in an ES Module context.fixIf your file is CommonJS, use `const tesults = require('tesults');`. If your project is ES Modules (`"type": "module"` in `package.json` or `.mjs` files), use `import tesults from 'tesults';` or `const tesults = await import('tesults');` and ensure your Node.js version supports ESM (v12.20.0+ is recommended).
Warnings
- gotcha The `tesults` npm package version 1.2.1 was published in 2017. While it functions, it uses older Node.js patterns (e.g., CommonJS modules, callback-based asynchronous operations) that may not align with modern Node.js development, which favors ES Modules and Promises/async-await. This could lead to integration complexities in newer projects or environments.
- gotcha The primary `tesults.results` method uses a Node.js-style callback pattern (`function (err, response)`). Developers expecting Promise-based or async/await syntax in modern JavaScript will need to wrap this in a Promise or adapt their code accordingly, as direct `await tesults.results(...)` will not work as intended.
- gotcha The `target` value, which is your Tesults API token, is crucial for authentication. Hardcoding this token directly into your application's source code is a security risk. If exposed, it could allow unauthorized access to your Tesults project.
Install
-
npm install tesults -
yarn add tesults -
pnpm add tesults
Imports
- tesults
const tesults = require('tesults'); - tesults
import { tesults } from 'tesults';import tesults from 'tesults';
- tesults
const tesults = await import('tesults');
Quickstart
import * as tesults from 'tesults';
const TESULTS_TOKEN = process.env.TESULTS_TOKEN ?? 'your_tesults_token'; // Replace or use environment variable
const data = {
target: TESULTS_TOKEN,
results: {
cases: [
{
name: 'User Login Test',
desc: 'Verify a user can log in with valid credentials.',
suite: 'Authentication Suite',
result: 'pass'
},
{
name: 'Invalid Password Test',
desc: 'Attempt login with an incorrect password and check error message.',
suite: 'Authentication Suite',
result: 'fail',
reason: 'Expected error message "Invalid credentials", but got "User not found".'
},
{
name: 'Data Persistence Check',
desc: 'Ensure saved user data remains after logout and re-login.',
suite: 'Data Integrity',
result: 'pass',
params: {
userType: 'admin',
region: 'US-East'
},
files: [] // Optionally attach log files or screenshots
}
]
}
};
tesults.results(data, function (err, response) {
if (err) {
console.error('Tesults library error:', err);
return;
}
if (response.success) {
console.log('Test results successfully uploaded to Tesults.');
} else {
console.error('Failed to upload results:', response.message);
if (response.warnings && response.warnings.length > 0) {
console.warn('Warnings:', response.warnings);
}
if (response.errors && response.errors.length > 0) {
console.error('Errors:', response.errors);
}
}
});