diff --git a/src/helpers/find-file.ts b/src/helpers/find-file.ts index c40811e1..eece2729 100644 --- a/src/helpers/find-file.ts +++ b/src/helpers/find-file.ts @@ -1,8 +1,6 @@ /* c8 ignore start */ -import { EOL } from 'node:os'; - export const findFile = (error: Error) => { - const stackLines = error.stack?.split(EOL) || []; + const stackLines = error.stack?.split('\n') || []; let file = ''; diff --git a/src/helpers/get-arg.ts b/src/helpers/get-arg.ts index 598dbc61..f803610b 100644 --- a/src/helpers/get-arg.ts +++ b/src/helpers/get-arg.ts @@ -1,7 +1,7 @@ /* c8 ignore start */ -import process from 'node:process'; +import { argv } from 'node:process'; -const [, , ...processArgs] = process.argv; +const [, , ...processArgs] = argv; /** * Gets the value of an argument. diff --git a/src/helpers/get-runtime.ts b/src/helpers/get-runtime.ts index 58955722..1262831e 100644 --- a/src/helpers/get-runtime.ts +++ b/src/helpers/get-runtime.ts @@ -1,6 +1,6 @@ /* c8 ignore start */ -import process from 'node:process'; +import { version } from 'node:process'; import type { Configs } from '../@types/poku.js'; declare const Deno: unknown; @@ -37,8 +37,6 @@ export const getRuntime = ( }; export const nodeVersion = - getRuntime() === 'node' - ? Number(process.version.match(/v(\d+)\./)?.[1]) - : undefined; + getRuntime() === 'node' ? Number(version.match(/v(\d+)\./)?.[1]) : undefined; /* c8 ignore stop */ diff --git a/src/helpers/hr.ts b/src/helpers/hr.ts index c123e002..a8573164 100644 --- a/src/helpers/hr.ts +++ b/src/helpers/hr.ts @@ -1,13 +1,10 @@ /* c8 ignore start */ - -import process from 'node:process'; -import { EOL } from 'node:os'; +import { stdout } from 'node:process'; import { write } from './logs.js'; export const hr = () => { - const line = '⎯'.repeat(process.stdout.columns - 10 || 40); + const line = '⎯'.repeat(stdout.columns - 10 || 40); - write(`${EOL}\x1b[2m\x1b[90m${line}\x1b[0m${EOL}`); + write(`\n\x1b[2m\x1b[90m${line}\x1b[0m\n`); }; - /* c8 ignore stop */ diff --git a/src/helpers/logs.ts b/src/helpers/logs.ts index d2a6617a..6961eac7 100644 --- a/src/helpers/logs.ts +++ b/src/helpers/logs.ts @@ -1,7 +1,6 @@ /* c8 ignore start */ -import process from 'node:process'; -import { EOL } from 'node:os'; +import { stdout } from 'node:process'; import type { Configs } from '../@types/poku.js'; export const isQuiet = (configs?: Configs): boolean => @@ -10,7 +9,7 @@ export const isQuiet = (configs?: Configs): boolean => export const isDebug = (configs?: Configs): boolean => Boolean(configs?.debug); export const write = (data: string | Uint8Array) => - process.stdout.write(`${String(data)}\n`); + stdout.write(`${String(data)}\n`); export const printOutput = (options: { output: string; @@ -38,7 +37,7 @@ export const printOutput = (options: { const mappedOutputs = outputs.map((current) => `${pad}${current}`); - write(mappedOutputs.join(EOL)); + write(mappedOutputs.join('\n')); }; /* c8 ignore stop */ diff --git a/src/helpers/parse-assertion.ts b/src/helpers/parse-assertion.ts index 1051e082..786fed35 100644 --- a/src/helpers/parse-assertion.ts +++ b/src/helpers/parse-assertion.ts @@ -1,7 +1,6 @@ -import process from 'node:process'; +import { cwd as processCWD, env, exit } from 'node:process'; import path from 'node:path'; import assert from 'node:assert'; -import { EOL } from 'node:os'; import { format } from './format.js'; import { hr } from './hr.js'; import { findFile } from './find-file.js'; @@ -15,7 +14,7 @@ import { write } from './logs.js'; /* c8 ignore next */ import type { ParseAssertionOptions } from '../@types/assert.js'; -const cwd = process.cwd(); +const cwd = processCWD(); export const parseResultType = (type?: unknown): string => { const recurse = (value: unknown): unknown => { @@ -64,9 +63,8 @@ export const parseAssertion = async ( cb: () => void | Promise, options: ParseAssertionOptions ) => { - const isPoku = - typeof process.env?.FILE === 'string' && process.env?.FILE.length > 0; - const FILE = process.env.FILE; + const isPoku = typeof env?.FILE === 'string' && env?.FILE.length > 0; + const FILE = env.FILE; let preIdentation = ''; if (indentation.hasDescribe || indentation.hasTest) preIdentation += ' '; @@ -125,7 +123,7 @@ export const parseAssertion = async ( file && write(`${format.dim(`${preIdentation} File`)} ${file}`); write(`${format.dim(`${preIdentation} Code`)} ${code}`); - write(`${format.dim(`${preIdentation} Operator`)} ${operator}${EOL}`); + write(`${format.dim(`${preIdentation} Operator`)} ${operator}\n`); if (!options?.hideDiff) { const splitActual = parseResultType(actual).split('\n'); @@ -137,7 +135,7 @@ export const parseAssertion = async ( ); write( - `${EOL}${preIdentation} ${format.dim(`${options?.expected || 'Expected'}:`)}` + `\n${preIdentation} ${format.dim(`${options?.expected || 'Expected'}:`)}` ); splitExpected.forEach((line) => write(`${preIdentation} ${format.bold(format.success(line))}`) @@ -149,7 +147,7 @@ export const parseAssertion = async ( hr(); } - process.exit(1); + exit(1); } // Non-assertion errors diff --git a/src/helpers/runner.ts b/src/helpers/runner.ts index a9f51196..2814fff9 100644 --- a/src/helpers/runner.ts +++ b/src/helpers/runner.ts @@ -1,12 +1,12 @@ /* c8 ignore start */ -import process from 'node:process'; +import { platform } from 'node:process'; import { extname } from 'node:path'; import { getRuntime } from './get-runtime.js'; import type { Configs } from '../@types/poku.js'; import type { Runner } from '../@types/runner.js'; -export const isWindows = process.platform === 'win32'; +export const isWindows = platform === 'win32'; export const runner = (filename: string, configs?: Configs): string[] => { const runtime = getRuntime(configs); diff --git a/src/modules/describe.ts b/src/modules/describe.ts index efe9fcd4..9f9c3a7b 100644 --- a/src/modules/describe.ts +++ b/src/modules/describe.ts @@ -1,5 +1,5 @@ /* c8 ignore next */ -import process from 'node:process'; +import { hrtime } from 'node:process'; import { format, backgroundColor } from '../helpers/format.js'; import { write } from '../helpers/logs.js'; /* c8 ignore next */ @@ -57,12 +57,12 @@ export async function describe( if (typeof cb !== 'function') return; - const start = process.hrtime(); + const start = hrtime(); const resultCb = cb(); /* c8 ignore next */ if (resultCb instanceof Promise) await resultCb; - const end = process.hrtime(start); + const end = hrtime(start); /* c8 ignore start */ if (title) { diff --git a/src/modules/it.ts b/src/modules/it.ts index 9ace47cd..9ab443ca 100644 --- a/src/modules/it.ts +++ b/src/modules/it.ts @@ -1,5 +1,5 @@ /* c8 ignore next */ -import process from 'node:process'; +import { hrtime } from 'node:process'; /* c8 ignore next */ import { each } from '../configs/each.js'; /* c8 ignore next */ @@ -46,12 +46,12 @@ export async function it( } /* c8 ignore end */ - const start = process.hrtime(); + const start = hrtime(); const resultCb = cb(); /* c8 ignore next */ if (resultCb instanceof Promise) await resultCb; - const end = process.hrtime(start); + const end = hrtime(start); if (typeof each.after.cb === 'function' && each.after.test) { const afterResult = each.after.cb(); diff --git a/src/modules/list-files-sync.ts b/src/modules/list-files-sync.ts index 9137fb18..791ab6c3 100644 --- a/src/modules/list-files-sync.ts +++ b/src/modules/list-files-sync.ts @@ -4,7 +4,7 @@ * This method will be removed in a future release to use `list-files.ts` instead. */ -import process from 'node:process'; +import { env } from 'node:process'; import { readdirSync, statSync } from 'node:fs'; import path from 'node:path'; import type { Configs } from '../@types/list-files.js'; @@ -12,8 +12,8 @@ import { escapeRegExp, sanitizePath } from './list-files.js'; const isDir = (fullPath: string) => statSync(fullPath).isDirectory(); -const envFilter = process.env.FILTER?.trim() - ? new RegExp(escapeRegExp(process.env.FILTER), 'i') +const envFilter = env.FILTER?.trim() + ? new RegExp(escapeRegExp(env.FILTER), 'i') : null; const listFiles = ( diff --git a/src/modules/list-files.ts b/src/modules/list-files.ts index 9409a67e..93398aeb 100644 --- a/src/modules/list-files.ts +++ b/src/modules/list-files.ts @@ -1,5 +1,5 @@ /* c8 ignore next */ -import process from 'node:process'; +import { env } from 'node:process'; import { sep, join } from 'node:path'; import { readdir, stat as fsStat } from '../polyfills/fs.js'; /* c8 ignore next */ @@ -28,8 +28,8 @@ export const escapeRegExp = (string: string) => /* c8 ignore stop */ /* c8 ignore start */ -const envFilter = process.env.FILTER?.trim() - ? new RegExp(escapeRegExp(process.env.FILTER), 'i') +const envFilter = env.FILTER?.trim() + ? new RegExp(escapeRegExp(env.FILTER), 'i') : undefined; /* c8 ignore stop */ diff --git a/src/modules/poku.ts b/src/modules/poku.ts index 1d4be1a3..99f498e3 100644 --- a/src/modules/poku.ts +++ b/src/modules/poku.ts @@ -5,7 +5,6 @@ */ import process from 'node:process'; -import { EOL } from 'node:os'; import { runTests, runTestsParallel } from '../services/run-tests.js'; import { exit } from './exit.js'; import { format } from '../helpers/format.js'; @@ -68,7 +67,7 @@ export async function poku( // Parallel if (showLogs) { hr(); - write(`${format.bold('Running the Test Suite in Parallel')}${EOL}`); + write(`${format.bold('Running the Test Suite in Parallel')}\n`); } try { @@ -100,7 +99,7 @@ export async function poku( ([file, time]) => `${indentation.test}${format.success('✔')} ${format.dim(`${file} › ${time}ms`)}` ) - .join(EOL) + .join('\n') ); } @@ -111,7 +110,7 @@ export async function poku( ([file, time]) => `${indentation.test}${format.fail('✘')} ${format.dim(`${file} › ${time}ms`)}` ) - .join(EOL) + .join('\n') ); } diff --git a/src/modules/test.ts b/src/modules/test.ts index f0d6c7a2..24986b5d 100644 --- a/src/modules/test.ts +++ b/src/modules/test.ts @@ -1,5 +1,5 @@ /* c8 ignore next */ -import process from 'node:process'; +import { hrtime } from 'node:process'; /* c8 ignore next */ import { each } from '../configs/each.js'; /* c8 ignore next */ @@ -45,12 +45,12 @@ export async function test( } /* c8 ignore stop */ - const start = process.hrtime(); + const start = hrtime(); const resultCb = cb(); /* c8 ignore next */ if (resultCb instanceof Promise) await resultCb; - const end = process.hrtime(start); + const end = hrtime(start); if (typeof each.after.cb === 'function' && each.after.test) { const afterResult = each.after.cb(); diff --git a/src/services/each.ts b/src/services/each.ts index 0d02794c..e2fe4701 100644 --- a/src/services/each.ts +++ b/src/services/each.ts @@ -1,4 +1,3 @@ -import { EOL } from 'node:os'; import { format } from '../helpers/format.js'; import { write } from '../helpers/logs.js'; /* c8 ignore next */ @@ -32,12 +31,12 @@ const eachCore = async ( ); write( format.fail( - ` ├─ Who's trying to run this ${type}?${EOL} │ └─ ${format.underline(fileRelative)}` + ` ├─ Who's trying to run this ${type}?\n │ └─ ${format.underline(fileRelative)}` ) ); error instanceof Error && - write(format.fail(` ├─ Message:${EOL} │ └─ ${error.message}`)); + write(format.fail(` ├─ Message:\n │ └─ ${error.message}`)); return false; } diff --git a/src/services/pid.ts b/src/services/pid.ts index 9f4ff67f..0898bd70 100644 --- a/src/services/pid.ts +++ b/src/services/pid.ts @@ -1,7 +1,6 @@ /* c8 ignore start */ import { spawn } from 'node:child_process'; -import { EOL } from 'node:os'; import { forceArray } from '../helpers/force-array.js'; export const setPortsAndPIDs = (portOrPID: number | number[]) => @@ -53,7 +52,7 @@ export const getPIDs = { ]); service.stdout.on('data', (data: Buffer) => { - const output = data.toString().trim().split(EOL); + const output = data.toString().trim().split('\n'); output.forEach((pid) => { if (pid) PIDs.add(Number(pid)); @@ -74,7 +73,7 @@ export const getPIDs = { service.stdout.on('data', (data: Buffer) => { const output = data.toString().trim(); - const lines = output.trim().split(EOL); + const lines = output.trim().split('\n'); /** * TODO: Chack line for "/:\d+\s+\w+\s+\d+\s+(\d+)/" regex match to safe support multiple Windows versions diff --git a/src/services/run-test-file.ts b/src/services/run-test-file.ts index f3c50e56..6fb53d5a 100644 --- a/src/services/run-test-file.ts +++ b/src/services/run-test-file.ts @@ -1,5 +1,5 @@ /* c8 ignore start */ // c8 bug -import process from 'node:process'; +import { cwd as processCWD, hrtime, env } from 'node:process'; import { relative } from 'node:path'; import { spawn } from 'node:child_process'; import { indentation } from '../configs/indentation.js'; @@ -11,7 +11,7 @@ import { beforeEach, afterEach } from './each.js'; /* c8 ignore next */ import type { Configs } from '../@types/poku.js'; -const cwd = process.cwd(); +const cwd = processCWD(); /* c8 ignore stop */ // c8 bug /* c8 ignore next */ // c8 bug @@ -49,8 +49,8 @@ export const runTestFile = ( ); } - const start = process.hrtime(); - let end: ReturnType; + const start = hrtime(); + let end: ReturnType; /* c8 ignore next */ if (!(await beforeEach(fileRelative, configs))) return false; @@ -61,7 +61,7 @@ export const runTestFile = ( /* c8 ignore next */ shell: isWindows, env: { - ...process.env, + ...env, FILE: configs?.parallel || configs?.deno?.cjs ? fileRelative : '', }, }); @@ -71,7 +71,7 @@ export const runTestFile = ( child.stderr.on('data', stdOut); child.on('close', async (code) => { - end = process.hrtime(start); + end = hrtime(start); const result = code === 0; @@ -95,7 +95,7 @@ export const runTestFile = ( /* c8 ignore start */ child.on('error', (err) => { - end = process.hrtime(start); + end = hrtime(start); const total = (end[0] * 1e3 + end[1] / 1e6).toFixed(6); diff --git a/src/services/run-tests.ts b/src/services/run-tests.ts index bffc22c7..a42380c5 100644 --- a/src/services/run-tests.ts +++ b/src/services/run-tests.ts @@ -1,5 +1,4 @@ -import process from 'node:process'; -import { EOL } from 'node:os'; +import { cwd as processCWD, hrtime } from 'node:process'; import { join, relative, sep } from 'node:path'; import { runner } from '../helpers/runner.js'; import { indentation } from '../configs/indentation.js'; @@ -15,7 +14,7 @@ import { isQuiet, write } from '../helpers/logs.js'; /* c8 ignore next */ import type { Configs } from '../@types/poku.js'; -const cwd = process.cwd(); +const cwd = processCWD(); /* c8 ignore start */ export const results = { @@ -42,7 +41,7 @@ export const runTests = async ( if (showLogs) { hr(); write( - `${format.bold(isFile ? 'File:' : 'Directory:')} ${format.underline(`.${sep}${currentDir}`)}${EOL}` + `${format.bold(isFile ? 'File:' : 'Directory:')} ${format.underline(`.${sep}${currentDir}`)}\n` ); } @@ -50,15 +49,15 @@ export const runTests = async ( const filePath = files[i]; const fileRelative = relative(cwd, filePath); - const start = process.hrtime(); + const start = hrtime(); const testPassed = await runTestFile(filePath, configs); - const end = process.hrtime(start); + const end = hrtime(start); const total = (end[0] * 1e3 + end[1] / 1e6).toFixed(6); const testNumber = i + 1; const counter = format.counter(testNumber, totalTests); const command = `${runner(fileRelative, configs).join(' ')} ${fileRelative} ${format.dim(`› ${total}ms`)}`; - const nextLine = i + 1 !== files.length ? EOL : ''; + const nextLine = i + 1 !== files.length ? '\n' : ''; const log = `${counter}/${totalTests} ${command} `; if (testPassed) { diff --git a/test/unit/assert-find-file.test.ts b/test/unit/assert-find-file.test.ts index eb2c0efc..9635d705 100644 --- a/test/unit/assert-find-file.test.ts +++ b/test/unit/assert-find-file.test.ts @@ -1,11 +1,6 @@ -import process from 'node:process'; import { test } from '../../src/modules/test.js'; import { assert } from '../../src/modules/assert.js'; import { findFile } from '../../src/helpers/find-file.js'; -import { isWindows } from '../../src/helpers/runner.js'; - -// TODO: Fix findFile fow Windows (sep) -if (isWindows) process.exit(0); const setStack = (stack: string): Error => { const error = new Error('Test error'); diff --git a/website/test/unit/check-extensions.test.ts b/website/test/unit/check-extensions.test.ts index 73ba30d9..af936cdf 100644 --- a/website/test/unit/check-extensions.test.ts +++ b/website/test/unit/check-extensions.test.ts @@ -1,4 +1,3 @@ -import { EOL } from 'node:os'; import { listFiles, assert } from 'poku'; const invalidFiles: string[] = []; @@ -17,7 +16,7 @@ const checkExtensions = ( files.forEach((file) => { if (!ignoreList.test(file) && !allowedExtensions.test(file)) { invalidFiles.push(file); - message.push(`${EOL}${String(allowedExtensions)}`); + message.push(`\n${String(allowedExtensions)}`); message.push(`- ${file}`); } }); @@ -33,5 +32,5 @@ checkExtensions(['src/css'], /\.scss$/); assert.deepStrictEqual( invalidFiles.length, 0, - Array.from(new Set(message)).join(EOL) + Array.from(new Set(message)).join('\n') );