ElasticDash Test Runner
elasticdash-test is an AI-native test runner specifically designed for testing ElasticDash workflows. Currently in early development at version 0.1.19, it provides capabilities for defining, executing, and potentially generating tests with AI assistance, tailored for the ElasticDash ecosystem. Given its `0.x` version, users should expect frequent updates and potential breaking changes as the API and features evolve rapidly. The package differentiates itself by integrating AI directly into the testing process, aiming to streamline workflow validation within ElasticDash environments, contrasting with general-purpose test runners by focusing on this specific use case and its associated data and API structures.
Common errors
-
Error: Must be run with Node.js version 20.0.0 or higher.
cause Attempting to run the test runner with an incompatible Node.js version.fixUpgrade your Node.js environment to version 20.0.0 or later. Use `nvm install 20 && nvm use 20` or similar. -
TypeError: test is not a function
cause The `test` function (or `describe`, `configure`) was imported incorrectly, often via a default import or a CommonJS `require` call in an ESM context.fixEnsure you are using named ES module imports: `import { test, describe, configure } from 'elasticdash-test';`. -
Error: ElasticDash API Key not configured. Please set 'apiKey' in configure() or ELASTICDASH_API_KEY environment variable.
cause The `configure` function was called without an `apiKey` or the `ELASTICDASH_API_KEY` environment variable is missing/empty.fixProvide a valid API key through `configure({ apiKey: 'your-key' })` or by setting the `ELASTICDASH_API_KEY` environment variable before running tests. -
SyntaxError: Cannot use import statement outside a module
cause An ES module file (e.g., your test file) is being run in a CommonJS context without proper configuration.fixAdd `"type": "module"` to your `package.json` or rename your test files to have a `.mjs` extension. Ensure your test runner command respects ESM.
Warnings
- breaking The package is in early `0.x` development (current version 0.1.19). Frequent breaking changes to the API, configuration, and underlying AI models are highly probable. Users should pin exact versions and review changelogs carefully.
- breaking This package requires Node.js version 20.0.0 or higher. Running with older Node.js versions will result in errors due to unsupported syntax or APIs.
- gotcha Configuration for ElasticDash API keys and endpoints is critical for the AI-native features to function. Improper or missing configuration will lead to authentication errors or non-functional AI capabilities.
- gotcha As an ESM-only package, CommonJS `require()` statements are not supported for importing `elasticdash-test` modules. Attempting to use `require` will result in runtime errors.
Install
-
npm install elasticdash-test -
yarn add elasticdash-test -
pnpm add elasticdash-test
Imports
- test
const { test } = require('elasticdash-test');import { test } from 'elasticdash-test'; - describe
import describe from 'elasticdash-test'; // 'describe' is a named export
import { describe } from 'elasticdash-test'; - configure
const configure = require('elasticdash-test').configure;import { configure } from 'elasticdash-test';
Quickstart
import { test, describe, expect, configure } from 'elasticdash-test';
// Configure the test runner with your ElasticDash API key
// It's recommended to load this from environment variables.
configure({
apiKey: process.env.ELASTICDASH_API_KEY ?? '',
endpoint: process.env.ELASTICDASH_API_ENDPOINT ?? 'https://api.elasticdash.com'
});
describe('User Management Workflow', () => {
test('should create a new user successfully', async () => {
// Simulate interaction with an ElasticDash workflow or API
// In a real scenario, this would involve calling the ElasticDash API client
const newUser = { id: 'user-123', name: 'John Doe', email: 'john.doe@example.com' };
const response = await simulateCreateUser(newUser);
expect(response.status).toBe(200);
expect(response.body.message).toBe('User created');
expect(response.body.user.name).toBe('John Doe');
});
test('should retrieve an existing user', async () => {
const userId = 'user-456';
const user = await simulateGetUser(userId);
expect(user).not.toBeNull();
expect(user.id).toBe(userId);
expect(user.name).toBe('Jane Doe');
});
});
async function simulateCreateUser(user: any) {
// Placeholder for actual ElasticDash API call
return Promise.resolve({
status: 200,
body: { message: 'User created', user }
});
}
async function simulateGetUser(id: string) {
// Placeholder for actual ElasticDash API call
if (id === 'user-456') {
return Promise.resolve({ id: 'user-456', name: 'Jane Doe', email: 'jane.doe@example.com' });
}
return Promise.resolve(null);
}
// To run:
// 1. Save as 'user.test.ts'
// 2. Set ELASTICDASH_API_KEY and ELASTICDASH_API_ENDPOINT environment variables
// 3. Run: npx elasticdash-test user.test.ts