Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): show external errors without requiring debugging #335

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/helpers/hr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { EOL } from 'node:os';
import process from 'node:process';

export const hr = () => {
const line = '⎯'.repeat(process.stdout.columns - 10);
const line = '⎯'.repeat(process.stdout.columns - 10 || 40);

console.log(`${EOL}\x1b[2m\x1b[90m${line}\x1b[0m${EOL}`);
};
Expand Down
28 changes: 4 additions & 24 deletions src/helpers/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,17 @@ export const isDebug = (configs?: Configs): boolean => Boolean(configs?.debug);

export const printOutput = (options: {
output: string;
runtime: string;
runtimeArguments: string[];
fileRelative: string;
result: boolean;
configs?: Configs;
}) => {
// const { output, runtime, runtimeArguments, fileRelative, configs } = options;
const { output, configs } = options;
const { output, result, configs } = options;

const showSuccess = isDebug(configs);
const debug = isDebug(configs);
const pad = configs?.parallel ? ' ' : ' ';
const splittedOutput = output.split(/\n/);

const outputs = (
showSuccess
debug || !result
? splittedOutput
: splittedOutput.filter((current) => {
if (current.includes('Exited with code')) return false;
Expand All @@ -33,23 +30,6 @@ export const printOutput = (options: {
})
).filter((line) => line?.trim().length > 0);

// TODO: Create "strict" option
// if (!showSuccess && /error:/i.test(output) && !/error:/i.test(outputs.join()))
// Object.assign(outputs, [
// ...outputs,
// format.bold(
// format.fail(`✘ External Error ${format.dim(`› ${fileRelative}`)}`)
// ),
// format.dim(' For detailed diagnostics:'),
// `${format.dim(` CLI ›`)} rerun with the ${format.bold('--debug')} flag enabled.`,
// `${format.dim(
// ` API ›`
// )} set the config option ${format.bold('debug')} to true.`,
// `${format.dim(' RUN ›')} ${format.bold(
// `${runtime === 'tsx' ? 'npx tsx' : runtime} ${runtimeArguments.slice(0, -1).join(' ')} ${fileRelative}`
// )}`,
// ]);

if (outputs.length === 0) return;

const mappedOutputs = outputs.map((current) => `${pad}${current}`);
Expand Down
23 changes: 14 additions & 9 deletions src/helpers/parse-assertion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,28 +98,33 @@ export const parseAssertion = async (

console.log(
isPoku
? `${finalMessage} ${format.dim(format.fail(`› ${FILE}`))}`
: finalMessage
? `${preIdentation}${finalMessage} ${format.dim(format.fail(`› ${FILE}`))}`
: `${preIdentation}${finalMessage}`
);

file && console.log(`${format.dim(' File')} ${file}`);
console.log(`${format.dim(' Code')} ${code}`);
console.log(`${format.dim(' Operator')} ${operator}${EOL}`);
file &&
console.log(`${format.dim(`${preIdentation} File`)} ${file}`);
console.log(`${format.dim(`${preIdentation} Code`)} ${code}`);
console.log(
`${format.dim(`${preIdentation} Operator`)} ${operator}${EOL}`
);

if (!options?.hideDiff) {
const splitActual = parseResultType(actual).split('\n');
const splitExpected = parseResultType(expected).split('\n');

console.log(format.dim(` ${options?.actual || 'Actual'}:`));
console.log(
format.dim(`${preIdentation} ${options?.actual || 'Actual'}:`)
);
splitActual.forEach((line) =>
console.log(` ${format.bold(format.fail(line))}`)
console.log(`${preIdentation} ${format.bold(format.fail(line))}`)
);

console.log(
`${EOL} ${format.dim(`${options?.expected || 'Expected'}:`)}`
`${EOL}${preIdentation} ${format.dim(`${options?.expected || 'Expected'}:`)}`
);
splitExpected.forEach((line) =>
console.log(` ${format.bold(format.success(line))}`)
console.log(`${preIdentation} ${format.bold(format.success(line))}`)
);
}

Expand Down
8 changes: 3 additions & 5 deletions src/services/run-test-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,17 @@ export const runTestFile = (
child.stderr.on('data', stdOut);

child.on('close', async (code) => {
const result = code === 0;

if (showLogs)
printOutput({
output,
runtime,
runtimeArguments,
fileRelative,
result,
configs,
});

if (!(await afterEach(fileRelative, configs))) return false;

const result = code === 0;

if (result) fileResults.success.push(fileRelative);
else fileResults.fail.push(fileRelative);

Expand Down
4 changes: 2 additions & 2 deletions test/e2e/background-process.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { getRuntime } from '../../src/helpers/get-runtime.js';
const runtime = getRuntime();

await test(async () => {
describe('Start Service (Single Port)', { background: false, icon: '🔀' });
describe('Start Service (Single Port)', { icon: '🔀' });

const server = await startService(`server-a.${ext}`, {
startAfter: 'ready',
Expand All @@ -34,7 +34,7 @@ import { getRuntime } from '../../src/helpers/get-runtime.js';
});

await test(async () => {
describe('Start Script (Single Port)', { background: false, icon: '🔀' });
describe('Start Script (Single Port)', { icon: '🔀' });

const server = await startScript(`start:${ext}`, {
startAfter: 'ready',
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const runtime = getRuntime();
if (runtime === 'deno' && !isProduction) process.exit(0);

test(async () => {
describe('Poku Test Runner: CLI', { background: false, icon: '🐷' });
describe('Poku Test Runner: CLI', { icon: '🐷' });

const output = await executeCLI([
ext === 'ts' || isProduction
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/exit-code.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { poku, assert, describe, test } from '../../src/index.js';

describe('Poku Runner Suite', { background: false, icon: '🐷' });
describe('Poku Runner Suite', { icon: '🐷' });

test(async () => {
const code = await poku(['./fixtures/success', 'fixtures/fail'], {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/assert/assert-no-message.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { nodeVersion } from '../../../src/helpers/get-runtime.js';
import { assert, describe, test } from '../../../src/index.js';

describe('Assert Suite (No Message)', { background: false, icon: '🔬' });
describe('Assert Suite (No Message)', { icon: '🔬' });

test(() => {
assert(true);
Expand Down
2 changes: 1 addition & 1 deletion test/integration/assert/assert-promise.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { nodeVersion } from '../../../src/helpers/get-runtime.js';
import { assertPromise as assert, describe, test } from '../../../src/index.js';

describe('Assert (Promise) Suite', { background: false, icon: '🔬' });
describe('Assert (Promise) Suite', { icon: '🔬' });

test(() => {
assert(true, 'ok (default) with true');
Expand Down
2 changes: 1 addition & 1 deletion test/integration/assert/assert.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { nodeVersion } from '../../../src/helpers/get-runtime.js';
import { assert, describe, test } from '../../../src/index.js';

describe('Assert Suite', { background: false, icon: '🔬' });
describe('Assert Suite', { icon: '🔬' });

test(() => {
assert(true, 'ok (default) with true');
Expand Down
2 changes: 1 addition & 1 deletion test/integration/import.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as index from '../../src/index.js';

index.describe('Import Suite', { background: false, icon: '🔬' });
index.describe('Import Suite', { icon: '🔬' });

index.assert.ok(index.poku, 'Importing poku method');
index.assert.ok(index.assert, 'Importing assert method');
Expand Down
3 changes: 2 additions & 1 deletion test/unit/assert.result-type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { test, assert, describe } from '../../src/index.js';
import { parseResultType } from '../../src/helpers/parse-assertion.js';
import { nodeVersion } from '../../src/helpers/get-runtime.js';

describe('Assert: Parse Result Type', { background: false, icon: '🔬' });
describe('Assert: Parse Result Type', { icon: '🔬' });

test(async () => {
assert.deepStrictEqual(
parseResultType(),
Expand Down
2 changes: 1 addition & 1 deletion test/unit/deno/allow.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assert, describe, test } from '../../../src/index.js';
import { runner } from '../../../src/helpers/runner.js';

describe('Deno Permissions (Allow)', { background: false, icon: '🔬' });
describe('Deno Permissions (Allow)', { icon: '🔬' });

test(() => {
assert.deepStrictEqual(
Expand Down
2 changes: 1 addition & 1 deletion test/unit/deno/cjs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const runtime = getRuntime();

if (runtime !== 'deno') process.exit(0);

describe('Deno Compatibility', { background: false, icon: '🦕' });
describe('Deno Compatibility', { icon: '🦕' });

const FILE = './fixtures/deno/require.cjs';
const polyfillPath = './lib/polyfills/deno.mjs';
Expand Down
2 changes: 1 addition & 1 deletion test/unit/deno/deny.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assert, describe, test } from '../../../src/index.js';
import { runner } from '../../../src/helpers/runner.js';

describe('Deno Permissions (Deny)', { background: false, icon: '🔬' });
describe('Deno Permissions (Deny)', { icon: '🔬' });

test(() => {
assert.deepStrictEqual(
Expand Down
2 changes: 1 addition & 1 deletion test/unit/run-test-file.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getRuntime } from '../../src/helpers/get-runtime.js';
const isProduction = process.env.NODE_ENV === 'production';
const ext = getRuntime() === 'deno' ? 'ts' : isProduction ? 'js' : 'ts';

describe('Service: runTestFile', { background: false, icon: '🔬' });
describe('Service: runTestFile', { icon: '🔬' });

test(async () => {
const code = await runTestFile(`./fixtures/fail/exit.test.${ext}`, {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/run-tests.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assert, describe, test } from '../../src/index.js';
import { runTests } from '../../src/services/run-tests.js';

describe('Service: runTests', { background: false, icon: '🔬' });
describe('Service: runTests', { icon: '🔬' });

test(async () => {
const code = await runTests('./fixtures/fail', {
Expand Down
Loading