Skip to content

Commit

Permalink
feat(skip): allow to skip tests (#523)
Browse files Browse the repository at this point in the history
  • Loading branch information
wellwelwel committed Jul 8, 2024
1 parent 99ed430 commit fccfb0d
Show file tree
Hide file tree
Showing 32 changed files with 127 additions and 43 deletions.
1 change: 1 addition & 0 deletions .nycrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"src/modules/helpers/list-files-sync.ts",
"src/modules/helpers/kill.ts",
"src/modules/helpers/log.ts",
"src/modules/helpers/skip.ts",
"src/services/pid.ts",
"src/services/container.ts",
"src/parsers/get-runner.ts",
Expand Down
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@
},
"[yaml]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[mdx]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
6 changes: 5 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,16 @@ npm run test:deno:parallel # Test with the locally installed Deno version
### Coverage
Methods that vary according to **Node.js** version, platform or OS aren't tested against the coverage rate.
The coverage target is **95%**.
```sh
npm run test:c8:sequential
```
> [!tip]
>
> Don't be intimidated by high coverage, methods that vary according to platform, platform versions, _OS_ and processes _(`process.exit`, `process.once`, etc.)_ aren't tested against the coverage rate 🙋🏻‍♂️
### Compatibility Per Platform (Docker)

> ⚠️ Testing using **Docker** can require a considerable local storage.
Expand Down
3 changes: 2 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"all": true,
"useImportRestrictions": "off",
"noConsole": "off",
"noMisplacedAssertion": "off"
"noMisplacedAssertion": "off",
"useImportExtensions": "error"
},
"performance": {
"all": true
Expand Down
2 changes: 0 additions & 2 deletions fixtures/before-after-each/integration.test.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable @typescript-eslint/no-var-requires */

const fs = require('node:fs');
const path = require('node:path');

Expand Down
2 changes: 0 additions & 2 deletions fixtures/deno/require.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const asModule = require('./module.cjs');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { message: asExports } = require('./exports.cjs');

console.log(asModule);
Expand Down
1 change: 0 additions & 1 deletion fixtures/docker/src/docker-compose-server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const http = require('node:http');

const server = http.createServer((_, res) => {
Expand Down
1 change: 0 additions & 1 deletion fixtures/docker/src/dockerfile-server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const http = require('node:http');

const server = http.createServer((_, res) => {
Expand Down
1 change: 0 additions & 1 deletion fixtures/sintax/big-int.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: BigInt literals are not available when targeting lower than ES2020
export const bigIntValue = 987456321456987456321n;
1 change: 1 addition & 0 deletions src/configs/poku.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const results = {
success: 0,
fail: 0,
skipped: 0,
};
4 changes: 3 additions & 1 deletion src/modules/essentials/assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const ifError = (
};

/* c8 ignore start */
const fail = (message?: ProcessAssertionOptions['message']): void => {
const fail = (message?: ProcessAssertionOptions['message']): never => {
processAssert(
() => {
nodeAssert.fail(message);
Expand All @@ -122,6 +122,8 @@ const fail = (message?: ProcessAssertionOptions['message']): void => {
hideDiff: true,
}
);

process.exit(1);
};
/* c8 ignore stop */

Expand Down
4 changes: 3 additions & 1 deletion src/modules/helpers/assert-promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const ifError = async (
/* c8 ignore start */
const fail = async (
message?: ProcessAssertionOptions['message']
): Promise<void> => {
): Promise<never> => {
await processAssert(
() => {
nodeAssert.fail(message);
Expand All @@ -130,6 +130,8 @@ const fail = async (
hideDiff: true,
}
);

process.exit(1);
};
/* c8 ignore stop */

Expand Down
2 changes: 1 addition & 1 deletion src/modules/helpers/exit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const exit = (code: Code, quiet?: boolean) => {
);
Write.hr();
Write.log(
`${format(` PASS › ${results.success} `).bg('green')} ${format(` FAIL › ${results.fail} `).bg(results.fail === 0 ? 'grey' : 'red')}`
`${format(` PASS › ${results.success - results.skipped} `).bg('green')} ${format(` FAIL › ${results.fail} `).bg(results.fail === 0 ? 'grey' : 'red')} ${results.skipped > 0 ? format(` SKIPPED › ${results.skipped} `).bg(results.skipped === 0 ? 'grey' : 'blue') : ''}`
);
Write.hr();
}
Expand Down
22 changes: 22 additions & 0 deletions src/modules/helpers/skip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { exit, env } from 'node:process';
import { Write } from '../../services/write.js';
import { format } from '../../services/format.js';

export const skip = (message?: string) => {
const isPoku = typeof env?.FILE === 'string' && env?.FILE.length > 0;
const FILE = env.FILE;

if (message) {
Write.log(
format(
isPoku
? `ℹ ${message} ${format('›').dim()} ${format(`${FILE}`).italic().gray().dim()}`
: `ℹ ${message}`
)
.info()
.bold()
);
}

exit(0);
};
1 change: 0 additions & 1 deletion src/modules/helpers/wait-for.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export const waitForExpectedResult = async (

const startTime = Date.now();

// eslint-disable-next-line no-constant-condition
while (true) {
const result = await callback();

Expand Down
1 change: 1 addition & 0 deletions src/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export { assert } from './essentials/assert.js';
export { test } from './helpers/test.js';
export { describe } from './helpers/describe.js';
export { it } from './helpers/it.js';
export { skip } from './helpers/skip.js';
export { beforeEach, afterEach } from './helpers/each.js';
export { docker } from './helpers/container.js';
export { startScript, startService } from './helpers/create-service.js';
Expand Down
7 changes: 7 additions & 0 deletions src/parsers/output.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/* c8 ignore next */ // Types
import type { Configs } from '../@types/poku.js';
import { results } from '../configs/poku.js';

const regex = {
newLine: /\n/,
ansi: /u001b\[0m|\n/i,
skipped: /^"\\u001b\[94m\\u001b\[1mℹ/i,
} as const;

export const isQuiet = (configs?: Configs): boolean =>
Expand All @@ -19,6 +21,11 @@ export const parserOutput = (options: {
configs?: Configs;
}) => {
const { output, result, configs } = options;
const normalizedOutput = JSON.stringify(output);

if (regex.skipped.test(normalizedOutput)) {
++results.skipped;
}

const debug = isDebug(configs);
const pad = configs?.parallel ? ' ' : ' ';
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { test } from '../../src/modules/helpers/test.js';
import { assert } from '../../src/modules/essentials/assert.js';
import { executeCLI, ext, isProduction } from '../helpers/capture-cli.test.js';
import { getRuntime } from '../../src/parsers/get-runtime.js';
import { skip } from '../../src/modules/helpers/skip.js';

const runtime = getRuntime();

if (runtime === 'deno' && !isProduction) {
process.exit(0);
skip();
}

test('Poku Test Runner: CLI', async () => {
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/runners.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import process from 'node:process';
import { execSync } from 'node:child_process';
import { describe } from '../../src/modules/helpers/describe.js';
import { it } from '../../src/modules/helpers/it.js';
import { assert } from '../../src/modules/essentials/assert.js';
import { isProduction, inspectCLI } from '../helpers/capture-cli.test.js';
import { skip } from '../../src/modules/helpers/skip.js';

if (isProduction) {
process.exit(0);
skip();
}

const hasNode = (() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import process from 'node:process';
import { nodeVersion, getRuntime } from '../../../src/parsers/get-runtime.js';
import { skip } from '../../../src/modules/helpers/skip.js';

if (nodeVersion && nodeVersion < 16) {
process.exit(0);
skip();
}

import fs from 'node:fs';
Expand All @@ -14,7 +14,7 @@ import { assert } from '../../../src/modules/essentials/assert.js';
const runtime = getRuntime();

if (runtime === 'deno') {
process.exit(0);
skip();
}

const jsonFilePath = path.resolve('./test-before-and-after-each.json');
Expand Down
11 changes: 3 additions & 8 deletions test/integration/containers/test-docker-compose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ import { execSync } from 'node:child_process';
import { describe } from '../../../src/modules/helpers/describe.js';
import { it } from '../../../src/modules/helpers/it.js';
import { assert } from '../../../src/modules/essentials/assert.js';
import { Write } from '../../../src/services/write.js';
import { format } from '../../../src/services/format.js';
import { docker } from '../../../src/modules/helpers/container.js';
import { legacyFetch } from '../../helpers/legacy-fetch.test.js';
import { isWindows } from '../../../src/parsers/get-runner.js';
import { waitForPort } from '../../../src/modules/helpers/wait-for.js';
import { skip } from '../../../src/modules/helpers/skip.js';

// External error: no matching manifest for windows/amd64
if (isWindows) {
process.exit(0);
skip('External error: no matching manifest for windows/amd64');
}

const hasDockerCompose = (() => {
Expand All @@ -25,10 +23,7 @@ const hasDockerCompose = (() => {

describe('Docker Compose Service', async () => {
if (!hasDockerCompose) {
Write.log(
format(' ℹ Skipping: Docker Compose not found').success().bold()
);
return;
skip('Docker Compose not found');
}

await it('Using all configs', async () => {
Expand Down
9 changes: 3 additions & 6 deletions test/integration/containers/test-dockerfile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ import { execSync } from 'node:child_process';
import { describe } from '../../../src/modules/helpers/describe.js';
import { it } from '../../../src/modules/helpers/it.js';
import { assert } from '../../../src/modules/essentials/assert.js';
import { Write } from '../../../src/services/write.js';
import { format } from '../../../src/services/format.js';
import { docker } from '../../../src/modules/helpers/container.js';
import { waitForPort } from '../../../src/modules/helpers/wait-for.js';
import { legacyFetch } from '../../helpers/legacy-fetch.test.js';
import { isWindows } from '../../../src/parsers/get-runner.js';
import { skip } from '../../../src/modules/helpers/skip.js';

// External error: no matching manifest for windows/amd64
if (isWindows) {
process.exit(0);
skip('External error: no matching manifest for windows/amd64');
}

const hasDocker = (() => {
Expand All @@ -25,8 +23,7 @@ const hasDocker = (() => {

describe('Docker Service', async () => {
if (!hasDocker) {
Write.log(format(' ℹ Skipping: Docker not found').success().bold());
return;
skip('Docker not found');
}

await it('Using custom configs', async () => {
Expand Down
1 change: 1 addition & 0 deletions test/integration/import.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ index.test('Import Suite', () => {
index.assert.ok(index.afterEach, 'Importing afterEach helper');
index.assert.ok(index.log, 'Importing log helper');
index.assert.ok(index.test, 'Importing test helper');
index.assert.ok(index.skip, 'Importing skip helper');
index.assert.ok(index.sleep, 'Importing sleep helper');
index.assert.ok(
index.waitForExpectedResult,
Expand Down
3 changes: 2 additions & 1 deletion test/unit/deno/cjs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import process from 'node:process';
import { spawn } from 'node:child_process';
import { test } from '../../../src/modules/helpers/test.js';
import { assert } from '../../../src/modules/essentials/assert.js';
import { skip } from '../../../src/modules/helpers/skip.js';
import { getRuntime } from '../../../src/parsers/get-runtime.js';

const runtime = getRuntime();

if (runtime !== 'deno') {
process.exit(0);
skip('Skipping for non-Deno platforms');
}

test('Deno Compatibility', async () => {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/map-tests.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import process from 'node:process';
import { nodeVersion } from '../../src/parsers/get-runtime.js';
import { skip } from '../../src/modules/helpers/skip.js';

if (nodeVersion && nodeVersion < 14) {
process.exit(0);
skip();
}

import { join } from 'node:path';
Expand Down
4 changes: 2 additions & 2 deletions test/unit/watch.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import process from 'node:process';
import fs from 'node:fs';
import path from 'node:path';
import { it } from '../../src/modules/helpers/it.js';
Expand All @@ -8,10 +7,11 @@ import { assert } from '../../src/modules/essentials/assert.js';
import { getRuntime, nodeVersion } from '../../src/parsers/get-runtime.js';
import { watch } from '../../src/services/watch.js';
import { sleep } from '../../src/modules/helpers/wait-for.js';
import { skip } from '../../src/modules/helpers/skip.js';
import type { WatchCallback } from '../../src/@types/watch.js';

if (nodeVersion && nodeVersion < 10) {
process.exit(0);
skip('rmSync is available from Node.js 10 onwards');
}

const runtime = getRuntime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"link": {
"type": "generated-index"
},
"position": 4
"position": 5
}
2 changes: 1 addition & 1 deletion website/docs/documentation/helpers/containers.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 5
sidebar_position: 6
tags: [containers]
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"link": {
"type": "generated-index"
},
"position": 8
"position": 9
}
Loading

0 comments on commit fccfb0d

Please sign in to comment.