Skip to main content

A Complex Case

Imagine these steps to perform a test:

  1. Perform Unit Tests suite in parallel
  2. Clear and Populate the Database
  3. Check for Expected Successes Integration suite sequentially
  4. Don't Clear or Populate the Database again
  5. Check for Expected Failures Integration suite sequentially

Requirements:

Each step requires success to be processed.

Directory Structure:

β”œβ”€β”€ .
β”œβ”€β”€ test
β”‚ β”œβ”€β”€ unit
β”‚ β”œβ”€β”€ integration
β”‚ β”‚ β”œβ”€β”€ successes
β”‚ β”‚ β”‚ └── **/.spec.js
β”‚ β”‚ └── failures
β”‚ β”‚ └── **/.spec.js
β”‚ β”œβ”€ run.test.js # The runner
β”‚ β”œβ”€ tools.test.js

Do we really need to complicate things even more by creating advanced tests runs to run our already complex tests? πŸ˜…

Poku's Solution βœ¨β€‹

import { poku, assert } from 'poku';
import { recreateDatabase } from './tools.test.js';

const unitCode = await poku('test/unit', {
noExit: true,
});

assert.strictEqual(0, unitCode, 'Running Unit Tests');

await recreateDatabase();

const successesCode = await poku('test/integration/successes', {
noExit: true,
sequential: true,
});

assert.strictEqual(0, successesCode, 'Running Successes Integration Tests');

const failuresCode = await poku('test/integration/failures', {
noExit: true,
sequential: true,
});

assert.strictEqual(0, failuresCode, 'Running Failures Integration Tests');

Why comment the code if we can do it better? πŸ§™πŸ»

Finally

npx poku test/run.test.js

Or npx poku test/run.test.ts for TypeScript.