Skip to content

Commit

Permalink
feat(CLI): flexible include (#12)
Browse files Browse the repository at this point in the history
* fix(CLI): more flexible RegExp

* feat(cli): flexible include
  • Loading branch information
wellwelwel authored Feb 18, 2024
1 parent d89c0c2 commit ec63f28
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 38 deletions.
Binary file added .github/assets/readme/parallel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file added .github/assets/readme/sequential.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
90 changes: 58 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,27 @@ A flexible and easy-to-use **Test Runner** for [Node.js][node-version-url], [Bun
- No need to compile **TypeScript**
- Compatible with **Coverage** tools
- Allows both **in-code** and **CLI** usage
- [**Node.js**][node-version-url], [**Bun**][bun-version-url] and [**Deno**][deno-version-url] compatibility
- Zero configurations, except you want
- No constraints or rules, code in your own signature style

---

- Totally **dependency-free**
- <img src="https://img.shields.io/bundlephobia/min/poku?label=Final%20Size">
- **Zero** external dependencies
- **Poku** dive to the deepest depths to find tests in the specified directories
- **Compatibility:** **Poku** is tested across all **Node 6+**, **Bun 0.5.3+** and **Deno 1.30+** versions
- **Poku** uses itself to test its own tests using `process.exit` at several depths on the same process node

---

```bash
npx poku --include='test/unit,test/integration'
```
| Sequential | Parallel |
| ------------------------------------------------------------ | ---------------------------------------------------------- |
| `npx poku test/unit,test/integration` | `npx poku --parallel test/unit,test/integration` |
| <img src=".github/assets/readme/sequential.png" width="360"> | <img src=".github/assets/readme/parallel.png" width="360"> |

<img src="./.github/assets/readme/screen-recording-2024-02-17-at-23.38.06.gif" width="360">
- By default, **Poku** searches for all _`.test.`_ files, but you can customize it using the option [`filter`](https://github.com/wellwelwel/poku#filter-rexexp).
- The same idea for [**Bun**][bun-version-url] and [**Deno**][deno-version-url] (see bellow).

---

Expand Down Expand Up @@ -113,35 +117,35 @@ import { poku } from 'npm:poku';
```ts
import { poku } from 'poku';

await poku(['./a', './b']);
await poku(['targetDirA', 'targetDirB']);
```

> <img src=".github/assets/readme/deno.svg" width="24" />
```ts
import { poku } from 'npm:poku';

await poku(['./a', './b']);
await poku(['targetDirA', 'targetDirB']);
```

### CLI

> <img src=".github/assets/readme/node-js.svg" width="24" />
```bash
npx poku --include='./a,./b'
npx poku targetDirA,targetDirB
```

> <img src=".github/assets/readme/bun.svg" width="24" />
```bash
bun poku --include='./a,./b'
bun poku targetDirA,targetDirB
```

> <img src=".github/assets/readme/deno.svg" width="24" />
```bash
deno run npm:poku --include='./a,./b'
deno run npm:poku targetDirA,targetDirB
```

---
Expand All @@ -156,20 +160,40 @@ deno run npm:poku --include='./a,./b'

#### Include directories

- **in-code**

```ts
poku('./targetDir');
poku('targetDir');
```

```ts
poku(['./targetDirA', './targetDirB']);
poku(['targetDirA', 'targetDirB']);
```

- **CLI**

By setting the directories as the last argument:

> _Since **1.3.0**_
```bash
npx poku --include='./targetDir'
npx poku targetDir
```

```bash
npx poku --include='./targetDirA,./targetDirB'
npx poku targetDirA,targetDirB
```

By using `--include` option:

> _Since **1.0.0**_
```bash
npx poku --include='targetDir'
```

```bash
npx poku --include='targetDirA,targetDirB'
```

---
Expand Down Expand Up @@ -211,7 +235,7 @@ poku(['...'], {
```bash
# Parallel mode

npx poku --include='...' --parallel
npx poku --parallel ./test
```

---
Expand Down Expand Up @@ -261,23 +285,25 @@ poku('...', {
```bash
# Normal

npx poku --include='...' --platform=node
bun poku --include='...' --platform=bun
deno poku --include='...' --platform=deno
npx poku --platform=node ./test
bun poku --platform=bun ./test
deno run npm:poku --platform=deno ./test
```

```bash
# Custom
# 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

npx poku --include='...' --platform=bun
bun poku --include='...' --platform=deno
deno run poku --include='...' --platform=node
# ...
```

---

#### `filter: RexExp`
#### `filter: RegExp`

By default, **Poku** searches for _`.test.`_ files, but you can customize it using the `filter` option.

Expand All @@ -303,7 +329,7 @@ poku(['...'], {
*/

poku(['...'], {
filter: /\.(m)?(j|t)?s$/,
filter: /\.(m)?(j|t)s$/,
// filter: /\.(js|ts|mjs|mts)$/,
});
```
Expand All @@ -313,19 +339,19 @@ poku(['...'], {
```bash
# Testing only a specific file

npx poku --include='...' --filter='some-file'
npx poku --filter='some-file' ./test
```

```bash
# Testing only a specific file

npx poku --include='...' --filter='some-file|other-file'
npx poku --filter='some-file|other-file' ./test
```

```bash
# Testing only paths that contains "unit"

npx poku --include='...' --filter='unit'
npx poku --filter='unit' ./test
```

- **Environment Variable**
Expand All @@ -335,24 +361,24 @@ npx poku --include='...' --filter='unit'
```bash
# Testing only a specific file

FILTER='some-file' npx poku --include='...'
FILTER='some-file' npx poku ./test
```

```bash
# Testing only a specific file

FILTER='some-file|other-file' npx poku --include='...'
FILTER='some-file|other-file' npx poku ./test
```

```bash
# Testing only paths that contains "unit"

FILTER='unit' npx poku --include='...'
FILTER='unit' npx poku ./test
```

---

#### `exclude: RexExp | RexExp[]`
#### `exclude: RegExp | RegExp[]`

> Exclude by path using Regex to match only the files that should be performed.
>
Expand Down Expand Up @@ -425,13 +451,13 @@ poku(['...'], {
```bash
# Excluding directories and files from tests

npx poku --include='...' --exclude='some-file-or-dir'
npx poku --exclude='some-file-or-dir' ./test
```

```bash
# Excluding directories and files from tests

npx poku --include='...' --exclude='some-file-or-dir|other-file-or-dir'
npx poku --exclude='some-file-or-dir|other-file-or-dir' ./test
```

---
Expand Down
16 changes: 13 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"update": "npx npu;",
"prebuild": "rm -rf ./lib ./ci",
"build": "npx tsc; npx tsc -p tsconfig.test.json",
"postbuild": "npx tsx ./tools/compatibility/node.ts; npm audit",
"postbuild": "npx tsx ./tools/compatibility/node.ts; chmod +x lib/bin/index.js; npm audit",
"eslint:checker": "npx eslint . --ext .js,.ts",
"eslint:fix": "npx eslint . --fix --config ./.eslintrc.json",
"prettier:checker": "npx prettier --check .",
Expand All @@ -27,9 +27,10 @@
"poku": "./lib/bin/index.js"
},
"keywords": [
"🐷",
"test",
"testing",
"runner",
"testing",
"run",
"isolate",
"isolation",
Expand All @@ -41,13 +42,22 @@
"unit",
"integration",
"typescript",
"tsx",
"filter",
"exclude",
"list",
"files",
"list-files",
"queue",
"queuing",
"nodejs",
"node",
"bun",
"deno"
"deno",
"cli",
"cli-app",
"easy",
"expect"
],
"author": "https://github.com/wellwelwel",
"bugs": {
Expand Down
7 changes: 5 additions & 2 deletions src/bin/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#! /usr/bin/env node

import { escapeRegExp } from '../modules/list-files.js';
import { getArg, hasArg } from '../helpers/get-arg.js';
import { getArg, getLastParam, hasArg } from '../helpers/get-arg.js';
import { poku } from '../index.js';
import { platformIsValid } from '../helpers/get-runtime.js';

const dirs = getArg('include')?.split(',') || [];
const dirs =
(hasArg('include')
? getArg('include')?.split(',')
: getLastParam()?.split(',')) || [];
const platform = getArg('platform');
const filter = getArg('filter');
const parallel = hasArg('parallel');
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/get-arg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ export const getArg = (arg: string): string | undefined => {

export const hasArg = (arg: string): boolean =>
args.some((a) => a.startsWith(`--${arg}`));

export const getLastParam = (): string => {
return args[args.length - 1];
};
2 changes: 1 addition & 1 deletion src/modules/list-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'node:path';
import type { Configs } from '../@types/list-files.js';

export const escapeRegExp = (string: string) =>
string.replace(/[.*+?^${}()[\]\\]/g, '\\$&');
string.replace(/[.*{}[\]\\]/g, '\\$&');

const envFilter = process.env.FILTER?.trim()
? new RegExp(escapeRegExp(process.env.FILTER), 'i')
Expand Down

0 comments on commit ec63f28

Please sign in to comment.