Skip to content

Commit

Permalink
feat: support for short and alternative flags (#568)
Browse files Browse the repository at this point in the history
* feat: support for short and alternative flags

* docs: add docs

* docs: add JSR faq

* chore: use short flags
  • Loading branch information
wellwelwel authored Jul 21, 2024
1 parent c7f8100 commit ee1800f
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 41 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ To see the detailed documentation, please visit the [**Documentation**](https://
- [Avoiding conflicts in environments with multiple platforms installed](https://poku.io/docs/tutorials/cross-platform#recommendations).
- [Properly running asynchronous tests on the same file](https://poku.io/docs/examples/promises).
- [Migrating from version **1.x** to version **2.x**](https://github.com/wellwelwel/poku/issues/533).
- [Using **Poku** with **Deno** and approaches to **JSR**](https://github.com/wellwelwel/poku/discussions/565).

---

Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
"test": "npm run test:parallel && npm run test:sequential",
"test:bun": "npm run test:bun:parallel && npm run test:bun:sequential",
"test:deno": "npm run test:deno:parallel && npm run test:deno:sequential",
"test:sequential": "tsx src/bin/index.ts --include=test/unit,test/integration,test/e2e",
"test:parallel": "tsx src/bin/index.ts --parallel --include=test/unit,test/integration,test/e2e",
"test:bun:sequential": "bun src/bin/index.ts --platform=bun --include=test/unit,test/integration,test/e2e",
"test:bun:parallel": "bun src/bin/index.ts --platform=bun --parallel --include=test/unit,test/integration,test/e2e",
"test:deno:sequential": "tsx src/bin/index.ts --platform=deno --deno-allow=all --deno-cjs --include=ci/test/unit,ci/test/integration,ci/test/e2e",
"test:deno:parallel": "tsx src/bin/index.ts --platform=deno --deno-allow=all --deno-cjs --parallel --include=ci/test/unit,ci/test/integration,ci/test/e2e",
"test:sequential": "tsx src/bin/index.ts test/unit test/integration test/e2e",
"test:parallel": "tsx src/bin/index.ts -p test/unit test/integration test/e2e",
"test:bun:sequential": "bun src/bin/index.ts --bun test/unit test/integration test/e2e",
"test:bun:parallel": "bun src/bin/index.ts --bun -p test/unit test/integration test/e2e",
"test:deno:sequential": "tsx src/bin/index.ts --deno --deno-allow=all --deno-cjs ci/test/unit ci/test/integration ci/test/e2e",
"test:deno:parallel": "tsx src/bin/index.ts --deno --deno-allow=all --deno-cjs -p ci/test/unit ci/test/integration ci/test/e2e",
"test:c8": "c8 tsx test/c8.test.ts",
"test:ci": "tsx test/ci.test.ts",
"test:ci:node": "FILTER='node-' npm run test:ci",
Expand Down
27 changes: 17 additions & 10 deletions src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ import { Write } from '../services/write.js';
import { getConfigs } from '../parsers/options.js';

(async () => {
const configFile = getArg('config');
const configFile = getArg('config') || getArg('c', '-');
const defaultConfigs = await getConfigs(configFile);

const dirs: string[] = (() => {
const includeArg = getArg('include');
const includeArg = getArg('include'); // deprecated
if (includeArg !== undefined) {
return includeArg.split(',');
}

return (
getPaths() ??
getPaths('-') ??
(defaultConfigs?.include
? Array.prototype.concat(defaultConfigs?.include)
: ['.'])
Expand All @@ -47,11 +47,12 @@ import { getConfigs } from '../parsers/options.js';
.filter((a) => a) ||
hasArg('deno-cjs') ||
defaultConfigs?.deno?.cjs;
const parallel = hasArg('parallel') || defaultConfigs?.parallel;
const quiet = hasArg('quiet') || defaultConfigs?.quiet;
const debug = hasArg('debug') || defaultConfigs?.debug;
const parallel =
hasArg('parallel') || hasArg('p', '-') || defaultConfigs?.parallel;
const quiet = hasArg('quiet') || hasArg('q', '-') || defaultConfigs?.quiet;
const debug = hasArg('debug') || hasArg('d', '-') || defaultConfigs?.debug;
const failFast = hasArg('fail-fast') || defaultConfigs?.failFast;
const watchMode = hasArg('watch');
const watchMode = hasArg('watch') || hasArg('w', '-');
const hasEnvFile = hasArg('env-file');
const concurrency = (() => {
if (!(parallel || defaultConfigs?.parallel)) {
Expand Down Expand Up @@ -101,9 +102,15 @@ import { getConfigs } from '../parsers/options.js';
const options: Configs = {
platform: platformIsValid(platform)
? platform
: platformIsValid(defaultConfigs?.platform)
? defaultConfigs?.platform
: undefined,
: hasArg('node')
? 'node'
: hasArg('bun')
? 'bun'
: hasArg('deno')
? 'deno'
: platformIsValid(defaultConfigs?.platform)
? defaultConfigs?.platform
: undefined,
filter:
typeof filter === 'string' ? new RegExp(escapeRegExp(filter)) : filter,
exclude:
Expand Down
45 changes: 41 additions & 4 deletions website/docs/documentation/poku/config-files.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,22 @@ By default, **Poku** comes with the most common usage pre-set, but you can confi

<History
records={[
{
version: '2.2.0',
changes: [
<>
Support for <code>-c</code> short flag.
</>,
],
},
{
version: '2.1.0',
changes: [
<>
support for config files (<code>js</code> and <code>cjs</code>)
Support for config files (<code>js</code> and <code>cjs</code>).
</>,
<>
support for config files (<code>json</code> and <code>jsonc</code>)
Support for config files (<code>json</code> and <code>jsonc</code>).
</>,
],
},
Expand All @@ -27,9 +35,21 @@ By default, **Poku** comes with the most common usage pre-set, but you can confi

## JavaScript

<Stability level={2} message={'Recommended: supports functions and regex.'} />
<Stability
level={2}
message={
<>
<div>
<strong>Pos:</strong> Supports functions and regex.
</div>
<div>
<strong>Cons:</strong> Needs to be an CommonJS file.
</div>
</>
}
/>

Create a `poku.js` (or `poku.cjs` when using `"type": "module"` in your _package.json_) in your project's root directory, for example:
Create a `poku.config.js` (or `poku.config.cjs` when using `"type": "module"` in your _package.json_) in your project's root directory, for example:

```js
const { defineConfig } = require('poku');
Expand Down Expand Up @@ -67,6 +87,21 @@ module.exports = defineConfig({

## JSON and JSONC

<Stability
level={2}
message={
<>
<div>
<strong>Pos:</strong> Universal file for both CommonJS, ES Modules and
TypeScript.
</div>
<div>
<strong>Cons:</strong> Doesn't support functions and regex.
</div>
</>
}
/>

Create a `poku.json` (or `poku.jsonc`) in your project's root directory, for example:

```js
Expand Down Expand Up @@ -145,3 +180,5 @@ npx poku --config='my-file.jsonc'
```sh
npx poku --config='my-file'
```

- Short flag: `-c`.
6 changes: 3 additions & 3 deletions website/docs/documentation/poku/include-files.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { Stability } from '@site/src/components/Stability';

By default, **Poku** searches for _`.test.`_ and `.spec.` files, but you can customize it using the [`filter`](/docs/documentation/poku/options/filter) option.

## CLI

<History
records={[
{
Expand All @@ -29,6 +27,8 @@ By default, **Poku** searches for _`.test.`_ and `.spec.` files, but you can cus
]}
/>

## CLI

### Common usage

```bash
Expand Down Expand Up @@ -72,7 +72,7 @@ npx poku targetPathA targetPathB
<Stability
level={0}
message={
"It's now possible to pass multiple paths in any order since v2.1.0."
"It's now possible to pass multiple paths in any position since v2.1.0."
}
/>

Expand Down
19 changes: 18 additions & 1 deletion website/docs/documentation/poku/options/debug.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,33 @@
sidebar_position: 6
---

import { History } from '@site/src/components/History';

# `debug`

By default **Poku** doesn't shows logs that doesn't comes from **Poku**'s **`assert`**, but you can enable them:
By default **Poku** doesn't shows logs that doesn't comes from **Poku**'s **`assert`**, but you can enable them.

<History
records={[
{
version: '2.2.0',
changes: [
<>
Support for <code>-d</code> short flag.
</>,
],
},
]}
/>

## CLI

```bash
npx poku --debug ./test
```

- Short flag: `-d`.

## API

```ts
Expand Down
17 changes: 17 additions & 0 deletions website/docs/documentation/poku/options/parallel.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,25 @@
sidebar_position: 1
---

import { History } from '@site/src/components/History';

# `parallel`

Run the tests files in parallel.

<History
records={[
{
version: '2.2.0',
changes: [
<>
Support for <code>-p</code> short flag.
</>,
],
},
]}
/>

## CLI

```bash
Expand All @@ -14,6 +29,8 @@ Run the tests files in parallel.
npx poku --parallel ./test
```

- Short flag: `-p`.

## API

```ts
Expand Down
21 changes: 20 additions & 1 deletion website/docs/documentation/poku/options/platform.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,25 @@ sidebar_position: 3
tags: [require, import, loader]
---

import { History } from '@site/src/components/History';

# `platform`

By default, **Poku** tries to identify the platform automatically, but you can set it manually:
By default, **Poku** tries to identify the platform automatically, but you can set it manually.

<History
records={[
{
version: '2.2.0',
changes: [
<>
Support for <code>--node</code>, <code>--bun</code>, and{' '}
<code>--deno</code> alternative flags.
</>,
],
},
]}
/>

## CLI

Expand All @@ -28,6 +44,9 @@ deno run npm:poku --platform=node ./test
# ...
```

- Alternative flags: `--node`, `--bun`, and `--deno`.
- It's only possible to use one per command.

## API

```ts
Expand Down
17 changes: 17 additions & 0 deletions website/docs/documentation/poku/options/quiet.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,34 @@
sidebar_position: 5
---

import { History } from '@site/src/components/History';

# `quiet`

Perform tests with no logs. <br />
This option overwrites all `log` settings by exiting with code and no logs (see bellow).

<History
records={[
{
version: '2.2.0',
changes: [
<>
Support for <code>-q</code> short flag.
</>,
],
},
]}
/>

## CLI

```bash
npx poku --quiet ./test
```

- Short flag: `-q`.

## API

```ts
Expand Down
17 changes: 17 additions & 0 deletions website/docs/documentation/poku/options/watch.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,25 @@
sidebar_position: 9
---

import { History } from '@site/src/components/History';

# `watch`

Watches the events on tests and files that contains tests (after running all the tests), re-running the tests files that are updated for each new event.

<History
records={[
{
version: '2.2.0',
changes: [
<>
Support for <code>-w</code> short flag.
</>,
],
},
]}
/>

## CLI

```bash
Expand All @@ -20,6 +35,8 @@ You can use the flag `--watch-interval` to set a custom interval for `watch` eve
npx poku --watch --watch-interval=1500
```

- Short flag: `-w`.

<hr />

:::tip
Expand Down
Loading

0 comments on commit ee1800f

Please sign in to comment.