Skip to content

Commit

Permalink
chore: reduce polyfills (#470)
Browse files Browse the repository at this point in the history
  • Loading branch information
wellwelwel authored Jun 26, 2024
1 parent bc5a1f3 commit 6cc1c54
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 65 deletions.
6 changes: 6 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@
{ "allow": ["arrowFunctions"] }
]
}
},
{
"files": ["src/polyfills/**"],
"rules": {
"@typescript-eslint/no-explicit-any": "off"
}
}
],
"settings": {
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/ci_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions .nycrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"src/bin",
"src/configs",
"src/polyfills",
"src/index.ts",
"benchmark",
"ci",
"fixtures",
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ npm run test:ci
### Lint
```sh
npm run lint:checker
npm run lint:check
```
> Also
Expand Down
4 changes: 2 additions & 2 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.2/schema.json",
"files": {
"include": ["**/**"],
"ignore": [
"node_modules",
"lib",
Expand Down Expand Up @@ -43,7 +44,6 @@
},
"suspicious": {
"all": true,
"noAsyncPromiseExecutor": "off",
"noEmptyBlockStatements": "off",
"noConsoleLog": "off"
},
Expand Down Expand Up @@ -72,7 +72,7 @@
}
},
{
"include": ["src/polyfills"],
"include": ["src/polyfills/**/**"],
"linter": {
"rules": {
"suspicious": {
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down
9 changes: 0 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 {
Expand All @@ -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 */
1 change: 0 additions & 1 deletion src/polyfills/object.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
88 changes: 44 additions & 44 deletions src/services/run-test-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> =>
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<typeof hrtime>;

/* c8 ignore start */
if (!(await beforeEach(fileRelative, configs))) {
return false;
}
/* c8 ignore stop */

// Export spawn helper is not an option
): Promise<boolean> => {
/* 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<typeof hrtime>;

/* 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 */
Expand All @@ -68,7 +67,6 @@ export const runTestFile = (
});

child.stdout.on('data', stdOut);

child.stderr.on('data', stdOut);

child.on('close', async (code) => {
Expand All @@ -86,7 +84,8 @@ export const runTestFile = (

/* c8 ignore start */
if (!(await afterEach(fileRelative, configs))) {
return false;
resolve(false);
return;
}
/* c8 ignore stop */

Expand Down Expand Up @@ -114,3 +113,4 @@ export const runTestFile = (
});
/* c8 ignore stop */
});
};
2 changes: 1 addition & 1 deletion src/services/run-tests.ts
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 6cc1c54

Please sign in to comment.