Testee Client Adapters
testee-client is a client-side library providing adapters for popular JavaScript testing frameworks such as Mocha, QUnit (versions 1 and 2), and Jasmine (versions 1 and 2). It functions by converting test results from these frameworks into Feathers service calls for `runs`, `suites`, `tests`, and `coverages`, which are then reported to a `testee` runner server. The current stable version is 0.5.6. The package appears to be in a maintenance phase, with releases addressing specific environment conflicts or improving existing integrations rather than introducing major new features. Its primary role is to bridge the gap between in-browser test execution and a centralized reporting server, allowing for custom configuration of the base URL, communication provider (sockets or REST), and even custom socket instances. It requires manual initialization (`window.Testee.init()`) in environments where test files are loaded asynchronously to prevent test runners from executing prematurely.
Common errors
-
Error: Cannot find module 'testee-client/dist/testee-client.js' (or similar file not found errors for dist/ files)
cause This error most commonly occurs when attempting to use `testee-client@0.5.2`, which was released without the necessary distribution files in its `dist/` folder, making the package effectively unusable.fixEnsure you are using `testee-client@0.5.3` or a later version, as version 0.5.2 was a faulty release and is missing critical files. -
process.cwd() returns an empty string or an unexpected path in StealJS/steal-tools environments
cause A specific conflict between the `steal-tools` process shim and `testee-client`'s internal shim in versions prior to 0.5.6 caused `process.cwd()` to return an incorrect or empty value, affecting tests relying on it.fixUpgrade `testee-client` to version 0.5.6 or higher. This version includes a fix that rebuilds the distribution without the conflicting `steal-tools` process shim. -
Uncaught ReferenceError: Testee is not defined
cause The `testee-client.js` script was not loaded in the browser, or `window.Testee` was accessed before the script had fully executed and populated the global object.fixEnsure that the `<script src="path/to/testee-client.js"></script>` tag is correctly placed in your HTML and executed before any code that attempts to access `window.Testee` or call `window.Testee.init()`.
Warnings
- breaking Version 0.5.2 was a faulty release distributed without the required `dist/` folder, rendering the package unusable if installed. Users attempting to use this specific version will encounter file not found errors.
- gotcha In version 0.5.6, a conflict was identified where `steal-tools`'s process shim could inadvertently override `testee-client`'s intended process shim. This led to incorrect `process.cwd()` results (e.g., returning an empty string instead of `/`) in certain build environments, specifically affecting projects using StealJS.
- gotcha When integrating `testee-client` with test frameworks that load test files asynchronously (e.g., using `define` with RequireJS or StealJS), it is critical to prevent the test framework from running automatically. `window.Testee.init()` must then be called manually *after* all test files are loaded and before the framework's `run` method is invoked.
Install
-
npm install testee-client -
yarn add testee-client -
pnpm add testee-client
Imports
- Testee
import { Testee } from 'testee-client'<!-- In HTML: --> <script type="text/javascript" src="testee-client.js"></script> <script type="text/javascript"> window.Testee = { baseURL: 'http://testee-server.com/' }; </script> - Testee.init
Testee.init() // Called before testee-client.js is loaded or if Testee is not on window
<!-- After asynchronous test files are loaded and Testee is configured: --> <script type="text/javascript"> if (window.Testee) { window.Testee.init(); } </script> - Testee.start
const { start } = require('testee-client'); start(...)Testee.start({ id: 'some-unique-run-id', environment: navigator.userAgent, runner: 'Mocha', framework: 'mocha' });
Quickstart
<!-- index.html -->
<!DOCTYPE html>
<html>
<head>
<title>Testee Client Quickstart</title>
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/mocha@10.0.0/mocha.min.css">
<script src="//cdn.jsdelivr.net/npm/mocha@10.0.0/mocha.min.js"></script>
<script type="text/javascript">
// Configure Testee client options before loading the script
window.Testee = {
baseURL: 'http://localhost:3030/testee-runner', // Replace with your Testee server URL
provider: { type: 'socket.io' } // Explicitly set for clarity, socket.io is often default
};
mocha.setup('bdd');
</script>
<!-- Load testee-client AFTER configuration -->
<script type="text/javascript" src="node_modules/testee-client/dist/testee-client.js"></script>
</head>
<body>
<div id="mocha"></div>
<script>
// Simulate asynchronous test loading and then run tests
// In a real application, 'tests.js' would contain your actual Mocha tests.
// Here, we're embedding a simple test.
Promise.resolve().then(() => {
describe('My application', () => {
it('should perform addition correctly', () => {
// Example of manual Testee API calls (normally handled by adapters)
if (typeof Testee !== 'undefined' && Testee.start) {
const runId = 'qs-run-id';
const suiteId = 'qs-suite-id';
const testId = 'qs-test-id';
Testee.start({ id: runId, environment: navigator.userAgent, runner: 'Mocha', framework: 'mocha' });
Testee.suite({ id: suiteId, title: 'Quickstart Arithmetic Suite', root: true, parent: runId });
Testee.test({ id: testId, title: '1 + 1 equals 2', parent: suiteId });
// Actual test assertion
if (1 + 1 === 2) {
Testee.pass({ id: testId, duration: 2 });
} else {
Testee.fail({ id: testId, err: { message: 'Unexpected result' } });
}
Testee.testEnd({ id: testId });
}
// Using a common assertion library (e.g., Chai) for actual test logic
// For this example, we'll just check directly.
if ((1 + 1) !== 2) {
throw new Error('1 + 1 should equal 2');
}
});
});
// After all test files are 'loaded', initialize Testee and run the framework
if (window.Testee) {
window.Testee.init();
}
mocha.run();
});
</script>
</body>
</html>