Comparing Test Runners
Test Runner | Isolation | CJS | ESM | node_modules | Bun | Deno |
---|---|---|---|---|---|---|
π· Poku (2.0.0) | β | β | β | β | β | |
Jest (29.7.0) | β | β | experimental | β | β | |
Mocha (10.4.0) | β | β | β | β | β | |
Vitest (1.6.0) | β | deprecated | β | β | β |
Quick Comparisonsβ
Performanceβ
Poku is continuously tested to ensure the following expectations for basic usage:
- ~4x faster than Jest (v29.7.0)
- ~4x faster than Vitest (v2.1.3)
- ~2x faster than Mocha (v10.7.3) β even with test file isolation
- You can see how the tests are run and compared in the benchmark directory.
- Comparing Poku and native test runners (discussion).
Installation Sizeβ
TypeScript Comparisonβ
Comparison using TypeScript (no compile) and ESM to show a simple error test:
- Let's starting from installation π¬
- Poku
- Jest
- Mocha + Chai
- Vitest
- AVA
Pokuβ
Installationβ
npm i -D poku tsx
Creating the test fileβ
test/index.test.ts
import { assert } from 'poku';
assert.deepStrictEqual('1', 1, 'Number should not be a text');
Running testsβ
npx poku
That's it π
tip
For simple tests, Poku doesn't need to use test
, describe
or it
, since the message is already in the assert
.
- Poku's
assert
is just an abstraction from originalassert
from Node.js. - It means: No new learning is needed π
Adopt a Poku for yourself π©΅
Jestβ
Installationβ
npm i -D jest @types/jest ts-jest
Configuring TypeScriptβ
Add in your tsconfig.json
{
"compilerOptions": {
"esModuleInterop": true
}
}
Configuring Jestβ
jest.config.js
export default {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['**/test/**/*.test.ts'],
};
Creating the test fileβ
test/index.test.ts
describe('Type comparison', () => {
test('Number should not be a text', () => {
expect('1').toStrictEqual(1);
});
});
Running testsβ
npx jest
Mocha + Chaiβ
Installationβ
npm i -D mocha @types/mocha chai @types/chai ts-node
Configuring ts-nodeβ
ts-loader.js
import { register } from 'node:module';
import { pathToFileURL } from 'node:url';
register('ts-node/esm', pathToFileURL('./'));
Configuring Mochaβ
.mocharc.json
{
"spec": "./test/**/*.test.ts",
"require": "ts-loader.js"
}
Creating the test fileβ
test/index.test.ts
import { expect } from 'chai';
describe('Type comparison', () => {
it('Number should not be a text', () => {
expect('1').to.deep.equal(1);
});
});
Running testsβ
npx mocha
Vitestβ
Installationβ
npm i -D vitest ts-node
Configuring Vitestβ
vitest.config.ts
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
include: ['test/**/*.test.ts'],
globals: true,
environment: 'node',
},
});
Creating the test fileβ
test/index.test.ts
import { describe, it, expect } from 'vitest';
describe('Type comparison', () => {
it('Number should not be a text', () => {
expect('1').toStrictEqual(1);
});
});
Running testsβ
npx vitest run
AVAβ
Installationβ
npm i -D ava tsimp
Configuring Gitβ
Include in the .gitignore:
/.tsimp
Configuring AVAβ
Include in the package.json:
{
"ava": {
"files": ["test/**/*.test.ts"],
"extensions": {
"ts": "module"
},
"nodeArguments": ["--import=tsimp"]
}
}
Creating the test fileβ
test/index.test.ts
import test from 'ava';
test('Number should not be a text', (t) => {
t.deepEqual('1', 1);
});
Running testsβ
npx ava