Skip to content

Commit

Permalink
chore!: drop platform option (#894)
Browse files Browse the repository at this point in the history
* chore!: drop platform option

* chore: improve environment variables

* chore: adjust Deno polyfill

* chore: remove `--platform`, `--node`, `--bun` and `deno`

* docs: remove `--platform`, `--node`, `--bun` and `deno`

* chore: remove unused deps

* ci: fix compatibility tests
  • Loading branch information
wellwelwel authored Dec 11, 2024
1 parent 19bd1d2 commit 7e07f16
Show file tree
Hide file tree
Showing 47 changed files with 586 additions and 1,135 deletions.
4 changes: 2 additions & 2 deletions benchmark/benchmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ echo '```'
# Not included in results.json
hyperfine -i --warmup 3 \
--command-name 'Node.js' 'node --test "./test/node/**.spec.js"' \
--command-name "🐷 Poku ($SHORT_SHA)" '../lib/bin/index.js --node ./test/poku' |
--command-name "🐷 Poku ($SHORT_SHA)" '../lib/bin/index.js ./test/poku' |
awk '/Summary/ {flag=1} flag'

echo '```\n'
Expand All @@ -31,7 +31,7 @@ echo '```'
# Not included in results.json
hyperfine -i --warmup 3 \
--command-name 'Bun' 'bun test "test/bun/"' \
--command-name "🐷 Poku ($SHORT_SHA)" '../lib/bin/index.js --bun ./test/poku' |
--command-name "🐷 Poku ($SHORT_SHA)" 'bun ../lib/bin/index.js ./test/poku' |
awk '/Summary/ {flag=1} flag'

echo '```\n'
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "🐷 Poku makes testing easy for Node.js, Bun, Deno, and you at the same time.",
"main": "./lib/modules/index.js",
"license": "MIT",
"type": "commonjs",
"bin": {
"poku": "./lib/bin/index.js"
},
Expand Down Expand Up @@ -31,12 +32,12 @@
},
"scripts": {
"test": "tsx src/bin/index.ts test/unit test/integration test/e2e",
"test:bun": "bun src/bin/index.ts --bun test/unit test/integration test/e2e",
"test:deno": "tsx src/bin/index.ts --deno --denoAllow=all test/unit test/integration test/e2e",
"test:bun": "bun src/bin/index.ts test/unit test/integration test/e2e",
"test:deno": "deno run -A src/bin/index.ts --denoAllow=all test/unit test/integration test/e2e",
"pretest:c8": "tsx tools/build/c8-file.ts",
"test:c8": "c8 --experimental-monocart tsx test/c8.test.ts",
"posttest:c8": "rm -rf ./.nycrc.json",
"test:docker:node": "tsx test/ci.test.ts",
"test:docker:node": "bun test/ci.test.ts",
"clear": "rm -rf lib ci coverage .temp test-src test-tests",
"prebuild": "npm run clear",
"build": "tsc && cd test && tsc",
Expand Down
8 changes: 1 addition & 7 deletions src/@types/background-process.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Runner } from './runner.js';
import type { Configs } from './poku.js';

type BackgroundProcessOptions = {
/**
Expand Down Expand Up @@ -40,11 +39,6 @@ export type StartScriptOptions = {
readonly runner?: Runner;
} & BackgroundProcessOptions;

export type StartServiceOptions = {
/**
* By default, Poku will try to identify the actual platform, but you can specify it manually
*/
readonly platform?: Configs['platform'];
} & BackgroundProcessOptions;
export type StartServiceOptions = BackgroundProcessOptions;

export type End = (port?: number | number[]) => Promise<void>;
6 changes: 0 additions & 6 deletions src/@types/poku.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ export type Configs = {
* @default false
*/
sequential?: boolean;
/**
* Determines the platform for test execution.
*
* @default 'node'
*/
platform?: Runtime;
/**
* Stops the tests at the first failure.
*
Expand Down
4 changes: 0 additions & 4 deletions src/bin/enforce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import { format } from '../services/format.js';

export const checkFlags = () => {
const allowedFlags = new Set([
'--bun',
'--concurrency',
'--config',
'--debug',
'--deno',
'--denoAllow',
'--denoCjs',
'--denoDeny',
Expand All @@ -20,9 +18,7 @@ export const checkFlags = () => {
'--killPid',
'--killPort',
'--killRange',
'--node',
'--only',
'--platform',
'--quiet',
'--sequential',
'--watch',
Expand Down
10 changes: 0 additions & 10 deletions src/bin/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ const options = i('[--options]');
const paths = i('[paths]');
const bullet = d('●');
const summary: [string, string][] = [
['--bun', 'Enforce tests to run through Bun.'],
['--concurrency', 'Limit the number of tests running concurrently.'],
['--config, -c', 'Specify a configuration file.'],
['--debug, -d', 'Show detailed logs.'],
['--deno', 'Enforce tests to run through Deno.'],
['--denoAllow', 'Allow permissions for Deno.'],
['--denoCjs', 'Support CommonJS in Deno.'],
['--denoDeny', 'Deny permissions for Deno.'],
Expand All @@ -28,9 +26,7 @@ const summary: [string, string][] = [
['--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', 'Enable selective execution of tests.'],
['--platform', 'Enforce tests to run through a platform.'],
['--quiet, -q', 'Run tests with no logs.'],
['--sequential', 'Run tests files sequentially.'],
['--version, -v', "Show Poku's installed version."],
Expand All @@ -49,12 +45,6 @@ const header = `
poku ${options} ${paths}
poku ${paths} ${options}
${u(b('Ensuring platforms:'))}
poku ${b('--node')} ${options} ${paths}
poku ${b('--bun')} ${options} ${paths}
poku ${b('--deno')} ${options} ${paths}
${u(b('Tips:'))}
${bullet} All CLI options use camel case pattern (e.g.: ${b('--failFast')}).
Expand Down
11 changes: 0 additions & 11 deletions src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type { Configs } from '../@types/poku.js';
import { escapeRegExp } from '../modules/helpers/list-files.js';
import { getArg, getPaths, hasArg, argToArray } from '../parsers/get-arg.js';
import { states } from '../configs/files.js';
import { platformIsValid } from '../parsers/get-runtime.js';
import { format } from '../services/format.js';
import { kill } from '../modules/helpers/kill.js';
import { envFile } from '../modules/helpers/env.js';
Expand Down Expand Up @@ -36,7 +35,6 @@ import { getConfigs } from '../parsers/options.js';
(defaultConfigs?.include
? Array.prototype.concat(defaultConfigs?.include)
: ['.']);
const platform = getArg('platform');
const filter = getArg('filter') ?? defaultConfigs?.filter;
const exclude = getArg('exclude') ?? defaultConfigs?.exclude;
const killPort = getArg('killPort');
Expand Down Expand Up @@ -144,15 +142,6 @@ import { getConfigs } from '../parsers/options.js';
}

const options: Configs = {
/* c8 ignore next 8 */ // Varies Platform
platform: (() => {
if (platformIsValid(platform)) return platform;
if (hasArg('node')) return 'node';
if (hasArg('bun')) return 'bun';
if (hasArg('deno')) return 'deno';
if (platformIsValid(defaultConfigs?.platform))
return defaultConfigs.platform;
})(),
filter:
typeof filter === 'string' ? new RegExp(escapeRegExp(filter)) : filter,
exclude:
Expand Down
9 changes: 0 additions & 9 deletions src/builders/assert.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { ProcessAssertionOptions } from '../@types/assert.js';
import type assert from 'node:assert';
import type { AssertPredicate } from 'node:assert';
import { nodeVersion } from '../parsers/get-runtime.js';
import { processAssert, processAsyncAssert } from '../services/assert.js';

export const createAssert = (nodeAssert: typeof assert) => {
Expand Down Expand Up @@ -244,10 +243,6 @@ export const createAssert = (nodeAssert: typeof assert) => {
regExp: RegExp,
message?: ProcessAssertionOptions['message']
): void => {
/* c8 ignore next 2 */ // Platform version
if (typeof nodeVersion === 'number' && nodeVersion < 12)
throw new Error('match is available from Node.js 12 or higher');

processAssert(() => nodeAssert?.match(value, regExp), {
message,
actual: 'Value',
Expand All @@ -261,10 +256,6 @@ export const createAssert = (nodeAssert: typeof assert) => {
regExp: RegExp,
message?: ProcessAssertionOptions['message']
): void => {
/* c8 ignore next 2 */ // Platform version
if (typeof nodeVersion === 'number' && nodeVersion < 12)
throw new Error('doesNotMatch is available from Node.js 12 or higher');

processAssert(() => nodeAssert.doesNotMatch(value, regExp), {
message,
actual: 'Value',
Expand Down
2 changes: 1 addition & 1 deletion src/modules/helpers/create-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export const startService = async (
file: string,
options?: StartServiceOptions
): Promise<{ end: End }> => {
const runtimeOptions = runner(file, { platform: options?.platform });
const runtimeOptions = runner(file);
const runtime = runtimeOptions.shift()!;
const runtimeArgs = [...runtimeOptions, file];

Expand Down
2 changes: 1 addition & 1 deletion src/modules/helpers/describe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function describeBase(
let options: DescribeOptions | undefined;

const isPoku = typeof env?.FILE === 'string' && env?.FILE.length > 0;
const FILE = env.FILE;
const FILE = env.POKU_FILE;

if (typeof arg1 === 'string') {
title = arg1;
Expand Down
5 changes: 3 additions & 2 deletions src/modules/helpers/it/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ export async function itBase(
let message: string | undefined;
let cb: () => unknown | Promise<unknown>;

const isPoku = typeof env?.FILE === 'string' && env?.FILE.length > 0;
const FILE = env.FILE;
const isPoku =
typeof env?.POKU_FILE === 'string' && env?.POKU_FILE.length > 0;
const FILE = env.POKU_FILE;

if (typeof args[0] === 'string') {
message = args[0];
Expand Down
5 changes: 3 additions & 2 deletions src/modules/helpers/skip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { Write } from '../../services/write.js';
import { format } from '../../services/format.js';

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

if (message)
Write.log(
Expand Down
8 changes: 4 additions & 4 deletions src/parsers/assert.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { fromEntries, entries } from '../polyfills/object.js';

const recurse = (value: unknown): unknown => {
if (
typeof value === 'undefined' ||
Expand All @@ -11,9 +9,11 @@ const recurse = (value: unknown): unknown => {
return String(value);
if (Array.isArray(value)) return value.map(recurse);
if (value instanceof Set) return Array.from(value).map(recurse);
if (value instanceof Map) return recurse(fromEntries(value));
if (value instanceof Map) return recurse(Object.fromEntries(value));
if (value !== null && typeof value === 'object')
return fromEntries(entries(value).map(([key, val]) => [key, recurse(val)]));
return Object.fromEntries(
Object.entries(value).map(([key, val]) => [key, recurse(val)])
);

return value;
};
Expand Down
2 changes: 1 addition & 1 deletion src/parsers/get-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getRuntime } from './get-runtime.js';
export const isWindows = platform === 'win32';

export const runner = (filename: string, configs?: Configs): string[] => {
const runtime = getRuntime(configs);
const runtime = getRuntime();

if (runtime === 'bun') return ['bun'];

Expand Down
19 changes: 4 additions & 15 deletions src/parsers/get-runtime.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
import type { Configs, Runtime } from '../@types/poku.js';
import { version } from 'node:process';
import type { Runtime } from '../@types/poku.js';
import { version, env } from 'node:process';

declare const Deno: unknown;
declare const Bun: unknown;

const regex = /v(\d+)\./;

export const supportedPlatforms: readonly Runtime[] = ['node', 'bun', 'deno'];

export const platformIsValid = (
platform: unknown
): platform is (typeof supportedPlatforms)[number] =>
typeof platform === 'string' &&
supportedPlatforms.indexOf(platform as Runtime) > -1;

export const getRuntime = (
configs?: Configs
): (typeof supportedPlatforms)[number] => {
if (configs?.platform && platformIsValid(configs.platform))
return configs.platform;
export const getRuntime = (): Runtime => {
if (env.POKU_RUNTIME) return env.POKU_RUNTIME as Runtime;
if (typeof Deno !== 'undefined') return 'deno';
if (typeof Bun !== 'undefined') return 'bun';

Expand Down
11 changes: 4 additions & 7 deletions src/polyfills/deno.mts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import process from 'node:process';
import { env, exit, cwd } from 'node:process';
import { createRequire } from 'node:module';
import { resolve, normalize } from 'node:path';

const file = process.env?.FILE;
if (!file) {
process.exit(1);
}
const file = env?.POKU_FILE;
if (!file) exit(1);

const cwd = process.cwd();
const targetPath = resolve(cwd, '');
const targetPath = resolve(cwd(), '');
const filePath = resolve(targetPath, file!);

globalThis.require = createRequire(targetPath);
Expand Down
32 changes: 0 additions & 32 deletions src/polyfills/object.ts

This file was deleted.

5 changes: 3 additions & 2 deletions src/services/assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ const regexFile = /file:(\/\/)?/;

const assertProcessor = () => {
const isPoku =
typeof process.env?.FILE === 'string' && process.env?.FILE.length > 0;
const FILE = process.env.FILE;
typeof process.env?.POKU_FILE === 'string' &&
process.env?.POKU_FILE.length > 0;
const FILE = process.env.POKU_FILE;

let preIdentation = '';

Expand Down
3 changes: 2 additions & 1 deletion src/services/run-test-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export const runTestFile = async (
shell: isWindows,
env: {
...env,
FILE: fileRelative,
POKU_FILE: fileRelative,
POKU_RUNTIME: env.POKU_RUNTIME,
},
});

Expand Down
10 changes: 9 additions & 1 deletion test/__utils__/capture-cli.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import process from 'node:process';
import process, { env } from 'node:process';
import {
type ChildProcessWithoutNullStreams,
spawn,
Expand Down Expand Up @@ -96,6 +96,10 @@ export const inspectPoku = (
return inspectCLI(`${cmd} ${basePath}${binFile} ${command}`, {
shell: isWindows,
...options,
env: {
...(options?.env || env),
POKU_RUNTIME: env.POKU_RUNTIME,
},
});
};

Expand All @@ -121,6 +125,10 @@ export const watchCLI = (
const childProcess = spawn(cmd, args, {
shell: isWindows,
...options,
env: {
...(options?.env || env),
POKU_RUNTIME: env.POKU_RUNTIME,
},
});

childProcess.stdout.setEncoding('utf8');
Expand Down
Loading

0 comments on commit 7e07f16

Please sign in to comment.