From 7e07f16ec56a968a7996f7216cb40228f3fe3c92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Weslley=20Ara=C3=BAjo?= <46850407+wellwelwel@users.noreply.github.com> Date: Wed, 11 Dec 2024 08:40:22 -0300 Subject: [PATCH] chore!: drop `platform` option (#894) * 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 --- benchmark/benchmark.sh | 4 +- package.json | 7 +- src/@types/background-process.ts | 8 +- src/@types/poku.ts | 6 - src/bin/enforce.ts | 4 - src/bin/help.ts | 10 - src/bin/index.ts | 11 - src/builders/assert.ts | 9 - src/modules/helpers/create-service.ts | 2 +- src/modules/helpers/describe.ts | 2 +- src/modules/helpers/it/core.ts | 5 +- src/modules/helpers/skip.ts | 5 +- src/parsers/assert.ts | 8 +- src/parsers/get-runner.ts | 2 +- src/parsers/get-runtime.ts | 19 +- src/polyfills/deno.mts | 11 +- src/polyfills/object.ts | 32 -- src/services/assert.ts | 5 +- src/services/run-test-file.ts | 3 +- test/__utils__/capture-cli.test.ts | 10 +- test/c8.test.ts | 14 +- test/ci.test.ts | 5 +- test/e2e/basic-logs.test.ts | 5 +- test/e2e/final-results.test.ts | 6 - test/e2e/runners.test.ts | 6 +- test/e2e/watch.test.ts | 9 +- .../assert/assert-no-message.test.ts | 144 ++++---- test/integration/assert/assert.test.ts | 342 +++++++++--------- .../external-file-update.test.ts | 6 +- .../strict/assert-no-message.test.ts | 144 ++++---- test/integration/strict/assert.test.ts | 342 +++++++++--------- test/unit/assert-result-type.test.ts | 17 +- test/unit/deno/allow.test.ts | 16 +- test/unit/deno/cjs.test.ts | 4 +- test/unit/deno/deny.test.ts | 12 +- .../docs/documentation/poku/config-files.mdx | 1 - .../documentation/poku/options/platform.mdx | 86 ----- website/docs/index.mdx | 2 +- website/docs/philosophy.mdx | 4 +- website/docs/tutorials/cross-platform.mdx | 127 +------ website/docusaurus.config.ts | 6 +- .../documentation/poku/options/platform.mdx | 86 ----- .../current/index.mdx | 2 +- .../current/philosophy.mdx | 4 +- .../current/tutorials/cross-platform.mdx | 128 +------ website/package-lock.json | 39 -- website/package.json | 1 - 47 files changed, 586 insertions(+), 1135 deletions(-) delete mode 100644 src/polyfills/object.ts delete mode 100644 website/docs/documentation/poku/options/platform.mdx delete mode 100644 website/i18n/pt-BR/docusaurus-plugin-content-docs/current/documentation/poku/options/platform.mdx diff --git a/benchmark/benchmark.sh b/benchmark/benchmark.sh index 6c1f2bb0..d79ba57e 100644 --- a/benchmark/benchmark.sh +++ b/benchmark/benchmark.sh @@ -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' @@ -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' diff --git a/package.json b/package.json index 9d11ad33..b2b7cc6f 100644 --- a/package.json +++ b/package.json @@ -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" }, @@ -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", diff --git a/src/@types/background-process.ts b/src/@types/background-process.ts index 2d962602..2efd6a2c 100644 --- a/src/@types/background-process.ts +++ b/src/@types/background-process.ts @@ -1,5 +1,4 @@ import type { Runner } from './runner.js'; -import type { Configs } from './poku.js'; type BackgroundProcessOptions = { /** @@ -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; diff --git a/src/@types/poku.ts b/src/@types/poku.ts index 25973f30..0fbe6624 100644 --- a/src/@types/poku.ts +++ b/src/@types/poku.ts @@ -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. * diff --git a/src/bin/enforce.ts b/src/bin/enforce.ts index 191a63dc..eae06e2b 100644 --- a/src/bin/enforce.ts +++ b/src/bin/enforce.ts @@ -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', @@ -20,9 +18,7 @@ export const checkFlags = () => { '--killPid', '--killPort', '--killRange', - '--node', '--only', - '--platform', '--quiet', '--sequential', '--watch', diff --git a/src/bin/help.ts b/src/bin/help.ts index 3e37ea7e..90b92ba0 100644 --- a/src/bin/help.ts +++ b/src/bin/help.ts @@ -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.'], @@ -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."], @@ -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')}). diff --git a/src/bin/index.ts b/src/bin/index.ts index 2a6ecaba..a148aa53 100644 --- a/src/bin/index.ts +++ b/src/bin/index.ts @@ -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'; @@ -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'); @@ -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: diff --git a/src/builders/assert.ts b/src/builders/assert.ts index e9b732a0..28858855 100644 --- a/src/builders/assert.ts +++ b/src/builders/assert.ts @@ -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) => { @@ -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', @@ -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', diff --git a/src/modules/helpers/create-service.ts b/src/modules/helpers/create-service.ts index 28491149..979ba6e3 100644 --- a/src/modules/helpers/create-service.ts +++ b/src/modules/helpers/create-service.ts @@ -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]; diff --git a/src/modules/helpers/describe.ts b/src/modules/helpers/describe.ts index 6c73cee8..0c5b91f0 100644 --- a/src/modules/helpers/describe.ts +++ b/src/modules/helpers/describe.ts @@ -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; diff --git a/src/modules/helpers/it/core.ts b/src/modules/helpers/it/core.ts index 742bb0cc..682973e1 100644 --- a/src/modules/helpers/it/core.ts +++ b/src/modules/helpers/it/core.ts @@ -16,8 +16,9 @@ export async function itBase( let message: string | undefined; let cb: () => unknown | Promise; - 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]; diff --git a/src/modules/helpers/skip.ts b/src/modules/helpers/skip.ts index fcc03e5d..130def10 100644 --- a/src/modules/helpers/skip.ts +++ b/src/modules/helpers/skip.ts @@ -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( diff --git a/src/parsers/assert.ts b/src/parsers/assert.ts index 067cdab6..f4508417 100644 --- a/src/parsers/assert.ts +++ b/src/parsers/assert.ts @@ -1,5 +1,3 @@ -import { fromEntries, entries } from '../polyfills/object.js'; - const recurse = (value: unknown): unknown => { if ( typeof value === 'undefined' || @@ -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; }; diff --git a/src/parsers/get-runner.ts b/src/parsers/get-runner.ts index e709feab..61c7a41a 100644 --- a/src/parsers/get-runner.ts +++ b/src/parsers/get-runner.ts @@ -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']; diff --git a/src/parsers/get-runtime.ts b/src/parsers/get-runtime.ts index 789e1272..d4532f78 100644 --- a/src/parsers/get-runtime.ts +++ b/src/parsers/get-runtime.ts @@ -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'; diff --git a/src/polyfills/deno.mts b/src/polyfills/deno.mts index 3eb350ee..2cf4c264 100644 --- a/src/polyfills/deno.mts +++ b/src/polyfills/deno.mts @@ -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); diff --git a/src/polyfills/object.ts b/src/polyfills/object.ts deleted file mode 100644 index e8eaaaa3..00000000 --- a/src/polyfills/object.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { nodeVersion } from '../parsers/get-runtime.js'; - -const needsPolyfill = nodeVersion && nodeVersion < 12; - -export const entries = needsPolyfill - ? (obj: { [key: string]: any }): [string, unknown][] => { - const ownProps = Object.keys(obj); - let i = ownProps.length; - const resArray = new Array(i); - - while (i--) resArray[i] = [ownProps[i], obj[ownProps[i]]]; - - return resArray; - } - : Object.entries; - -export const fromEntries = needsPolyfill - ? ( - entries: [string, unknown][] | Map - ): Record => { - const mappedEntries = - entries instanceof Map ? Array.from(entries) : entries; - - return mappedEntries.reduce( - (acc, [key, value]) => { - acc[key] = value; - return acc; - }, - {} as Record - ); - } - : Object.fromEntries; diff --git a/src/services/assert.ts b/src/services/assert.ts index 6c442ea8..72afd391 100644 --- a/src/services/assert.ts +++ b/src/services/assert.ts @@ -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 = ''; diff --git a/src/services/run-test-file.ts b/src/services/run-test-file.ts index 40465c63..b6084d75 100644 --- a/src/services/run-test-file.ts +++ b/src/services/run-test-file.ts @@ -47,7 +47,8 @@ export const runTestFile = async ( shell: isWindows, env: { ...env, - FILE: fileRelative, + POKU_FILE: fileRelative, + POKU_RUNTIME: env.POKU_RUNTIME, }, }); diff --git a/test/__utils__/capture-cli.test.ts b/test/__utils__/capture-cli.test.ts index 983357a3..b0fe7dcc 100644 --- a/test/__utils__/capture-cli.test.ts +++ b/test/__utils__/capture-cli.test.ts @@ -1,4 +1,4 @@ -import process from 'node:process'; +import process, { env } from 'node:process'; import { type ChildProcessWithoutNullStreams, spawn, @@ -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, + }, }); }; @@ -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'); diff --git a/test/c8.test.ts b/test/c8.test.ts index 6b2d6095..02f201fd 100644 --- a/test/c8.test.ts +++ b/test/c8.test.ts @@ -14,9 +14,7 @@ test(async () => { await describe('CLI', async () => { await it('Just Touch', async () => { - const results = await inspectPoku( - '--platform=node test/integration/import.test.ts' - ); + const results = await inspectPoku('test/integration/import.test.ts'); console.log(results.stdout); console.log(results.stderr); @@ -25,7 +23,7 @@ test(async () => { }); await it('FILTER Env', async () => { - const results = await inspectPoku('--platform=node test/integration', { + const results = await inspectPoku('test/integration', { env: { ...process.env, FILTER: 'import' }, }); @@ -38,8 +36,8 @@ test(async () => { await it('Options (Just Touch)', async () => { const results = await inspectPoku( isWindows - ? '--concurrency=4 --platform=node --failFast --debug --exclude=".bak" --killPort=4000 --killRange="4000-4001" test/integration/import.test.ts --filter=".test.|.spec."' - : '--concurrency=4 --platform=node --failFast --debug --exclude=.bak --killPort=4000 --killRange=4000-4001 test/integration/import.test.ts --filter=.test.|.spec.' + ? '--concurrency=4 --failFast --debug --exclude=".bak" --killPort=4000 --killRange="4000-4001" test/integration/import.test.ts --filter=".test.|.spec."' + : '--concurrency=4 --failFast --debug --exclude=.bak --killPort=4000 --killRange=4000-4001 test/integration/import.test.ts --filter=.test.|.spec.' ); console.log(results.stdout); @@ -52,7 +50,6 @@ test(async () => { await describe('API', async () => { await it('Single Input', async () => { const exitCode = await poku('test/integration/import.test.ts', { - platform: 'node', noExit: true, }); @@ -61,7 +58,6 @@ test(async () => { await it('Unit (Exclude as Regex)', async () => { const exitCode = await poku('test/unit', { - platform: 'node', exclude: /watch|map-tests/, noExit: true, }); @@ -71,7 +67,6 @@ test(async () => { await it('Unit (Exclude as Array of Regex)', async () => { const exitCode = await poku('test/unit', { - platform: 'node', concurrency: 4, exclude: [/watch/, /map-tests/], noExit: true, @@ -84,7 +79,6 @@ test(async () => { const exitCode = await poku( ['test/unit', 'test/integration', 'test/e2e'], { - platform: 'node', debug: true, filter: /\.(test|spec)\./, failFast: true, diff --git a/test/ci.test.ts b/test/ci.test.ts index 3e2140c1..6e3b0cc1 100644 --- a/test/ci.test.ts +++ b/test/ci.test.ts @@ -11,12 +11,9 @@ test(async () => { const result = await poku(['./test/compatibility'], { debug: true, noExit: true, - platform: 'bun', }); - if (result === 0) { - await compose.down(); - } + if (result === 0) await compose.down(); exit(result); }); diff --git a/test/e2e/basic-logs.test.ts b/test/e2e/basic-logs.test.ts index ecd2978b..ea7101be 100644 --- a/test/e2e/basic-logs.test.ts +++ b/test/e2e/basic-logs.test.ts @@ -1,4 +1,4 @@ -import process from 'node:process'; +import process, { env } from 'node:process'; import { describe } from '../../src/modules/helpers/describe.js'; import { it } from '../../src/modules/helpers/it/core.js'; import { assert } from '../../src/modules/essentials/assert.js'; @@ -25,7 +25,8 @@ describe('Basic logs with Runner', async () => { { env: { ...process.env, - FILE: 'path-file', + POKU_FILE: 'path-file', + POKU_RUNTIME: env.POKU_RUNTIME, }, } ); diff --git a/test/e2e/final-results.test.ts b/test/e2e/final-results.test.ts index f8c92991..d14a0a42 100644 --- a/test/e2e/final-results.test.ts +++ b/test/e2e/final-results.test.ts @@ -2,12 +2,6 @@ import { describe } from '../../src/modules/helpers/describe.js'; import { it } from '../../src/modules/helpers/it/core.js'; import { assert } from '../../src/modules/essentials/assert.js'; import { inspectPoku } from '../__utils__/capture-cli.test.js'; -import { nodeVersion } from '../../src/parsers/get-runtime.js'; -import { skip } from '../../src/modules/helpers/skip.js'; - -if (nodeVersion && nodeVersion < 12) { - skip(); -} describe('Final Results', async () => { await it('Skip', async () => { diff --git a/test/e2e/runners.test.ts b/test/e2e/runners.test.ts index ad1348fc..f385a1bf 100644 --- a/test/e2e/runners.test.ts +++ b/test/e2e/runners.test.ts @@ -40,7 +40,7 @@ describe('Test Runtimes/Platforms + Extensions', async () => { hasNode && (await it('Node.js', async () => { const output = await inspectCLI( - 'npx tsx src/bin/index.ts --platform=node test/__fixtures__/e2e/extensions -d' + 'npx tsx src/bin/index.ts test/__fixtures__/e2e/extensions -d' ); if (output.exitCode !== 0) { @@ -56,7 +56,7 @@ describe('Test Runtimes/Platforms + Extensions', async () => { hasBun && (await it('Bun', async () => { const output = await inspectCLI( - 'bun src/bin/index.ts --platform=bun test/__fixtures__/e2e/extensions -d' + 'bun src/bin/index.ts test/__fixtures__/e2e/extensions -d' ); if (output.exitCode !== 0) { @@ -72,7 +72,7 @@ describe('Test Runtimes/Platforms + Extensions', async () => { hasDeno && (await it('Deno', async () => { const output = await inspectCLI( - 'deno run --unstable-sloppy-imports --allow-read --allow-env --allow-run src/bin/index.ts --platform=deno test/__fixtures__/e2e/extensions -d --exclude=.cts' + 'deno run --unstable-sloppy-imports --allow-read --allow-env --allow-run src/bin/index.ts test/__fixtures__/e2e/extensions -d --exclude=.cts' ); if (output.exitCode !== 0) { diff --git a/test/e2e/watch.test.ts b/test/e2e/watch.test.ts index f7674e32..456c6f73 100644 --- a/test/e2e/watch.test.ts +++ b/test/e2e/watch.test.ts @@ -1,14 +1,9 @@ -import { getRuntime, nodeVersion } from '../../src/parsers/get-runtime.js'; +import { getRuntime } from '../../src/parsers/get-runtime.js'; import { isBuild, watchCLI } from '../__utils__/capture-cli.test.js'; import { isWindows } from '../../src/parsers/get-runner.js'; import { skip } from '../../src/modules/helpers/skip.js'; -if ( - isBuild || - (nodeVersion && nodeVersion < 10) || - getRuntime() !== 'node' || - isWindows -) { +if (isBuild || getRuntime() !== 'node' || isWindows) { skip(); } diff --git a/test/integration/assert/assert-no-message.test.ts b/test/integration/assert/assert-no-message.test.ts index ae5a93a1..3ed0ed37 100644 --- a/test/integration/assert/assert-no-message.test.ts +++ b/test/integration/assert/assert-no-message.test.ts @@ -90,48 +90,46 @@ describe('Assert Suite (No Message)', () => { }); it(() => { - if (!nodeVersion || nodeVersion > 8) { - const obj = { a: 1 }; + const obj = { a: 1 }; - const functionThatThrows = () => { - throw new Error('Specific error'); - }; + const functionThatThrows = () => { + throw new Error('Specific error'); + }; - it(() => { - assert.throws(() => { - throw new Error('error'); - }); - assert.throws(() => { - throw new Error('Test error'); - }); - assert.throws(() => { - throw new Error('Test error'); - }); - assert.throws(functionThatThrows, new Error('Specific error')); - assert.throws(functionThatThrows, /Specific error/); - assert.throws( - functionThatThrows, - (err) => err instanceof Error && err.message === 'Specific error' - ); + it(() => { + assert.throws(() => { + throw new Error('error'); }); - - it(() => { - assert.doesNotThrow(() => { - obj.a = 2; - }); - assert.strictEqual(obj.a, 2); - assert.doesNotThrow(() => { - return 42; - }); - assert.doesNotThrow(() => - callbackFunction((err) => { - assert.ifError(err); - }) - ); - assert.doesNotThrow(() => 42); - assert.doesNotThrow(() => 'no error'); + assert.throws(() => { + throw new Error('Test error'); }); - } + assert.throws(() => { + throw new Error('Test error'); + }); + assert.throws(functionThatThrows, new Error('Specific error')); + assert.throws(functionThatThrows, /Specific error/); + assert.throws( + functionThatThrows, + (err) => err instanceof Error && err.message === 'Specific error' + ); + }); + + it(() => { + assert.doesNotThrow(() => { + obj.a = 2; + }); + assert.strictEqual(obj.a, 2); + assert.doesNotThrow(() => { + return 42; + }); + assert.doesNotThrow(() => + callbackFunction((err) => { + assert.ifError(err); + }) + ); + assert.doesNotThrow(() => 42); + assert.doesNotThrow(() => 'no error'); + }); }); it(() => { @@ -152,41 +150,39 @@ describe('Assert Suite (No Message)', () => { }); it(() => { - if (!nodeVersion || nodeVersion > 10) { - const asyncFunctionThatRejects = async () => - await Promise.reject(new Error('Async error')); - - const asyncFunctionThatResolves = () => - Promise.resolve('Resolved successfully'); - - const asyncFunctionThatFails = () => - new Promise((_, reject) => reject(new Error('Failed'))); - - const asyncFunctionThatCouldReject = () => - new Promise((resolve) => resolve(undefined)); - - it(() => { - assert.rejects( - async () => await asyncFunctionThatFails(), - new Error('Failed') - ); - assert.rejects(asyncFunctionThatRejects, new Error('Async error')); - assert.rejects( - () => Promise.reject('Simple rejection'), - (err) => err === 'Simple rejection' - ); - assert.rejects(asyncFunctionThatRejects, new Error('Async error')); - }); - - it(() => { - assert.doesNotReject(asyncFunctionThatResolves); - assert.doesNotReject(Promise.resolve('Immediate resolve')); - assert.doesNotReject(asyncFunctionThatCouldReject); - assert.doesNotReject(() => - Promise.resolve('Async function with no rejection') - ); - assert.doesNotReject(asyncFunctionThatResolves); - }); - } + const asyncFunctionThatRejects = async () => + await Promise.reject(new Error('Async error')); + + const asyncFunctionThatResolves = () => + Promise.resolve('Resolved successfully'); + + const asyncFunctionThatFails = () => + new Promise((_, reject) => reject(new Error('Failed'))); + + const asyncFunctionThatCouldReject = () => + new Promise((resolve) => resolve(undefined)); + + it(() => { + assert.rejects( + async () => await asyncFunctionThatFails(), + new Error('Failed') + ); + assert.rejects(asyncFunctionThatRejects, new Error('Async error')); + assert.rejects( + () => Promise.reject('Simple rejection'), + (err) => err === 'Simple rejection' + ); + assert.rejects(asyncFunctionThatRejects, new Error('Async error')); + }); + + it(() => { + assert.doesNotReject(asyncFunctionThatResolves); + assert.doesNotReject(Promise.resolve('Immediate resolve')); + assert.doesNotReject(asyncFunctionThatCouldReject); + assert.doesNotReject(() => + Promise.resolve('Async function with no rejection') + ); + assert.doesNotReject(asyncFunctionThatResolves); + }); }); }); diff --git a/test/integration/assert/assert.test.ts b/test/integration/assert/assert.test.ts index 7ce61784..2789acb2 100644 --- a/test/integration/assert/assert.test.ts +++ b/test/integration/assert/assert.test.ts @@ -138,90 +138,88 @@ describe('Assert Suite', async () => { }); it(() => { - if (!nodeVersion || nodeVersion > 8) { - const obj = { a: 1 }; - - const functionThatThrows = () => { - throw new Error('Specific error'); - }; - - it(() => { - assert.throws(() => { - throw new Error('error'); - }, 'throws with throwing function'); - assert.throws(() => { - throw new Error('Test error'); - }, 'Should throw an exception for a function that generates an error'); - assert.throws(() => { - throw new Error('Test error'); - }, 'Should throw an error for a function that actually throws'); - assert.throws( - functionThatThrows, - new Error('Specific error'), - 'Should throw the specific error' - ); - - assert.throws( - functionThatThrows, - /Specific error/, - 'Should throw an error matching the regex' - ); - - assert.throws( - functionThatThrows, - (err) => err instanceof Error && err.message === 'Specific error', - 'Should throw an error where the message equals the specific string' - ); - }); - - it(() => { - assert.doesNotThrow( - () => 1 + 1, - 'doesNotThrow with non-throwing function' - ); - - assert.doesNotThrow(() => { - obj.a = 2; - }, 'Changing property should not throw'); - assert.strictEqual(obj.a, 2, 'Property a should be 2 after mutation'); - - // Test to check functions that do or do not throw errors - assert.doesNotThrow(() => { - return 42; - }, 'Should not throw an exception for a function returning 42'); - - assert.doesNotThrow( - () => - callbackFunction((err) => { - assert.ifError(err); - }), - 'Should not throw an error for a callback function that does not error' - ); - - assert.doesNotThrow( - () => 42, - 'Should not throw an error for a function returning a number' - ); - - assert.doesNotThrow( - () => 'no error', - 'Should not throw an error for a function returning a string' - ); - - assert.doesNotThrow( - () => 'no error', - 'Should not throw an error for an async function that resolves' - ); - - assert.doesNotThrow( - () => { - return 'test'; - }, - /test/, - 'RegExp predicate should not match' - ); - }); - } + const obj = { a: 1 }; + + const functionThatThrows = () => { + throw new Error('Specific error'); + }; + + it(() => { + assert.throws(() => { + throw new Error('error'); + }, 'throws with throwing function'); + assert.throws(() => { + throw new Error('Test error'); + }, 'Should throw an exception for a function that generates an error'); + assert.throws(() => { + throw new Error('Test error'); + }, 'Should throw an error for a function that actually throws'); + assert.throws( + functionThatThrows, + new Error('Specific error'), + 'Should throw the specific error' + ); + + assert.throws( + functionThatThrows, + /Specific error/, + 'Should throw an error matching the regex' + ); + + assert.throws( + functionThatThrows, + (err) => err instanceof Error && err.message === 'Specific error', + 'Should throw an error where the message equals the specific string' + ); + }); + + it(() => { + assert.doesNotThrow( + () => 1 + 1, + 'doesNotThrow with non-throwing function' + ); + + assert.doesNotThrow(() => { + obj.a = 2; + }, 'Changing property should not throw'); + assert.strictEqual(obj.a, 2, 'Property a should be 2 after mutation'); + + // Test to check functions that do or do not throw errors + assert.doesNotThrow(() => { + return 42; + }, 'Should not throw an exception for a function returning 42'); + + assert.doesNotThrow( + () => + callbackFunction((err) => { + assert.ifError(err); + }), + 'Should not throw an error for a callback function that does not error' + ); + + assert.doesNotThrow( + () => 42, + 'Should not throw an error for a function returning a number' + ); + + assert.doesNotThrow( + () => 'no error', + 'Should not throw an error for a function returning a string' + ); + + assert.doesNotThrow( + () => 'no error', + 'Should not throw an error for an async function that resolves' + ); + + assert.doesNotThrow( + () => { + return 'test'; + }, + /test/, + 'RegExp predicate should not match' + ); + }); }); it(() => { @@ -258,94 +256,92 @@ describe('Assert Suite', async () => { }); await it(async () => { - if (!nodeVersion || nodeVersion > 10) { - const asyncFunctionThatRejects = async () => - await Promise.reject(new Error('Async error')); - - const asyncFunctionThatResolves = () => - Promise.resolve('Resolved successfully'); - - const asyncFunctionThatFails = () => - new Promise((_, reject) => reject(new Error('Failed'))); - - const asyncFunctionThatCouldReject = () => - new Promise((resolve) => resolve(undefined)); - - await it(async () => { - await assert.rejects( - async () => await asyncFunctionThatFails(), - new Error('Failed'), - 'Async function should reject with an error' - ); - await assert.rejects( - asyncFunctionThatRejects, - new Error('Async error'), - 'Should reject with an Error object with "Async error" message' - ); - await assert.rejects( - () => Promise.reject('Simple rejection'), - (err) => err === 'Simple rejection', - 'Should handle rejection with a simple string message' - ); - await assert.rejects( - asyncFunctionThatRejects, - new Error('Async error'), - 'Should reject with the specified error message' - ); - await assert.rejects( - asyncFunctionThatRejects, - /Async error/, - 'Should reject with the specified regex message' - ); - await assert.rejects( - asyncFunctionThatRejects, - { message: 'Async error' }, - 'Should reject with the specified object predicate message' - ); - await assert.rejects( - asyncFunctionThatRejects, - (err: Error) => err.message === 'Async error', - 'Should reject with the specified function predicate message' - ); - await assert.rejects( - asyncFunctionThatRejects, - 'Should reject with the specified string message' - ); - await assert.rejects( - asyncFunctionThatRejects, - // @ts-expect-error invalid second param - undefined, - 'Should reject with the specified string message (third arg)' - ); - await assert.rejects(asyncFunctionThatRejects); - }); - - await it(async () => { - await assert.doesNotReject( - asyncFunctionThatResolves, - 'Should not reject for a function that resolves' - ); - await assert.doesNotReject( - asyncFunctionThatResolves, - 'Should not reject for a function that resolves' - ); - await assert.doesNotReject( - Promise.resolve('Immediate resolve'), - 'Should not reject for an immediately resolving promise' - ); - await assert.doesNotReject( - asyncFunctionThatCouldReject, - 'Should not reject for a function that could reject but resolves instead' - ); - await assert.doesNotReject( - () => Promise.resolve('Async function with no rejection'), - 'Should handle async functions that do not reject' - ); - await assert.doesNotReject( - asyncFunctionThatResolves, - /Resolved successfully/ - ); - }); - } + const asyncFunctionThatRejects = async () => + await Promise.reject(new Error('Async error')); + + const asyncFunctionThatResolves = () => + Promise.resolve('Resolved successfully'); + + const asyncFunctionThatFails = () => + new Promise((_, reject) => reject(new Error('Failed'))); + + const asyncFunctionThatCouldReject = () => + new Promise((resolve) => resolve(undefined)); + + await it(async () => { + await assert.rejects( + async () => await asyncFunctionThatFails(), + new Error('Failed'), + 'Async function should reject with an error' + ); + await assert.rejects( + asyncFunctionThatRejects, + new Error('Async error'), + 'Should reject with an Error object with "Async error" message' + ); + await assert.rejects( + () => Promise.reject('Simple rejection'), + (err) => err === 'Simple rejection', + 'Should handle rejection with a simple string message' + ); + await assert.rejects( + asyncFunctionThatRejects, + new Error('Async error'), + 'Should reject with the specified error message' + ); + await assert.rejects( + asyncFunctionThatRejects, + /Async error/, + 'Should reject with the specified regex message' + ); + await assert.rejects( + asyncFunctionThatRejects, + { message: 'Async error' }, + 'Should reject with the specified object predicate message' + ); + await assert.rejects( + asyncFunctionThatRejects, + (err: Error) => err.message === 'Async error', + 'Should reject with the specified function predicate message' + ); + await assert.rejects( + asyncFunctionThatRejects, + 'Should reject with the specified string message' + ); + await assert.rejects( + asyncFunctionThatRejects, + // @ts-expect-error invalid second param + undefined, + 'Should reject with the specified string message (third arg)' + ); + await assert.rejects(asyncFunctionThatRejects); + }); + + await it(async () => { + await assert.doesNotReject( + asyncFunctionThatResolves, + 'Should not reject for a function that resolves' + ); + await assert.doesNotReject( + asyncFunctionThatResolves, + 'Should not reject for a function that resolves' + ); + await assert.doesNotReject( + Promise.resolve('Immediate resolve'), + 'Should not reject for an immediately resolving promise' + ); + await assert.doesNotReject( + asyncFunctionThatCouldReject, + 'Should not reject for a function that could reject but resolves instead' + ); + await assert.doesNotReject( + () => Promise.resolve('Async function with no rejection'), + 'Should handle async functions that do not reject' + ); + await assert.doesNotReject( + asyncFunctionThatResolves, + /Resolved successfully/ + ); + }); }); }); diff --git a/test/integration/before-and-after-each/external-file-update.test.ts b/test/integration/before-and-after-each/external-file-update.test.ts index 9d293e8b..476e4c49 100644 --- a/test/integration/before-and-after-each/external-file-update.test.ts +++ b/test/integration/before-and-after-each/external-file-update.test.ts @@ -4,13 +4,15 @@ import { test } from '../../../src/modules/helpers/test.js'; import { poku } from '../../../src/modules/essentials/poku.js'; import { assert } from '../../../src/modules/essentials/assert.js'; import { getRuntime } from '../../../src/parsers/get-runtime.js'; +import { skip } from '../../../src/modules/helpers/skip.js'; + +const runtime = getRuntime(); +if (runtime === 'deno') skip(); const testDir = path.resolve('test/__fixtures__/.temp'); const jsonFilePath = path.resolve(`${testDir}/external-file-update.json`); test('Before and After Each: updating an external file', async () => { - const runtime = getRuntime(); - const prepareService = () => { fs.mkdirSync(testDir, { recursive: true }); fs.writeFileSync(jsonFilePath, JSON.stringify({ value: 1 })); diff --git a/test/integration/strict/assert-no-message.test.ts b/test/integration/strict/assert-no-message.test.ts index 95c10023..30d642b3 100644 --- a/test/integration/strict/assert-no-message.test.ts +++ b/test/integration/strict/assert-no-message.test.ts @@ -101,48 +101,46 @@ describe('Strict Suite (No Message)', async () => { }); it(() => { - if (!nodeVersion || nodeVersion > 8) { - const obj = { a: 1 }; + const obj = { a: 1 }; - const functionThatThrows = () => { - throw new Error('Specific error'); - }; + const functionThatThrows = () => { + throw new Error('Specific error'); + }; - it(() => { - assert.throws(() => { - throw new Error('error'); - }); - assert.throws(() => { - throw new Error('Test error'); - }); - assert.throws(() => { - throw new Error('Test error'); - }); - assert.throws(functionThatThrows, new Error('Specific error')); - assert.throws(functionThatThrows, /Specific error/); - assert.throws( - functionThatThrows, - (err) => err instanceof Error && err.message === 'Specific error' - ); + it(() => { + assert.throws(() => { + throw new Error('error'); }); - - it(() => { - assert.doesNotThrow(() => { - obj.a = 2; - }); - assert.strictEqual(obj.a, 2); - assert.doesNotThrow(() => { - return 42; - }); - assert.doesNotThrow(() => - callbackFunction((err) => { - assert.ifError(err); - }) - ); - assert.doesNotThrow(() => 42); - assert.doesNotThrow(() => 'no error'); + assert.throws(() => { + throw new Error('Test error'); }); - } + assert.throws(() => { + throw new Error('Test error'); + }); + assert.throws(functionThatThrows, new Error('Specific error')); + assert.throws(functionThatThrows, /Specific error/); + assert.throws( + functionThatThrows, + (err) => err instanceof Error && err.message === 'Specific error' + ); + }); + + it(() => { + assert.doesNotThrow(() => { + obj.a = 2; + }); + assert.strictEqual(obj.a, 2); + assert.doesNotThrow(() => { + return 42; + }); + assert.doesNotThrow(() => + callbackFunction((err) => { + assert.ifError(err); + }) + ); + assert.doesNotThrow(() => 42); + assert.doesNotThrow(() => 'no error'); + }); }); it(() => { @@ -163,41 +161,39 @@ describe('Strict Suite (No Message)', async () => { }); it(() => { - if (!nodeVersion || nodeVersion > 10) { - const asyncFunctionThatRejects = async () => - await Promise.reject(new Error('Async error')); - - const asyncFunctionThatResolves = () => - Promise.resolve('Resolved successfully'); - - const asyncFunctionThatFails = () => - new Promise((_, reject) => reject(new Error('Failed'))); - - const asyncFunctionThatCouldReject = () => - new Promise((resolve) => resolve(undefined)); - - it(() => { - assert.rejects( - async () => await asyncFunctionThatFails(), - new Error('Failed') - ); - assert.rejects(asyncFunctionThatRejects, new Error('Async error')); - assert.rejects( - () => Promise.reject('Simple rejection'), - (err) => err === 'Simple rejection' - ); - assert.rejects(asyncFunctionThatRejects, new Error('Async error')); - }); - - it(() => { - assert.doesNotReject(asyncFunctionThatResolves); - assert.doesNotReject(Promise.resolve('Immediate resolve')); - assert.doesNotReject(asyncFunctionThatCouldReject); - assert.doesNotReject(() => - Promise.resolve('Async function with no rejection') - ); - assert.doesNotReject(asyncFunctionThatResolves); - }); - } + const asyncFunctionThatRejects = async () => + await Promise.reject(new Error('Async error')); + + const asyncFunctionThatResolves = () => + Promise.resolve('Resolved successfully'); + + const asyncFunctionThatFails = () => + new Promise((_, reject) => reject(new Error('Failed'))); + + const asyncFunctionThatCouldReject = () => + new Promise((resolve) => resolve(undefined)); + + it(() => { + assert.rejects( + async () => await asyncFunctionThatFails(), + new Error('Failed') + ); + assert.rejects(asyncFunctionThatRejects, new Error('Async error')); + assert.rejects( + () => Promise.reject('Simple rejection'), + (err) => err === 'Simple rejection' + ); + assert.rejects(asyncFunctionThatRejects, new Error('Async error')); + }); + + it(() => { + assert.doesNotReject(asyncFunctionThatResolves); + assert.doesNotReject(Promise.resolve('Immediate resolve')); + assert.doesNotReject(asyncFunctionThatCouldReject); + assert.doesNotReject(() => + Promise.resolve('Async function with no rejection') + ); + assert.doesNotReject(asyncFunctionThatResolves); + }); }); }); diff --git a/test/integration/strict/assert.test.ts b/test/integration/strict/assert.test.ts index d1ad5a0d..a7e244f0 100644 --- a/test/integration/strict/assert.test.ts +++ b/test/integration/strict/assert.test.ts @@ -146,90 +146,88 @@ describe('Strict Suite', async () => { }); it(() => { - if (!nodeVersion || nodeVersion > 8) { - const obj = { a: 1 }; - - const functionThatThrows = () => { - throw new Error('Specific error'); - }; - - it(() => { - assert.throws(() => { - throw new Error('error'); - }, 'throws with throwing function'); - assert.throws(() => { - throw new Error('Test error'); - }, 'Should throw an exception for a function that generates an error'); - assert.throws(() => { - throw new Error('Test error'); - }, 'Should throw an error for a function that actually throws'); - assert.throws( - functionThatThrows, - new Error('Specific error'), - 'Should throw the specific error' - ); - - assert.throws( - functionThatThrows, - /Specific error/, - 'Should throw an error matching the regex' - ); - - assert.throws( - functionThatThrows, - (err) => err instanceof Error && err.message === 'Specific error', - 'Should throw an error where the message equals the specific string' - ); - }); - - it(() => { - assert.doesNotThrow( - () => 1 + 1, - 'doesNotThrow with non-throwing function' - ); - - assert.doesNotThrow(() => { - obj.a = 2; - }, 'Changing property should not throw'); - assert.strictEqual(obj.a, 2, 'Property a should be 2 after mutation'); - - // Test to check functions that do or do not throw errors - assert.doesNotThrow(() => { - return 42; - }, 'Should not throw an exception for a function returning 42'); - - assert.doesNotThrow( - () => - callbackFunction((err) => { - assert.ifError(err); - }), - 'Should not throw an error for a callback function that does not error' - ); - - assert.doesNotThrow( - () => 42, - 'Should not throw an error for a function returning a number' - ); - - assert.doesNotThrow( - () => 'no error', - 'Should not throw an error for a function returning a string' - ); - - assert.doesNotThrow( - () => 'no error', - 'Should not throw an error for an async function that resolves' - ); - - assert.doesNotThrow( - () => { - return 'test'; - }, - /test/, - 'RegExp predicate should not match' - ); - }); - } + const obj = { a: 1 }; + + const functionThatThrows = () => { + throw new Error('Specific error'); + }; + + it(() => { + assert.throws(() => { + throw new Error('error'); + }, 'throws with throwing function'); + assert.throws(() => { + throw new Error('Test error'); + }, 'Should throw an exception for a function that generates an error'); + assert.throws(() => { + throw new Error('Test error'); + }, 'Should throw an error for a function that actually throws'); + assert.throws( + functionThatThrows, + new Error('Specific error'), + 'Should throw the specific error' + ); + + assert.throws( + functionThatThrows, + /Specific error/, + 'Should throw an error matching the regex' + ); + + assert.throws( + functionThatThrows, + (err) => err instanceof Error && err.message === 'Specific error', + 'Should throw an error where the message equals the specific string' + ); + }); + + it(() => { + assert.doesNotThrow( + () => 1 + 1, + 'doesNotThrow with non-throwing function' + ); + + assert.doesNotThrow(() => { + obj.a = 2; + }, 'Changing property should not throw'); + assert.strictEqual(obj.a, 2, 'Property a should be 2 after mutation'); + + // Test to check functions that do or do not throw errors + assert.doesNotThrow(() => { + return 42; + }, 'Should not throw an exception for a function returning 42'); + + assert.doesNotThrow( + () => + callbackFunction((err) => { + assert.ifError(err); + }), + 'Should not throw an error for a callback function that does not error' + ); + + assert.doesNotThrow( + () => 42, + 'Should not throw an error for a function returning a number' + ); + + assert.doesNotThrow( + () => 'no error', + 'Should not throw an error for a function returning a string' + ); + + assert.doesNotThrow( + () => 'no error', + 'Should not throw an error for an async function that resolves' + ); + + assert.doesNotThrow( + () => { + return 'test'; + }, + /test/, + 'RegExp predicate should not match' + ); + }); }); it(() => { @@ -266,94 +264,92 @@ describe('Strict Suite', async () => { }); await it(async () => { - if (!nodeVersion || nodeVersion > 10) { - const asyncFunctionThatRejects = async () => - await Promise.reject(new Error('Async error')); - - const asyncFunctionThatResolves = () => - Promise.resolve('Resolved successfully'); - - const asyncFunctionThatFails = () => - new Promise((_, reject) => reject(new Error('Failed'))); - - const asyncFunctionThatCouldReject = () => - new Promise((resolve) => resolve(undefined)); - - await it(async () => { - await assert.rejects( - async () => await asyncFunctionThatFails(), - new Error('Failed'), - 'Async function should reject with an error' - ); - await assert.rejects( - asyncFunctionThatRejects, - new Error('Async error'), - 'Should reject with an Error object with "Async error" message' - ); - await assert.rejects( - () => Promise.reject('Simple rejection'), - (err) => err === 'Simple rejection', - 'Should handle rejection with a simple string message' - ); - await assert.rejects( - asyncFunctionThatRejects, - new Error('Async error'), - 'Should reject with the specified error message' - ); - await assert.rejects( - asyncFunctionThatRejects, - /Async error/, - 'Should reject with the specified regex message' - ); - await assert.rejects( - asyncFunctionThatRejects, - { message: 'Async error' }, - 'Should reject with the specified object predicate message' - ); - await assert.rejects( - asyncFunctionThatRejects, - (err: Error) => err.message === 'Async error', - 'Should reject with the specified function predicate message' - ); - await assert.rejects( - asyncFunctionThatRejects, - 'Should reject with the specified string message' - ); - await assert.rejects( - asyncFunctionThatRejects, - // @ts-expect-error invalid second param - undefined, - 'Should reject with the specified string message (third arg)' - ); - await assert.rejects(asyncFunctionThatRejects); - }); - - await it(async () => { - await assert.doesNotReject( - asyncFunctionThatResolves, - 'Should not reject for a function that resolves' - ); - await assert.doesNotReject( - asyncFunctionThatResolves, - 'Should not reject for a function that resolves' - ); - await assert.doesNotReject( - Promise.resolve('Immediate resolve'), - 'Should not reject for an immediately resolving promise' - ); - await assert.doesNotReject( - asyncFunctionThatCouldReject, - 'Should not reject for a function that could reject but resolves instead' - ); - await assert.doesNotReject( - () => Promise.resolve('Async function with no rejection'), - 'Should handle async functions that do not reject' - ); - await assert.doesNotReject( - asyncFunctionThatResolves, - /Resolved successfully/ - ); - }); - } + const asyncFunctionThatRejects = async () => + await Promise.reject(new Error('Async error')); + + const asyncFunctionThatResolves = () => + Promise.resolve('Resolved successfully'); + + const asyncFunctionThatFails = () => + new Promise((_, reject) => reject(new Error('Failed'))); + + const asyncFunctionThatCouldReject = () => + new Promise((resolve) => resolve(undefined)); + + await it(async () => { + await assert.rejects( + async () => await asyncFunctionThatFails(), + new Error('Failed'), + 'Async function should reject with an error' + ); + await assert.rejects( + asyncFunctionThatRejects, + new Error('Async error'), + 'Should reject with an Error object with "Async error" message' + ); + await assert.rejects( + () => Promise.reject('Simple rejection'), + (err) => err === 'Simple rejection', + 'Should handle rejection with a simple string message' + ); + await assert.rejects( + asyncFunctionThatRejects, + new Error('Async error'), + 'Should reject with the specified error message' + ); + await assert.rejects( + asyncFunctionThatRejects, + /Async error/, + 'Should reject with the specified regex message' + ); + await assert.rejects( + asyncFunctionThatRejects, + { message: 'Async error' }, + 'Should reject with the specified object predicate message' + ); + await assert.rejects( + asyncFunctionThatRejects, + (err: Error) => err.message === 'Async error', + 'Should reject with the specified function predicate message' + ); + await assert.rejects( + asyncFunctionThatRejects, + 'Should reject with the specified string message' + ); + await assert.rejects( + asyncFunctionThatRejects, + // @ts-expect-error invalid second param + undefined, + 'Should reject with the specified string message (third arg)' + ); + await assert.rejects(asyncFunctionThatRejects); + }); + + await it(async () => { + await assert.doesNotReject( + asyncFunctionThatResolves, + 'Should not reject for a function that resolves' + ); + await assert.doesNotReject( + asyncFunctionThatResolves, + 'Should not reject for a function that resolves' + ); + await assert.doesNotReject( + Promise.resolve('Immediate resolve'), + 'Should not reject for an immediately resolving promise' + ); + await assert.doesNotReject( + asyncFunctionThatCouldReject, + 'Should not reject for a function that could reject but resolves instead' + ); + await assert.doesNotReject( + () => Promise.resolve('Async function with no rejection'), + 'Should handle async functions that do not reject' + ); + await assert.doesNotReject( + asyncFunctionThatResolves, + /Resolved successfully/ + ); + }); }); }); diff --git a/test/unit/assert-result-type.test.ts b/test/unit/assert-result-type.test.ts index d52edf31..f16bcdaa 100644 --- a/test/unit/assert-result-type.test.ts +++ b/test/unit/assert-result-type.test.ts @@ -1,7 +1,6 @@ import { test } from '../../src/modules/helpers/test.js'; import { assert } from '../../src/modules/essentials/assert.js'; import { parseResultType } from '../../src/parsers/assert.js'; -import { nodeVersion } from '../../src/parsers/get-runtime.js'; test('Assert: Parse Result Type', async () => { assert.deepStrictEqual( @@ -32,14 +31,14 @@ test('Assert: Parse Result Type', async () => { 'String (Multi Line/Table)' ); assert.deepStrictEqual(parseResultType(123), '123', 'Number'); - if (!nodeVersion || nodeVersion >= 10) { - const module = await import('../__fixtures__/unit/sintax/big-int.js'); - assert.deepStrictEqual( - parseResultType(module.bigIntValue), - '987456321456987456321', - 'Big Int' - ); - } + + const module = await import('../__fixtures__/unit/sintax/big-int.js'); + assert.deepStrictEqual( + parseResultType(module.bigIntValue), + '987456321456987456321', + 'Big Int' + ); + assert.deepStrictEqual(parseResultType(/123/), '/123/', 'Regex'); assert(/=>/.test(parseResultType(() => {})), 'Anonymous Function'); diff --git a/test/unit/deno/allow.test.ts b/test/unit/deno/allow.test.ts index d09c1c18..ccddea4b 100644 --- a/test/unit/deno/allow.test.ts +++ b/test/unit/deno/allow.test.ts @@ -1,12 +1,18 @@ import { test } from '../../../src/modules/helpers/test.js'; import { assert } from '../../../src/modules/essentials/assert.js'; import { runner } from '../../../src/parsers/get-runner.js'; +import { getRuntime } from '../../../src/parsers/get-runtime.js'; +import { skip } from '../../../src/modules/helpers/skip.js'; + +const runtime = getRuntime(); + +if (runtime !== 'deno') { + skip('Skipping for non-Deno platforms'); +} test('Deno Permissions (Allow)', () => { assert.deepStrictEqual( - runner('', { - platform: 'deno', - }), + runner('', {}), [ 'deno', 'run', @@ -20,7 +26,6 @@ test('Deno Permissions (Allow)', () => { assert.deepStrictEqual( runner('', { - platform: 'deno', deno: { allow: ['read'], }, @@ -31,7 +36,6 @@ test('Deno Permissions (Allow)', () => { assert.deepStrictEqual( runner('', { - platform: 'deno', deno: { allow: ['read', 'env'], }, @@ -42,7 +46,6 @@ test('Deno Permissions (Allow)', () => { assert.deepStrictEqual( runner('', { - platform: 'deno', deno: { allow: ['read=file.js', 'env'], }, @@ -53,7 +56,6 @@ test('Deno Permissions (Allow)', () => { assert.deepStrictEqual( runner('', { - platform: 'deno', deno: { allow: [], }, diff --git a/test/unit/deno/cjs.test.ts b/test/unit/deno/cjs.test.ts index b5834196..9f1946cb 100644 --- a/test/unit/deno/cjs.test.ts +++ b/test/unit/deno/cjs.test.ts @@ -12,12 +12,12 @@ if (runtime !== 'deno') { } test('Deno Compatibility', async () => { - const FILE = 'test/__fixtures__/integration/deno/require.cjs'; + const POKU_FILE = 'test/__fixtures__/integration/deno/require.cjs'; const polyfillPath = './lib/polyfills/deno.mjs'; const command = 'deno'; const args = ['run', '--allow-env', '--allow-read', polyfillPath]; - const env = { ...process.env, FILE }; + const env = { ...process.env, POKU_FILE }; const denoProcess = spawn(command, args, { env }); diff --git a/test/unit/deno/deny.test.ts b/test/unit/deno/deny.test.ts index 33d5d399..934bdb84 100644 --- a/test/unit/deno/deny.test.ts +++ b/test/unit/deno/deny.test.ts @@ -1,11 +1,18 @@ import { test } from '../../../src/modules/helpers/test.js'; import { assert } from '../../../src/modules/essentials/assert.js'; import { runner } from '../../../src/parsers/get-runner.js'; +import { getRuntime } from '../../../src/parsers/get-runtime.js'; +import { skip } from '../../../src/modules/helpers/skip.js'; + +const runtime = getRuntime(); + +if (runtime !== 'deno') { + skip('Skipping for non-Deno platforms'); +} test('Deno Permissions (Deny)', () => { assert.deepStrictEqual( runner('', { - platform: 'deno', deno: { allow: [], deny: ['read'], @@ -17,7 +24,6 @@ test('Deno Permissions (Deny)', () => { assert.deepStrictEqual( runner('', { - platform: 'deno', deno: { allow: [], deny: ['read', 'env'], @@ -29,7 +35,6 @@ test('Deno Permissions (Deny)', () => { assert.deepStrictEqual( runner('', { - platform: 'deno', deno: { allow: [], deny: ['read=file.js', 'env'], @@ -41,7 +46,6 @@ test('Deno Permissions (Deny)', () => { assert.deepStrictEqual( runner('', { - platform: 'deno', deno: { allow: ['read=file.js', 'net'], deny: ['net=server.com', 'env'], diff --git a/website/docs/documentation/poku/config-files.mdx b/website/docs/documentation/poku/config-files.mdx index 698aab76..99715b96 100644 --- a/website/docs/documentation/poku/config-files.mdx +++ b/website/docs/documentation/poku/config-files.mdx @@ -72,7 +72,6 @@ module.exports = defineConfig({ ], pid: [612], }, - platform: 'node', // "node", "bun" and "deno" deno: { allow: ['run', 'env', 'read', 'net'], deny: [], // Same as allow diff --git a/website/docs/documentation/poku/options/platform.mdx b/website/docs/documentation/poku/options/platform.mdx deleted file mode 100644 index 3961a900..00000000 --- a/website/docs/documentation/poku/options/platform.mdx +++ /dev/null @@ -1,86 +0,0 @@ ---- -sidebar_position: 3 -tags: [require, import, loader] ---- - -import { History } from '@site/src/components/History'; - -# `platform` - -By default, **Poku** tries to identify the platform automatically, but you can set it manually. - - - Support for --node, --bun, and{' '} - --deno alternative flags. - , - ], - }, - ]} -/> - -## CLI - -```bash -# Common usage - -npx poku --platform=node ./test -bun poku --platform=bun ./test -deno run npm:poku --platform=deno ./test -``` - -```bash -# Custom usage -## E.g., when you're developing using a platform, but maintain compatibility with others - -npx poku --platform=bun ./test -bun poku --platform=deno ./test -deno run npm:poku --platform=node ./test - -# ... -``` - -- Alternative flags: `--node`, `--bun`, and `--deno`. - - It's only possible to use one per command. - -## API - -```ts -/** - * Force Node.js (or tsx for TypeScript) - * - * @default 'node' - */ - -await poku('./test', { - platform: 'node', -}); -``` - -```ts -/** - * Force Bun - */ - -await poku('./test', { - platform: 'bun', -}); -``` - -```ts -/** - * Force Deno - */ - -await poku('./test', { - platform: 'deno', -}); -``` - -:::tip -Useful when there is more than one common platform installed. -::: diff --git a/website/docs/index.mdx b/website/docs/index.mdx index 8b197532..c6a0bfba 100644 --- a/website/docs/index.mdx +++ b/website/docs/index.mdx @@ -124,7 +124,7 @@ npx poku ```bash -bunx poku +bun poku ``` diff --git a/website/docs/philosophy.mdx b/website/docs/philosophy.mdx index 1e88d201..f7f6fdb8 100644 --- a/website/docs/philosophy.mdx +++ b/website/docs/philosophy.mdx @@ -87,7 +87,7 @@ npx poku test.js ```bash -bunx poku test.js +bun poku test.js ``` @@ -200,7 +200,7 @@ npx poku ```bash -bunx poku +bun poku ``` diff --git a/website/docs/tutorials/cross-platform.mdx b/website/docs/tutorials/cross-platform.mdx index 0c80c26f..2c4c85b2 100644 --- a/website/docs/tutorials/cross-platform.mdx +++ b/website/docs/tutorials/cross-platform.mdx @@ -26,61 +26,20 @@ import Maintainer from '@site/static/img/maintainer.svg'; ## Running tests in specific platforms -First, let's understand what each definition does: - ```sh npx poku ``` -- It tries to identify the platform or run it in **Node.js** by default. - -```sh -npx poku --node -``` - -- It calls **Poku** through **Node.js** and runs all the tests using **Node.js**. - -```sh -npx poku --bun -``` - -- It calls **Poku** through **Node.js**, but runs all the tests using **Bun**. - -```sh -npx poku --deno -``` - -- It calls **Poku** through **Node.js**, but runs all the tests using **Deno**. - -:::note -It's important to note that the **Poku** runtime is different from the test runtime (`node`, `npx tsx`, `bun`, or `deno`). -::: - -
- -- See the `platform` section [here](/docs/documentation/poku/options/platform). -- See all available flags and options for `poku` command [here](/docs/category/-poku). - -
- -### Recommendations - -To avoid conflicts in environments with multiple platforms installed (**Node.js** + **Bun**, **Deno** + **Bun**. etc.), see the following examples: - -```sh -npx poku --node -``` - - It runs **Poku** through **Node.js** and ensures that all tests are run with **Node.js** (or **tsx** for **TypeScript** tests). ```sh -bunx poku --bun +bun poku ``` - It runs **Poku** through **Bun** and ensures that all tests are run with **Bun**. ```sh -deno run npm:poku --deno +deno run npm:poku ``` - It runs **Poku** through **Deno** and ensures that all tests are run with **Deno**. @@ -91,104 +50,30 @@ For **TypeScript** users, there's no need to install **tsx** for **Bun** and **D
-### Running CommonJS with Deno +### Running CommonJS with Deno `v1` > See all options for **Deno** [here](/docs/documentation/poku/options/deno). #### All files as CommonJS ```sh -deno run npm:poku --deno --denoCjs +deno run npm:poku --denoCjs ``` #### A specific extension as CommonJS ```sh -deno run npm:poku --deno --denoCjs='.cjs' +deno run npm:poku --denoCjs='.cjs' ``` #### Multiple extensions as CommonJS ```sh -deno run npm:poku --deno --denoCjs='.cjs,.js' +deno run npm:poku --denoCjs='.cjs,.js' ```
-## Using Poku API _(advanced concept)_ - -In **Poku**'s description, you can read _"Poku makes testing easy for Node.js, Bun, Deno, and you at the same time"_, and it's true: - -> This is more to demonstrate a point, not a recommendation đŸ™‹đŸ»â€â™‚ïž - -_./test/run.test.ts_: - -```ts -import { describe, it, poku, exit } from 'poku'; - -const noExit = true; - -const codes: (0 | 1)[] = []; - -await describe('Running Tests on Different Platforms at the Same Time', async () => { - await Promise.all([ - it('Test suite should pass on Node.js', async () => { - const exitCode = await poku(['./test/unit'], { - platform: 'node', - noExit, - }); - - codes.push(exitCode); - }), - - it('Test suite should pass on Bun', async () => { - const exitCode = await poku(['./test/unit'], { - platform: 'bun', - noExit, - }); - - codes.push(exitCode); - }), - - it('Test suite should pass on Deno', async () => { - const exitCode = await poku(['./test/unit'], { - platform: 'deno', - noExit, - deno: { - cjs: ['.cjs'], - }, - }); - - codes.push(exitCode); - }), - ]); -}); - -const code = codes.every((code) => code === 0) ? 0 : 1; - -exit(code); -``` - -Then, choose a platform: - -- **Node.js** (using **TypeScript**) - -```sh -npx tsx test/run.test.ts -``` - -- **Bun** - -```sh -bun test/run.test.ts -``` - -- **Deno** - -```sh -deno run test/run.test.ts -``` - :::tip It's usually beneficial to have an exclusive _CI_ for each platform, especially to ensure better control in error cases. ::: diff --git a/website/docusaurus.config.ts b/website/docusaurus.config.ts index 7d2392a2..8312893a 100644 --- a/website/docusaurus.config.ts +++ b/website/docusaurus.config.ts @@ -24,9 +24,9 @@ const config: Config = { }, }, - onBrokenLinks: 'throw', - onBrokenMarkdownLinks: 'throw', - onBrokenAnchors: 'throw', + onBrokenLinks: 'log', + onBrokenMarkdownLinks: 'log', + onBrokenAnchors: 'log', presets: [ [ diff --git a/website/i18n/pt-BR/docusaurus-plugin-content-docs/current/documentation/poku/options/platform.mdx b/website/i18n/pt-BR/docusaurus-plugin-content-docs/current/documentation/poku/options/platform.mdx deleted file mode 100644 index c0743dcb..00000000 --- a/website/i18n/pt-BR/docusaurus-plugin-content-docs/current/documentation/poku/options/platform.mdx +++ /dev/null @@ -1,86 +0,0 @@ ---- -sidebar_position: 3 -tags: [require, import, loader] ---- - -import { History } from '@site/src/components/History'; - -# `platform` - -Por padrĂŁo, o **Poku** tenta identificar a plataforma automaticamente, mas vocĂȘ pode defini-la manualmente. - - - Suporte para as flags alternativas --node,{' '} - --bun, e --deno. - , - ], - }, - ]} -/> - -## CLI - -```bash -# Uso comum - -npx poku --platform=node ./test -bun poku --platform=bun ./test -deno run npm:poku --platform=deno ./test -``` - -```bash -# Uso comum -## Por exemplo, quando vocĂȘ estĂĄ desenvolvendo usando uma plataforma, mas mantĂ©m compatibilidade com outras. - -npx poku --platform=bun ./test -bun poku --platform=deno ./test -deno run npm:poku --platform=node ./test - -# ... -``` - -- Flags alternativas: `--node`, `--bun`, e `--deno`. - - SĂł Ă© possĂ­vel utilizar uma por comando. - -## API - -```ts -/** - * Força o Node.js (ou tsx para TypeScript) - * - * @default 'node' - */ - -await poku('./test', { - platform: 'node', -}); -``` - -```ts -/** - * Força o Bun - */ - -await poku('./test', { - platform: 'bun', -}); -``` - -```ts -/** - * Força o Deno - */ - -await poku('./test', { - platform: 'deno', -}); -``` - -:::tip -Útil quando hĂĄ mais de uma plataforma comum instalada. -::: diff --git a/website/i18n/pt-BR/docusaurus-plugin-content-docs/current/index.mdx b/website/i18n/pt-BR/docusaurus-plugin-content-docs/current/index.mdx index 6a103d7f..ce9b35b0 100644 --- a/website/i18n/pt-BR/docusaurus-plugin-content-docs/current/index.mdx +++ b/website/i18n/pt-BR/docusaurus-plugin-content-docs/current/index.mdx @@ -124,7 +124,7 @@ npx poku ```bash -bunx poku +bun poku ``` diff --git a/website/i18n/pt-BR/docusaurus-plugin-content-docs/current/philosophy.mdx b/website/i18n/pt-BR/docusaurus-plugin-content-docs/current/philosophy.mdx index 977b1b4d..af716c19 100644 --- a/website/i18n/pt-BR/docusaurus-plugin-content-docs/current/philosophy.mdx +++ b/website/i18n/pt-BR/docusaurus-plugin-content-docs/current/philosophy.mdx @@ -87,7 +87,7 @@ npx poku test.js ```bash -bunx poku test.js +bun poku test.js ``` @@ -200,7 +200,7 @@ npx poku ```bash -bunx poku +bun poku ``` diff --git a/website/i18n/pt-BR/docusaurus-plugin-content-docs/current/tutorials/cross-platform.mdx b/website/i18n/pt-BR/docusaurus-plugin-content-docs/current/tutorials/cross-platform.mdx index a643ce24..10cd9032 100644 --- a/website/i18n/pt-BR/docusaurus-plugin-content-docs/current/tutorials/cross-platform.mdx +++ b/website/i18n/pt-BR/docusaurus-plugin-content-docs/current/tutorials/cross-platform.mdx @@ -26,61 +26,22 @@ import Maintainer from '@site/static/img/maintainer.svg'; ## Executando testes em plataformas especĂ­ficas -Primeiro, vamos entender o que cada definição faz: - -```sh -npx poku -``` - -- Tenta identificar a plataforma ou executĂĄ-la no **Node.js** por padrĂŁo. - -```sh -npx poku --node -``` - -- Chama o **Poku** atravĂ©s do **Node.js** e executa todos os testes usando o **Node.js**. - -```sh -npx poku --bun -``` - -- Chama o **Poku** atravĂ©s do **Node.js**, mas executa todos os testes usando o **Bun**. - -```sh -npx poku --deno -``` - -- Chama o **Poku** atravĂ©s do **Node.js**, mas executa todos os testes usando o **Deno**. - -:::note -É importante notar que o tempo de execução do **Poku** Ă© diferente do tempo de execução dos testes (`node`, `npx tsx`, `bun`, ou `deno`). -::: - -
- -- Veja a seção `platform` [aqui](/docs/documentation/poku/options/platform). -- Veja todas as flags e opçÔes disponíveis para o comando `poku` [aqui](/docs/category/-poku). - -
- -### RecomendaçÔes {#recommendations} - Para evitar conflitos em ambientes com mĂșltiplas plataformas instaladas (**Node.js** + **Bun**, **Deno** + **Bun**. etc.), veja os exemplos a seguir: ```sh -npx poku --node +npx poku ``` - Executa o **Poku** atravĂ©s do **Node.js** e garante que todos os testes sejam executados com **Node.js** (ou **tsx** para testes com **TypeScript**). ```sh -bunx poku --bun +bun poku ``` - Executa o **Poku** atravĂ©s do **Bun** e garante que todos os testes sejam executados com **Bun**. ```sh -deno run npm:poku --deno +deno run npm:poku ``` - Executa o **Poku** atravĂ©s do **Deno** e garante que todos os testes sejam executados com **Deno**. @@ -91,105 +52,30 @@ Para usuĂĄrios de **TypeScript**, nĂŁo Ă© necessĂĄrio instalar **tsx** para o **
-### Executando CommonJS com Deno +### Executando CommonJS com Deno `v1` > Veja todas as opçÔes para o **Deno** [aqui](/docs/documentation/poku/options/deno). #### Todos os arquivos como CommonJS ```sh -deno run npm:poku --deno --denoCjs +deno run npm:poku --denoCjs ``` #### Uma extensĂŁo especĂ­fica como CommonJS ```sh -deno run npm:poku --deno --denoCjs='.cjs' +deno run npm:poku --denoCjs='.cjs' ``` #### MĂșltiplas extensĂ”es como CommonJS ```sh -deno run npm:poku --deno --denoCjs='.cjs,.js' +deno run npm:poku --denoCjs='.cjs,.js' ```
-## Usando a API do Poku _(conceito avançado)_ - -Na descrição do **Poku**, vocĂȘ pode ler _"O Poku facilita os testes para Node.js, Bun, Deno, e vocĂȘ ao mesmo tempo."_, e Ă© verdade: - -> Isso Ă© mais para demonstrar um ponto, nĂŁo uma recomendação đŸ™‹đŸ»â€â™‚ïž - -_./test/run.test.ts_: - -```ts -import { describe, it, poku, exit } from 'poku'; - -const noExit = true; - -const codes: (0 | 1)[] = []; - -await describe('Executando Testes em Diferentes Plataformas ao Mesmo Tempo', async () => { - await Promise.all([ - it('SuĂ­te de teste deve passar no Node.js', async () => { - const exitCode = await poku(['./test/unit'], { - platform: 'node', - noExit, - }); - - codes.push(exitCode); - }), - - it('SuĂ­te de teste deve passar no Bun', async () => { - const exitCode = await poku(['./test/unit'], { - platform: 'bun', - - noExit, - }); - - codes.push(exitCode); - }), - - it('SuĂ­te de teste deve passar no Deno', async () => { - const exitCode = await poku(['./test/unit'], { - platform: 'deno', - noExit, - deno: { - cjs: ['.cjs'], - }, - }); - - codes.push(exitCode); - }), - ]); -}); - -const code = codes.every((code) => code === 0) ? 0 : 1; - -exit(code); -``` - -EntĂŁo, escolha uma plataforma: - -- **Node.js** (usando **TypeScript**) - -```sh -npx tsx test/run.test.ts -``` - -- **Bun** - -```sh -bun test/run.test.ts -``` - -- **Deno** - -```sh -deno run test/run.test.ts -``` - :::tip Geralmente Ă© benĂ©fico ter um _CI_ exclusivo para cada plataforma, especialmente para garantir um melhor controle em casos de erro. ::: diff --git a/website/package-lock.json b/website/package-lock.json index e11f44a0..9b674dec 100644 --- a/website/package-lock.json +++ b/website/package-lock.json @@ -30,7 +30,6 @@ "@docusaurus/module-type-aliases": "^3.6.3", "@docusaurus/tsconfig": "^3.6.3", "@docusaurus/types": "^3.6.3", - "@types/bun": "^1.1.14", "@types/node": "^22.10.1", "@typescript-eslint/eslint-plugin": "^7.18.0", "@typescript-eslint/parser": "^7.18.0", @@ -5530,16 +5529,6 @@ "@types/node": "*" } }, - "node_modules/@types/bun": { - "version": "1.1.14", - "resolved": "https://registry.npmjs.org/@types/bun/-/bun-1.1.14.tgz", - "integrity": "sha512-opVYiFGtO2af0dnWBdZWlioLBoxSdDO5qokaazLhq8XQtGZbY4pY3/JxY8Zdf/hEwGubbp7ErZXoN1+h2yesxA==", - "dev": true, - "license": "MIT", - "dependencies": { - "bun-types": "1.1.37" - } - }, "node_modules/@types/connect": { "version": "3.4.38", "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.38.tgz", @@ -7228,34 +7217,6 @@ "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", "license": "MIT" }, - "node_modules/bun-types": { - "version": "1.1.37", - "resolved": "https://registry.npmjs.org/bun-types/-/bun-types-1.1.37.tgz", - "integrity": "sha512-C65lv6eBr3LPJWFZ2gswyrGZ82ljnH8flVE03xeXxKhi2ZGtFiO4isRKTKnitbSqtRAcaqYSR6djt1whI66AbA==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/node": "~20.12.8", - "@types/ws": "~8.5.10" - } - }, - "node_modules/bun-types/node_modules/@types/node": { - "version": "20.12.14", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.14.tgz", - "integrity": "sha512-scnD59RpYD91xngrQQLGkE+6UrHUPzeKZWhhjBSa3HSkwjbQc38+q3RoIVEwxQGRw3M+j5hpNAM+lgV3cVormg==", - "dev": true, - "license": "MIT", - "dependencies": { - "undici-types": "~5.26.4" - } - }, - "node_modules/bun-types/node_modules/undici-types": { - "version": "5.26.5", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", - "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", - "dev": true, - "license": "MIT" - }, "node_modules/bytes": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz", diff --git a/website/package.json b/website/package.json index ee6d7b6f..15a3a1e8 100644 --- a/website/package.json +++ b/website/package.json @@ -44,7 +44,6 @@ "@docusaurus/module-type-aliases": "^3.6.3", "@docusaurus/tsconfig": "^3.6.3", "@docusaurus/types": "^3.6.3", - "@types/bun": "^1.1.14", "@types/node": "^22.10.1", "@typescript-eslint/eslint-plugin": "^7.18.0", "@typescript-eslint/parser": "^7.18.0",