Skip to content

Commit

Permalink
Merge branch 'main' into release-please--branches--main--components--…
Browse files Browse the repository at this point in the history
…poku
  • Loading branch information
wellwelwel committed Sep 17, 2024
2 parents c8f3f7b + eed39f5 commit fa4a0e7
Show file tree
Hide file tree
Showing 8 changed files with 364 additions and 97 deletions.
2 changes: 0 additions & 2 deletions src/bin/enforce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ export const checkFlags = () => {
'--denoAllow',
'--denoCjs',
'--denoDeny',
'--describeOnly',
'--enforce',
'--envFile',
'--exclude',
'--failFast',
'--filter',
'--itOnly',
'--killPid',
'--killPort',
'--killRange',
Expand Down
5 changes: 1 addition & 4 deletions src/bin/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,21 @@ const summary: [string, string][] = [
['--denoAllow', 'Allow permissions for Deno.'],
['--denoCjs', 'Support CommonJS in Deno.'],
['--denoDeny', 'Deny permissions for Deno.'],
['--describeOnly', 'Only `describe` tests using `.only` will be run.'],
['--enforce, -x', 'Validate options before running tests.'],
['--envFile', 'Read and set an environment file.'],
['--exclude', 'Exclude by path using Regex to match files.'],
['--failFast', 'Stop tests at the first failure.'],
['--filter', 'Filter by path using Regex to match files.'],
['--help, -h', "Show Poku's CLI basic usage."],
['--itOnly', 'Only `it` and `test` tests using `.only` will be run.'],
['--killPid', 'Terminate the specified processes.'],
['--killPort', 'Terminate the specified ports.'],
['--killRange', 'Terminate the specified port ranges.'],
['--listFiles', 'Display all the files returned in the terminal.'],
['--node', 'Enforce tests to run through Node.js.'],
['--only', 'Only tests using `.only` will be run.'],
['--only', 'Enable selective execution of tests.'],
['--parallel, -p', 'Run tests files in parallel.'],
['--platform', 'Enforce tests to run through a platform.'],
['--quiet, -q', 'Run tests with no logs.'],
['--testOnly', 'Only `it` and `test` tests using `.only` will be run.'],
['--version, -v', "Show Poku's installed version."],
['--watch, -w', 'Watch for test events.'],
['--watchInterval', 'Set an interval for watch events.'],
Expand Down
4 changes: 2 additions & 2 deletions src/modules/helpers/modifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export async function onlyDescribe(
if (!(hasOnly || hasDescribeOnly)) {
Write.log(
format(
"Can't run `describe.only` tests without `--only` or `--describeOnly` flags"
"Can't run `describe.only` tests without `--only` or `--only=describe` flags"
).fail()
);
exit(1);
Expand All @@ -78,7 +78,7 @@ export async function onlyIt(
if (!(hasOnly || hasItOnly)) {
Write.log(
format(
"Can't run `it.only` and `test.only` tests without `--only`, `--itOnly` or `--testOnly` flags"
"Can't run `it.only` and `test.only` tests without `--only`, `--only=it` or `--only=test` flags"
).fail()
);
exit(1);
Expand Down
8 changes: 5 additions & 3 deletions src/parsers/get-arg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ export const argToArray = (
.filter((a) => a);
};

export const hasOnly = hasArg('only');
const only = getArg('only');

export const hasItOnly = hasArg('itonly') || hasArg('testonly');
export const hasOnly = hasArg('only') && !only;

export const hasDescribeOnly = hasArg('describeonly');
export const hasDescribeOnly = only === 'describe';

export const hasItOnly = only && ['it', 'test'].includes(only);
6 changes: 3 additions & 3 deletions src/services/run-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import { hasOnly, hasDescribeOnly, hasItOnly } from '../parsers/get-arg.js';

const cwd = process.cwd();

if (hasOnly) deepOptions.push('--only');
if (hasDescribeOnly) deepOptions.push('--describeOnly');
if (hasItOnly) deepOptions.push('--itOnly');
if (hasDescribeOnly) deepOptions.push('--only=describe');
else if (hasItOnly) deepOptions.push('--only=it');
else if (hasOnly) deepOptions.push('--only');

export const runTests = async (
dir: string,
Expand Down
66 changes: 66 additions & 0 deletions test/__fixtures__/e2e/only/examples/only-it.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { test } from '../../../../../src/modules/helpers/test.js';
import { describe } from '../../../../../src/modules/helpers/describe.js';
import { it } from '../../../../../src/modules/helpers/it/core.js';
import {
beforeEach,
afterEach,
} from '../../../../../src/modules/helpers/each.js';
import { assert } from '../../../../../src/modules/essentials/assert.js';

beforeEach(() => {
// It will run normally before all `it.only` and `test.only`.
});

afterEach(() => {
// It will run normally after all `it.only` and `test.only`.
});

let counter = 0;

// ⬇️ `describe` scopes ⬇️

describe('1', () => {
counter++; // ✅ `describe` scope will be executed as it's in "native" JavaScript flow

it.only('2', () => {
counter++; // ✅ `it.only` will be executed
});

it('3', () => {
counter++; // ⏭️ `it` will be skipped
});

test.only('4', () => {
counter++; // ✅ `test.only` will be executed
});

test('5', () => {
counter++; // ⏭️ `test` will be skipped
});
});

// ⬇️ Top-level or non-`describe` scopes ⬇️

counter++; // ✅ Will be executed as it's in "native" JavaScript flow

test('6', () => {
counter++; // ⏭️ `test` will be skipped
});

test.only('7', () => {
counter++; // ✅ `test.only` will be executed
});

it('8', () => {
counter++; // ⏭️ `it` will be skipped
});

it.only('9', () => {
counter++; // ✅ `it.only` will be executed
});

// describe.only('10', () => {
// counter++; // ❌ It would force a failure since `describe.only` is not enabled in `--only=it`
// });

assert.strictEqual(counter, 6);
25 changes: 19 additions & 6 deletions test/e2e/only.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ describe('Only', async () => {
assert.strictEqual(results.exitCode, 0, 'Passed');
});

await it('--itOnly', async () => {
const results = await inspectPoku('--itOnly --debug', {
await it('--only=it', async () => {
const results = await inspectPoku('--only=it --debug', {
cwd: 'test/__fixtures__/e2e/only/--it-only',
});

Expand All @@ -33,8 +33,8 @@ describe('Only', async () => {
assert.strictEqual(results.exitCode, 0, 'Passed');
});

await it('--testOnly', async () => {
const results = await inspectPoku('--testOnly --debug', {
await it('--only=test', async () => {
const results = await inspectPoku('--only=test --debug', {
cwd: 'test/__fixtures__/e2e/only/--it-only',
});

Expand All @@ -59,8 +59,8 @@ describe('Only', async () => {
assert.strictEqual(results.exitCode, 1, 'Failed');
});

await it('--describeOnly', async () => {
const results = await inspectPoku('--describeOnly --debug', {
await it('--only=describe', async () => {
const results = await inspectPoku('--only=describe --debug', {
cwd: 'test/__fixtures__/e2e/only/--describe-only',
});

Expand Down Expand Up @@ -123,4 +123,17 @@ describe('Only', async () => {

assert.strictEqual(results.exitCode, 1, 'Failed');
});

await it('Ensure complex examples works', async () => {
const results = await inspectPoku('--only=it', {
cwd: 'test/__fixtures__/e2e/only/examples',
});

if (results.exitCode !== 0) {
console.log(results.stdout);
console.log(results.stderr);
}

assert.strictEqual(results.exitCode, 0, 'Passed');
});
});
Loading

0 comments on commit fa4a0e7

Please sign in to comment.