diff --git a/.eslintrc.json b/.eslintrc.json index c8c67ee3..ba8240fa 100755 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -78,6 +78,12 @@ { "allow": ["arrowFunctions"] } ] } + }, + { + "files": ["src/polyfills/**"], + "rules": { + "@typescript-eslint/no-explicit-any": "off" + } } ], "settings": { diff --git a/.github/workflows/ci_lint.yml b/.github/workflows/ci_lint.yml index b06e8b49..474df9e2 100644 --- a/.github/workflows/ci_lint.yml +++ b/.github/workflows/ci_lint.yml @@ -33,8 +33,11 @@ jobs: - name: ๐Ÿ“ฆ Installing Dependencies run: npm ci + - name: ๐Ÿคน๐Ÿปโ€โ™€๏ธ Biome Check + run: npm run biome:check + - name: ๐Ÿคน๐Ÿปโ€โ™€๏ธ ESLint Check - run: npm run eslint:checker + run: npm run eslint:check - name: ๐Ÿคน๐Ÿปโ€โ™€๏ธ Prettier Check - run: npm run prettier:checker + run: npm run prettier:check diff --git a/.nycrc b/.nycrc index 86335595..49b06f22 100644 --- a/.nycrc +++ b/.nycrc @@ -6,6 +6,7 @@ "src/bin", "src/configs", "src/polyfills", + "src/index.ts", "benchmark", "ci", "fixtures", diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d5d31d97..7824b57b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -139,7 +139,7 @@ npm run test:ci ### Lint ```sh -npm run lint:checker +npm run lint:check ``` > Also diff --git a/biome.json b/biome.json index 59a2af71..0fbca6d8 100644 --- a/biome.json +++ b/biome.json @@ -1,6 +1,7 @@ { "$schema": "https://biomejs.dev/schemas/1.8.2/schema.json", "files": { + "include": ["**/**"], "ignore": [ "node_modules", "lib", @@ -43,7 +44,6 @@ }, "suspicious": { "all": true, - "noAsyncPromiseExecutor": "off", "noEmptyBlockStatements": "off", "noConsoleLog": "off" }, @@ -72,7 +72,7 @@ } }, { - "include": ["src/polyfills"], + "include": ["src/polyfills/**/**"], "linter": { "rules": { "suspicious": { diff --git a/package.json b/package.json index 7b7c1d04..290a266f 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "1.20.0", "description": "๐Ÿท Poku makes testing easy for Node.js, Bun, Deno, and you at the same time.", "license": "MIT", + "type": "commonjs", "main": "./lib/index.js", "bin": { "poku": "./lib/bin/index.js" @@ -47,11 +48,12 @@ "build": "tsc && tsc -p tsconfig.test.json", "postbuild": "tsx tools/compatibility/node.ts && shx cp fixtures/server/package.json ci/fixtures/server/package.json && npm run build:deno && shx chmod +x lib/bin/index.js", "build:deno": "esbuild src/polyfills/deno.mts --outfile=lib/polyfills/deno.mjs --format=esm", - "eslint:checker": "eslint . --ext .js,.ts", + "biome:check": "npx @biomejs/biome lint", + "eslint:check": "eslint . --ext .js,.ts", "eslint:fix": "eslint . --fix --config .eslintrc.json", - "lint:checker": "npm run eslint:checker && npm run prettier:checker", + "lint:check": "npm run biome:check && npm run eslint:check && npm run prettier:check", "lint:fix": "npm run eslint:fix && npm run prettier:fix", - "prettier:checker": "prettier --check .", + "prettier:check": "prettier --check .", "prettier:fix": "prettier --write .github/workflows/*.yml .", "update": "pu minor && npm i && npm audit fix", "postupdate": "npm run lint:fix", diff --git a/src/index.ts b/src/index.ts index 9a30d6c8..beb97b65 100755 --- a/src/index.ts +++ b/src/index.ts @@ -1,10 +1,5 @@ -/* c8 ignore start */ - -// Essentials export { poku } from './modules/poku.js'; export { assert } from './modules/assert.js'; - -// Helpers export { test } from './modules/test.js'; export { describe } from './modules/describe.js'; export { it } from './modules/it.js'; @@ -21,8 +16,6 @@ export { exit } from './modules/exit.js'; export { log } from './modules/log.js'; export { publicListFiles as listFiles } from './modules/list-files-sync.js'; export { assertPromise } from './modules/assert-promise.js'; - -// Types export type { Code } from './@types/code.js'; export type { Configs } from './@types/poku.js'; export type { @@ -38,5 +31,3 @@ export type { WaitForPortOptions, } from './@types/wait-for.js'; export type { Configs as ListFilesConfigs } from './@types/list-files.js'; - -/* c8 ignore stop */ diff --git a/src/polyfills/object.ts b/src/polyfills/object.ts index 9a39e3a6..49b2bdd9 100644 --- a/src/polyfills/object.ts +++ b/src/polyfills/object.ts @@ -1,4 +1,3 @@ -// eslint-disable-next-line @typescript-eslint/no-explicit-any export const entries = (obj: { [key: string]: any }): [string, unknown][] => { const ownProps = Object.keys(obj); let i = ownProps.length; diff --git a/src/services/run-test-file.ts b/src/services/run-test-file.ts index a783d3c9..69cb1e78 100644 --- a/src/services/run-test-file.ts +++ b/src/services/run-test-file.ts @@ -13,50 +13,49 @@ import { beforeEach, afterEach } from './each.js'; const cwd = processCWD(); /* c8 ignore next */ // c8 bug -export const runTestFile = ( +export const runTestFile = async ( filePath: string, configs?: Configs -): Promise => - new Promise(async (resolve) => { - /* c8 ignore start */ - const runtimeOptions = runner(filePath, configs); - const runtime = runtimeOptions.shift()!; - const runtimeArguments = [ - ...runtimeOptions, - configs?.deno?.cjs === true || - (Array.isArray(configs?.deno?.cjs) && - configs.deno.cjs.some((ext) => filePath.includes(ext))) - ? 'https://cdn.jsdelivr.net/npm/poku/lib/polyfills/deno.mjs' - : filePath, - ]; - /* c8 ignore stop */ - - const fileRelative = relative(cwd, filePath); - const showLogs = !isQuiet(configs); - - let output = ''; - - const stdOut = (data: Buffer): void => { - output += String(data); - }; - - if (!configs?.parallel) { - showLogs && - write( - `${indentation.test}${format('โ—').info().dim()} ${format(fileRelative).dim()}` - ); - } - - const start = hrtime(); - let end: ReturnType; - - /* c8 ignore start */ - if (!(await beforeEach(fileRelative, configs))) { - return false; - } - /* c8 ignore stop */ - - // Export spawn helper is not an option +): Promise => { + /* c8 ignore start */ // multi-platform + const runtimeOptions = runner(filePath, configs); + const runtime = runtimeOptions.shift()!; + const runtimeArguments = [ + ...runtimeOptions, + configs?.deno?.cjs === true || + (Array.isArray(configs?.deno?.cjs) && + configs.deno.cjs.some((ext) => filePath.includes(ext))) + ? 'https://cdn.jsdelivr.net/npm/poku/lib/polyfills/deno.mjs' + : filePath, + ]; + /* c8 ignore stop */ + + const fileRelative = relative(cwd, filePath); + const showLogs = !isQuiet(configs); + + let output = ''; + + const stdOut = (data: Buffer): void => { + output += String(data); + }; + + if (!configs?.parallel) { + showLogs && + write( + `${indentation.test}${format('โ—').info().dim()} ${format(fileRelative).dim()}` + ); + } + + const start = hrtime(); + let end: ReturnType; + + /* c8 ignore start */ + if (!(await beforeEach(fileRelative, configs))) { + return false; + } + /* c8 ignore stop */ + + return new Promise((resolve) => { const child = spawn(runtime, runtimeArguments, { stdio: ['inherit', 'pipe', 'pipe'], /* c8 ignore next */ @@ -68,7 +67,6 @@ export const runTestFile = ( }); child.stdout.on('data', stdOut); - child.stderr.on('data', stdOut); child.on('close', async (code) => { @@ -86,7 +84,8 @@ export const runTestFile = ( /* c8 ignore start */ if (!(await afterEach(fileRelative, configs))) { - return false; + resolve(false); + return; } /* c8 ignore stop */ @@ -114,3 +113,4 @@ export const runTestFile = ( }); /* c8 ignore stop */ }); +}; diff --git a/src/services/run-tests.ts b/src/services/run-tests.ts index fdc93966..34d8ef2f 100644 --- a/src/services/run-tests.ts +++ b/src/services/run-tests.ts @@ -1,4 +1,4 @@ -/* c8 ignore start */ // c8 bug (incompatibility) => +/* c8 ignore start */ // c8 bug (incompatibility) /** * This service is strictly tested, but these tests use deep child process for it */ diff --git a/tsconfig.json b/tsconfig.json index 4b792018..422d30d1 100755 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,8 +2,8 @@ "include": ["src"], "exclude": ["test", "tools", "src/@types"], "compilerOptions": { - "target": "ES2015", - "lib": ["ES2015"], + "target": "ES2016", + "lib": ["ES2016"], "module": "CommonJS", "moduleResolution": "Node", "outDir": "lib",