Codi Test Framework
The Codi Test Framework is a minimalist JavaScript testing solution designed for simplicity and ease of use, providing core functionalities for writing unit and integration tests. Currently stable at version 1.0.39, it maintains an active release cadence, pushing minor updates and bug fixes as needed, with major versions reserved for significant API overhauls or new paradigm introductions. Its key differentiators include a low-overhead setup, a focus on direct, readable test syntax, and minimal configuration, making it suitable for projects that prioritize explicit test code over complex tooling or extensive plugin ecosystems often found in larger frameworks. It's ideal for quick verification tasks and projects where testing complexity needs to be kept to a minimum, aiming to provide a clear, concise developer experience without sacrificing essential testing features.
Common errors
-
ReferenceError: test is not defined
cause Attempting to use `test` (or `describe`, `expect`) without importing it, or in a CommonJS module that doesn't support ESM imports.fixEnsure your test file is an ES Module (`.mjs` or `type: "module"` in `package.json`) and you've added `import { test } from 'codi-test-framework';`. -
AssertionError: Expected 5 but got 3
cause A test assertion failed because the actual value did not match the expected value.fixReview the logic of your test case and the expected outcome. Ensure the code under test behaves as intended and that your assertion `expect(actual).toBe(expected)` has the correct `expected` value. -
TypeError: expect(...).toEquals is not a function
cause Attempting to use a deprecated or incorrect assertion method. The `toEquals` method was removed in version 1.0.0.fixUpdate assertion method to `expect(...).toEqual(...)` for deep object comparison or `expect(...).toBe(...)` for primitive value comparison.
Warnings
- breaking The `expect` API underwent a significant breaking change in version 1.0.0. Methods like `equals` were replaced with more descriptive `toBe` and `toEqual` to align with common testing patterns.
- breaking Asynchronous tests in versions prior to 0.8.0 relied on a `done` callback. This callback mechanism was removed in favor of native `async/await` support for clearer asynchronous test handling.
- gotcha When running tests in non-isolated environments (e.g., directly in a global script without a proper test runner), the `test`, `expect`, and `describe` functions might inadvertently pollute the global scope, leading to unexpected conflicts.
- deprecated The `beforeEach` and `afterEach` hooks for setting up and tearing down test environments were deprecated in version 1.0.20 due to inconsistent behavior with asynchronous operations.
Install
-
npm install codi-test-framework -
yarn add codi-test-framework -
pnpm add codi-test-framework
Imports
- test
const { test } = require('codi-test-framework');import { test } from 'codi-test-framework'; - expect
import expect from 'codi-test-framework';
import { expect } from 'codi-test-framework'; - describe
import * as Codi from 'codi-test-framework'; Codi.describe(() => {});import { describe } from 'codi-test-framework';
Quickstart
import { test, expect, describe } from 'codi-test-framework';
describe('Math Operations', () => {
test('should add two numbers correctly', () => {
const result = 1 + 2;
expect(result).toBe(3);
});
test('should handle asynchronous operations', async () => {
const fetchData = () => Promise.resolve({ data: 'hello' });
const response = await fetchData();
expect(response.data).toBe('hello');
});
test('should multiply numbers', () => {
expect(2 * 3).toBe(6);
expect(5 * 0).toBe(0);
});
});
// Simulate a test runner executing these tests
console.log('Running tests with Codi Test Framework...');
// In a real scenario, these tests would be discovered and executed by a runner.
// For this quickstart, assume the 'describe' and 'test' calls register tests internally.
console.log('Tests completed. (Output depends on actual runner implementation)');