Skip to content

Commit

Permalink
feat: support target file and directories (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
wellwelwel committed Feb 28, 2024
1 parent cc742fd commit 4353996
Show file tree
Hide file tree
Showing 16 changed files with 71 additions and 50 deletions.
42 changes: 29 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@ Enjoying **Poku**? Consider giving him a star ⭐️

---

🐷 [**Documentation Website**](https://poku.dev) • 🔬 [**Compare Poku with the Most Popular Test Runners**](https://poku.dev/docs/comparing)
🐷 [**Documentation Website**](https://poku.dev) • 🔬 [**Compare Poku with the Most Popular Test Runners**](https://poku.dev/docs/comparing) • 🧪 [**Examples**](https://poku.dev/docs/category/examples)

---

## Why Poku?

Don't worry about `describe`, `it`, `beforeEach` and everything else 🚀 <br/>
After all, you don't need to learn what you already know ([**see why**](https://poku.dev/docs/examples/beforeEach)) ✨
Let's make `describe`, `beforeEach` and everything else easier ([**see why and how**](https://poku.dev/docs/examples/beforeEach)) 🚀 <br/>

- Supports **ESM** and **CJS**
- Designed to be highly intuitive
Expand All @@ -65,6 +64,12 @@ After all, you don't need to learn what you already know ([**see why**](https://

---

## Examples

- See real example usages in [**Examples**](https://poku.dev/docs/category/examples) section for **Poku**'s + **Mock**, **Virutal DOM** and more.

---

## Overview

### `poku`
Expand Down Expand Up @@ -117,47 +122,58 @@ import { poku } from 'npm:poku';

## Quick Start

### CLI
### `poku`

#### CLI

> Try to set the flag `--parallel` before the target path 🚀
> <img src=".github/assets/readme/node-js.svg" width="24" />
```bash
npx poku targetDir
npx poku targetPath
npx poku targetPathA,targetPathB
```

> <img src=".github/assets/readme/bun.svg" width="24" />
```bash
bun poku targetDir
bun poku targetPath
bun poku targetPathA,targetPathB
```

> <img src=".github/assets/readme/deno.svg" width="24" />
```bash
deno run npm:poku targetDir
deno run npm:poku targetPath
deno run npm:poku targetPathA,targetPathB
```

### API (_In-code_)
#### API (_In-code_)

#### Node.js, TypeScript (Node.js) and Bun
##### Node.js, TypeScript (Node.js) and Bun

```ts
import { poku } from 'poku';

await poku(['targetDir']);
await poku(['targetPath']);
```

#### Deno
##### Deno

```ts
import { poku } from 'npm:poku';

await poku(['targetDir']);
await poku(['targetPath']);
```

### `assert`

Use it exactly as it's for **Node.js** 💚

---

To see the detailed documentation, please visit the [**Documentation**](https://poku.dev/docs/category/documentation) section in the [**Poku**'s website](https://poku.dev).
To see the detailed documentation, please visit the [**Documentation**](https://poku.dev/docs/category/documentation) and [**Examples**](https://poku.dev/docs/category/examples) sections in the [**Poku**'s website](https://poku.dev).

---

Expand Down
7 changes: 5 additions & 2 deletions src/modules/list-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export const sanitizePath = (input: string, ensureTarget?: boolean): string => {
export const escapeRegExp = (string: string) =>
string.replace(/[.*{}[\]\\]/g, '\\$&');

export const isFile = (fullPath: string) => fs.statSync(fullPath).isFile();

export const isDir = (fullPath: string) => fs.statSync(fullPath).isDirectory();

const envFilter = process.env.FILTER?.trim()
? new RegExp(escapeRegExp(process.env.FILTER), 'i')
: null;
Expand Down Expand Up @@ -46,8 +50,7 @@ export const listFiles = (
if (/node_modules/.test(fullPath)) continue;
if (exclude && exclude.some((regex) => regex.test(fullPath))) continue;

if (fs.statSync(fullPath).isDirectory())
listFiles(fullPath, files, configs);
if (isDir(fullPath)) listFiles(fullPath, files, configs);
else if (filter.test(fullPath)) files.push(fullPath);
}

Expand Down
8 changes: 4 additions & 4 deletions src/modules/poku.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ import { fileResults } from '../services/run-test-file.js';
import { indentation } from '../helpers/indentation.js';

export async function poku(
targetDirs: string | string[],
targetPaths: string | string[],
configs: Configs & { noExit: true }
): Promise<Code>;
export async function poku(
targetDirs: string | string[],
targetPaths: string | string[],
configs?: Configs
): Promise<void>;
export async function poku(
targetDirs: string | string[],
targetPaths: string | string[],
configs?: Configs
): Promise<Code | void> {
let code: Code = 0;

const prepareDirs = forceArray(targetDirs);
const prepareDirs = forceArray(targetPaths);
const dirs = prepareDirs.length > 0 ? prepareDirs : ['./'];
const showLogs = !isQuiet(configs);

Expand Down
6 changes: 3 additions & 3 deletions src/services/run-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { EOL } from 'node:os';
import path from 'node:path';
import { runner } from '../helpers/runner.js';
import { indentation } from '../helpers/indentation.js';
import { listFiles, sanitizePath } from '../modules/list-files.js';
import { isFile, listFiles, sanitizePath } from '../modules/list-files.js';
import { hr } from '../helpers/hr.js';
import { format } from '../helpers/format.js';
import { runTestFile } from './run-test-file.js';
Expand All @@ -22,7 +22,7 @@ export const runTests = async (
const cwd = process.cwd();
const testDir = path.join(cwd, sanitizePath(dir));
const currentDir = path.relative(cwd, testDir);
const files = listFiles(testDir, undefined, configs);
const files = isFile(dir) ? [dir] : listFiles(testDir, undefined, configs);
const totalTests = files.length;
const showLogs = !isQuiet(configs);

Expand Down Expand Up @@ -73,7 +73,7 @@ export const runTestsParallel = async (
): Promise<boolean> => {
const cwd = process.cwd();
const testDir = path.join(cwd, dir);
const files = listFiles(testDir, undefined, configs);
const files = isFile(dir) ? [dir] : listFiles(testDir, undefined, configs);

const promises = files.map(async (filePath) => {
const testPassed = await runTestFile(filePath, configs);
Expand Down
2 changes: 1 addition & 1 deletion website/docs/documentation/poku/configs/debug.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sidebar_position: 6

# `debug`

> `poku(targetDirs: string | string[], configs?: Configs)`
> `poku(targetPaths: string | string[], configs?: Configs)`
>
> `debug: boolean`
Expand Down
2 changes: 1 addition & 1 deletion website/docs/documentation/poku/configs/exclude.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sidebar_position: 4

# `exclude`

> `poku(targetDirs: string | string[], configs?: Configs)`
> `poku(targetPaths: string | string[], configs?: Configs)`
>
> `exclude: RegExp | RegExp[]`
Expand Down
2 changes: 1 addition & 1 deletion website/docs/documentation/poku/configs/filter.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sidebar_position: 2

# `filter`

> `poku(targetDirs: string | string[], configs?: Configs)`
> `poku(targetPaths: string | string[], configs?: Configs)`
>
> `filter: RegExp`
Expand Down
2 changes: 1 addition & 1 deletion website/docs/documentation/poku/configs/no-exit.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sidebar_position: 7

# `noExit`

> `poku(targetDirs: string | string[], configs?: Configs)`
> `poku(targetPaths: string | string[], configs?: Configs)`
>
> `noExit: boolean`
Expand Down
2 changes: 1 addition & 1 deletion website/docs/documentation/poku/configs/parallel.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sidebar_position: 1

# `parallel`

> `poku(targetDirs: string | string[], configs?: Configs)`
> `poku(targetPaths: string | string[], configs?: Configs)`
>
> `parallel: boolean`
Expand Down
2 changes: 1 addition & 1 deletion website/docs/documentation/poku/configs/platform.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sidebar_position: 3

# `platform`

> `poku(targetDirs: string | string[], configs?: Configs)`
> `poku(targetPaths: string | string[], configs?: Configs)`
>
> `platform: "node" | "bun" | "deno"`
Expand Down
2 changes: 1 addition & 1 deletion website/docs/documentation/poku/configs/quiet.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sidebar_position: 5

# `quiet`

> `poku(targetDirs: string | string[], configs?: Configs)`
> `poku(targetPaths: string | string[], configs?: Configs)`
>
> `quiet: boolean`
Expand Down
14 changes: 7 additions & 7 deletions website/docs/documentation/poku/include-files.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ sidebar_position: 1

# Include Directories

> `poku(targetDirs: string | string[])`
> `poku(targetPaths: string | string[])`
>
> By default, **Poku** searches for _`.test.`_ and `.spec.` files, but you can customize it using the [`filter`](/docs/documentation/poku/configs/filter) option.
## API (_in-code_)

```ts
poku('targetDir');
poku('targetePath');
```

```ts
poku(['targetDirA', 'targetDirB']);
poku(['targetePathA', 'targetePathB']);
```

```ts
Expand All @@ -29,11 +29,11 @@ By setting the directories as the **last argument**:
> _Since **1.3.0**_
```bash
npx poku targetDir
npx poku targetePath
```

```bash
npx poku targetDirA,targetDirB
npx poku targetePathA,targetePathB
```

```bash
Expand All @@ -44,11 +44,11 @@ npx poku
By using `--include` option, you can use it in any order:

```bash
npx poku --include='targetDir'
npx poku --include='targetePath'
```

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

```bash
Expand Down
4 changes: 2 additions & 2 deletions website/docs/examples/beforeEach.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ assert.strictEqual(0, failuresCode, 'Running Failures Integration Tests');
**Finally**

```bash
node ./test/run.test.js
npx poku test/run.test.js
```

> Or `npx tsx ./test/run.test.ts` for **TypeScript**.
> Or `npx poku test/run.test.ts` for **TypeScript**.
20 changes: 12 additions & 8 deletions website/docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,17 @@ Enjoying **Poku**? Consider giving him a star ⭐️
<div className='features black'>
<p>
<Success />
<span>You don't need to learn what you already know ✨</span>
<span>
Let's make `describe`, `beforeEach` and everything else easier ([**see why
and how**](/docs/examples/beforeEach)) 🚀
</span>
</p>
<p>
<Success />
<span>
Don't worry about `describe`, `it`, `beforeEach` and everything else
([**see why**](/docs/examples/beforeEach)) 🚀
**Poku** brings human-friendly testing and assertion to
[**Node.js**][node-version-url], [**Bun**][bun-version-url] &
[**Deno**][deno-version-url] at the same time ✨
</span>
</p>
</div>
Expand Down Expand Up @@ -125,7 +129,7 @@ import { poku } from 'https://esm.sh/poku';
```ts
import { poku } from 'poku';

await poku(['targetDir']);
await poku(['targetPath']);
```

</TabItem>
Expand All @@ -134,7 +138,7 @@ import { poku } from 'https://esm.sh/poku';
```ts
import { poku } from 'npm:poku';
await poku(['targetDir']);
await poku(['targetPath']);
```

</TabItem>
Expand All @@ -146,21 +150,21 @@ await poku(['targetDir']);
<TabItem default value='Node.js and TypeScript (Node.js)'>

```bash
npx poku targetDir
npx poku targetPath
```

</TabItem>
<TabItem value='Bun'>

```bash
bun poku targetDir
bun poku targetPath
```

</TabItem>
<TabItem value='Deno'>

```bash
deno run npm:poku targetDir
deno run npm:poku targetPath
```

**Poku** requires these permissions by default:
Expand Down
1 change: 0 additions & 1 deletion website/src/css/home.scss
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@
& > small {
width: 100%;
text-align: center;
hyphens: auto;
text-shadow: 1px 1px 1px #13152dab;
font-family: 'Montserrat', sans-serif;
font-size: 15px;
Expand Down
5 changes: 2 additions & 3 deletions website/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,8 @@ const Home = () => {
</div>
<footer>
<small>
<Silhouette width={13} /> Don't worry about{' '}
<code>describe</code>, <code>it</code>,{' '}
<code>beforeEach</code> and everything else 🚀
<Silhouette width={13} /> Let's make <code>describe</code>,{' '}
<code>beforeEach</code> and everything else easier 🚀
</small>
<div className='custom-code-block'>
npm i -D poku
Expand Down

0 comments on commit 4353996

Please sign in to comment.