poku 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +46 -0
- package/lib/@types/code.d.ts +1 -0
- package/lib/@types/code.js +2 -0
- package/lib/@types/poku.d.ts +36 -0
- package/lib/@types/poku.js +2 -0
- package/lib/helpers/escape-reg-exp.d.ts +1 -0
- package/lib/helpers/escape-reg-exp.js +5 -0
- package/lib/helpers/filter.d.ts +1 -0
- package/lib/helpers/filter.js +8 -0
- package/lib/helpers/force-array.d.ts +1 -0
- package/lib/helpers/force-array.js +9 -0
- package/lib/helpers/format.d.ts +8 -0
- package/lib/helpers/format.js +15 -0
- package/lib/helpers/getFiles.d.ts +2 -0
- package/lib/helpers/getFiles.js +24 -0
- package/lib/helpers/hr.d.ts +1 -0
- package/lib/helpers/hr.js +10 -0
- package/lib/helpers/indentation.d.ts +4 -0
- package/lib/helpers/indentation.js +7 -0
- package/lib/helpers/logs.d.ts +4 -0
- package/lib/helpers/logs.js +9 -0
- package/lib/helpers/pad.d.ts +4 -0
- package/lib/helpers/pad.js +16 -0
- package/lib/helpers/runner.d.ts +1 -0
- package/lib/helpers/runner.js +9 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +7 -0
- package/lib/modules/exit.d.ts +2 -0
- package/lib/modules/exit.js +27 -0
- package/lib/modules/poku.d.ts +6 -0
- package/lib/modules/poku.js +44 -0
- package/lib/services/runTestFile.d.ts +2 -0
- package/lib/services/runTestFile.js +43 -0
- package/lib/services/runTests.d.ts +3 -0
- package/lib/services/runTests.js +85 -0
- package/lib/src/@types/code.d.ts +1 -0
- package/lib/src/@types/poku.d.ts +36 -0
- package/lib/src/helpers/escape-reg-exp.d.ts +1 -0
- package/lib/src/helpers/filter.d.ts +1 -0
- package/lib/src/helpers/force-array.d.ts +1 -0
- package/lib/src/helpers/format.d.ts +8 -0
- package/lib/src/helpers/getFiles.d.ts +2 -0
- package/lib/src/helpers/hr.d.ts +1 -0
- package/lib/src/helpers/indentation.d.ts +4 -0
- package/lib/src/helpers/logs.d.ts +4 -0
- package/lib/src/helpers/pad.d.ts +4 -0
- package/lib/src/helpers/runner.d.ts +1 -0
- package/lib/src/index.d.ts +2 -0
- package/lib/src/modules/exit.d.ts +2 -0
- package/lib/src/modules/poku.d.ts +6 -0
- package/lib/src/services/runTestFile.d.ts +2 -0
- package/lib/src/services/runTests.d.ts +3 -0
- package/lib/test/ci.test.d.ts +1 -0
- package/lib/test/compatibility/node-06.test.d.ts +1 -0
- package/lib/test/compatibility/node-07.test.d.ts +1 -0
- package/lib/test/compatibility/node-08.test.d.ts +1 -0
- package/lib/test/compatibility/node-09.test.d.ts +1 -0
- package/lib/test/compatibility/node-10.test.d.ts +1 -0
- package/lib/test/compatibility/node-11.test.d.ts +1 -0
- package/lib/test/compatibility/node-12.test.d.ts +1 -0
- package/lib/test/compatibility/node-13.test.d.ts +1 -0
- package/lib/test/compatibility/node-14.test.d.ts +1 -0
- package/lib/test/compatibility/node-15.test.d.ts +1 -0
- package/lib/test/compatibility/node-16.test.d.ts +1 -0
- package/lib/test/compatibility/node-17.test.d.ts +1 -0
- package/lib/test/compatibility/node-18.test.d.ts +1 -0
- package/lib/test/compatibility/node-19.test.d.ts +1 -0
- package/lib/test/compatibility/node-20.test.d.ts +1 -0
- package/lib/test/compatibility/node-21.test.d.ts +1 -0
- package/lib/test/fixtures/fail/exit.test.d.ts +0 -0
- package/lib/test/fixtures/success/exit.test.d.ts +0 -0
- package/lib/test/helpers/check-node.test.d.ts +1 -0
- package/lib/test/integration/code.test.d.ts +1 -0
- package/lib/test/integration/import.test.d.ts +1 -0
- package/lib/test/run.test.d.ts +1 -0
- package/lib/test/unit/pad.test.d.ts +1 -0
- package/lib/test/unit/runTestFile.test.d.ts +1 -0
- package/lib/test/unit/runTests.test.d.ts +1 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-current Weslley Araújo (@wellwelwel)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Poku
|
|
2
|
+
|
|
3
|
+
<img align="right" width="128" height="128" alt="Logo" src=".github/assets/readme/poku.svg">
|
|
4
|
+
|
|
5
|
+
🖇️ A flexible and user-friendly **Test Runner** which allows parallel runs and high isolation level.
|
|
6
|
+
|
|
7
|
+
> - **Poku** is designed to be highly intuitive.<br />
|
|
8
|
+
> - Compatible with **ESM** and **CJS**, **Node.js** and **TypeScript** (_no-build_).<br />
|
|
9
|
+
> - From **Node.js 6** to the **Latest** release.<br />
|
|
10
|
+
> - Totally dependency-free.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## In progress
|
|
15
|
+
|
|
16
|
+
🧑🏻🔧 Soon releasing version `1.x`.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install --save-dev poku
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { poku } from 'poku';
|
|
32
|
+
|
|
33
|
+
await poku(['./test/unit/']);
|
|
34
|
+
|
|
35
|
+
// 🧑🏻🔧 Soon documenting all options and Poku's usage variations.
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## TypeScript
|
|
41
|
+
|
|
42
|
+
To run your tests without compile, just install `tsx` and it's done:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npm install --save-dev tsx
|
|
46
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Code = 0 | 1;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export type Configs = {
|
|
2
|
+
/**
|
|
3
|
+
* By setting `true`, **Poku** won't exit the process and will return the exit code (`0` or `1`).
|
|
4
|
+
*
|
|
5
|
+
* You can combine this option with **Poku**'s `exit` method or just use the result, for example, in `process.exit(code)`.
|
|
6
|
+
*
|
|
7
|
+
* @default false
|
|
8
|
+
*/
|
|
9
|
+
noExit?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Customize `stdout` options.
|
|
12
|
+
*/
|
|
13
|
+
log?: {
|
|
14
|
+
/**
|
|
15
|
+
* @default false
|
|
16
|
+
*/
|
|
17
|
+
success?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* @default true
|
|
20
|
+
*/
|
|
21
|
+
fail?: boolean;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* This option overwrites all `log` settings
|
|
25
|
+
*
|
|
26
|
+
* @default false
|
|
27
|
+
*/
|
|
28
|
+
quiet?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Filter by path to match only the files that should be performed
|
|
31
|
+
*
|
|
32
|
+
* @default /\.test\./i
|
|
33
|
+
*/
|
|
34
|
+
filter?: RegExp;
|
|
35
|
+
parallel?: boolean;
|
|
36
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const escapeRegExp: (string: string) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const filter: RegExp | null;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.filter = void 0;
|
|
5
|
+
const escape_reg_exp_js_1 = require("./escape-reg-exp.js");
|
|
6
|
+
exports.filter = ((_a = process.env.FILTER) === null || _a === void 0 ? void 0 : _a.trim())
|
|
7
|
+
? new RegExp((0, escape_reg_exp_js_1.escapeRegExp)(process.env.FILTER), 'i')
|
|
8
|
+
: null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const forceArray: <T>(input: T | T[]) => T[];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const format: {
|
|
2
|
+
counter: (current: number, total: number, pad?: string) => string;
|
|
3
|
+
bold: (value: string) => string;
|
|
4
|
+
underline: (value: string) => string;
|
|
5
|
+
info: (value: string) => string;
|
|
6
|
+
success: (value: string) => string;
|
|
7
|
+
fail: (value: string) => string;
|
|
8
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.format = void 0;
|
|
4
|
+
const pad_js_1 = require("./pad.js");
|
|
5
|
+
exports.format = {
|
|
6
|
+
counter: (current, total, pad = '0') => {
|
|
7
|
+
const totalDigits = String(total).length;
|
|
8
|
+
return (0, pad_js_1.padStart)(String(current), totalDigits, pad);
|
|
9
|
+
},
|
|
10
|
+
bold: (value) => `\x1b[1m${value}\x1b[0m`,
|
|
11
|
+
underline: (value) => `\x1b[4m${value}\x1b[0m`,
|
|
12
|
+
info: (value) => `\x1b[36m${value}\x1b[0m`,
|
|
13
|
+
success: (value) => `\x1b[32m${value}\x1b[0m`,
|
|
14
|
+
fail: (value) => `\x1b[31m${value}\x1b[0m`,
|
|
15
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getFiles = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const filter_js_1 = require("./filter.js");
|
|
10
|
+
const getFiles = (dirPath, files = [], configs) => {
|
|
11
|
+
const currentFiles = fs_1.default.readdirSync(dirPath);
|
|
12
|
+
const filter = (filter_js_1.filter ? filter_js_1.filter : configs === null || configs === void 0 ? void 0 : configs.filter) || /\.test\./i;
|
|
13
|
+
for (const file of currentFiles) {
|
|
14
|
+
const fullPath = path_1.default.join(dirPath, file);
|
|
15
|
+
if (fs_1.default.statSync(fullPath).isDirectory()) {
|
|
16
|
+
(0, exports.getFiles)(fullPath, files, configs);
|
|
17
|
+
}
|
|
18
|
+
else if (filter.test(fullPath)) {
|
|
19
|
+
files.push(fullPath);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return files;
|
|
23
|
+
};
|
|
24
|
+
exports.getFiles = getFiles;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const hr: () => void;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hr = void 0;
|
|
4
|
+
const os_1 = require("os");
|
|
5
|
+
const hr = () => {
|
|
6
|
+
const columns = process.stdout.columns;
|
|
7
|
+
const line = '_'.repeat(columns - 10 || 0);
|
|
8
|
+
console.log(`\x1b[2m${line}\x1b[0m${os_1.EOL}`);
|
|
9
|
+
};
|
|
10
|
+
exports.hr = hr;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.showFailures = exports.showSuccesses = exports.isQuiet = void 0;
|
|
4
|
+
const isQuiet = (configs) => typeof (configs === null || configs === void 0 ? void 0 : configs.quiet) === 'boolean' && Boolean(configs === null || configs === void 0 ? void 0 : configs.quiet);
|
|
5
|
+
exports.isQuiet = isQuiet;
|
|
6
|
+
const showSuccesses = (configs) => { var _a; return Boolean((_a = configs === null || configs === void 0 ? void 0 : configs.log) === null || _a === void 0 ? void 0 : _a.success); };
|
|
7
|
+
exports.showSuccesses = showSuccesses;
|
|
8
|
+
const showFailures = (configs) => { var _a, _b; return typeof ((_a = configs === null || configs === void 0 ? void 0 : configs.log) === null || _a === void 0 ? void 0 : _a.fail) === 'undefined' || Boolean((_b = configs === null || configs === void 0 ? void 0 : configs.log) === null || _b === void 0 ? void 0 : _b.fail); };
|
|
9
|
+
exports.showFailures = showFailures;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Custom implementations of `padStart` for compatibility with Node.js version 6.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.padStart = void 0;
|
|
7
|
+
const padStart = (str, targetLength, padString) => {
|
|
8
|
+
padString = !padString ? ' ' : String(padString);
|
|
9
|
+
if (str.length >= targetLength)
|
|
10
|
+
return str;
|
|
11
|
+
const paddingLength = targetLength - str.length;
|
|
12
|
+
let fullPadString = padString.repeat(Math.ceil(paddingLength / padString.length));
|
|
13
|
+
fullPadString = fullPadString.slice(0, paddingLength);
|
|
14
|
+
return fullPadString + str;
|
|
15
|
+
};
|
|
16
|
+
exports.padStart = padStart;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const runner: (filename: string) => "tsx" | "node";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.runner = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const runner = (filename) => path_1.default.extname(filename) === '.ts' ? 'tsx' : 'node';
|
|
9
|
+
exports.runner = runner;
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.exit = exports.poku = void 0;
|
|
4
|
+
var poku_js_1 = require("./modules/poku.js");
|
|
5
|
+
Object.defineProperty(exports, "poku", { enumerable: true, get: function () { return poku_js_1.poku; } });
|
|
6
|
+
var exit_js_1 = require("./modules/exit.js");
|
|
7
|
+
Object.defineProperty(exports, "exit", { enumerable: true, get: function () { return exit_js_1.exit; } });
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.exit = void 0;
|
|
4
|
+
const hr_js_1 = require("../helpers/hr.js");
|
|
5
|
+
const exit = (code, quiet) => {
|
|
6
|
+
!quiet &&
|
|
7
|
+
process.on('exit', (code) => {
|
|
8
|
+
console.log(`About to exit with code`, code);
|
|
9
|
+
});
|
|
10
|
+
!quiet && (0, hr_js_1.hr)();
|
|
11
|
+
if (code !== 0) {
|
|
12
|
+
!quiet && console.log('Some tests failed.');
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
!quiet && console.log('All tests passed.');
|
|
16
|
+
process.exit(0);
|
|
17
|
+
};
|
|
18
|
+
exports.exit = exit;
|
|
19
|
+
process.stdout.on('resize', hr_js_1.hr);
|
|
20
|
+
process.on('unhandledRejection', (reason) => {
|
|
21
|
+
console.log('unhandledRejection', reason);
|
|
22
|
+
process.exit(1);
|
|
23
|
+
});
|
|
24
|
+
process.on('uncaughtException', (err) => {
|
|
25
|
+
console.log('uncaughtException', err);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Code } from '../@types/code.js';
|
|
2
|
+
import { Configs } from '../@types/poku.js';
|
|
3
|
+
export declare function poku(targetDirs: string | string[], configs?: Configs): Promise<void>;
|
|
4
|
+
export declare function poku(targetDirs: string | string[], configs: Configs & {
|
|
5
|
+
noExit: true;
|
|
6
|
+
}): Promise<Code>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.poku = void 0;
|
|
13
|
+
const force_array_js_1 = require("../helpers/force-array.js");
|
|
14
|
+
const runTests_js_1 = require("../services/runTests.js");
|
|
15
|
+
const exit_js_1 = require("./exit.js");
|
|
16
|
+
function poku(targetDirs, configs) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
let code = 0;
|
|
19
|
+
const dirs = (0, force_array_js_1.forceArray)(targetDirs);
|
|
20
|
+
if (configs === null || configs === void 0 ? void 0 : configs.parallel) {
|
|
21
|
+
for (const dir of dirs) {
|
|
22
|
+
(0, runTests_js_1.runTestsParallel)(dir, configs).then((result) => {
|
|
23
|
+
if (!result)
|
|
24
|
+
code = 1;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
process.on('beforeExit', () => {
|
|
28
|
+
if (configs === null || configs === void 0 ? void 0 : configs.noExit)
|
|
29
|
+
return code;
|
|
30
|
+
(0, exit_js_1.exit)(code, configs === null || configs === void 0 ? void 0 : configs.quiet);
|
|
31
|
+
});
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
for (const dir of dirs) {
|
|
35
|
+
const result = yield (0, runTests_js_1.runTests)(dir, configs);
|
|
36
|
+
if (!result)
|
|
37
|
+
code = 1;
|
|
38
|
+
}
|
|
39
|
+
if (configs === null || configs === void 0 ? void 0 : configs.noExit)
|
|
40
|
+
return code;
|
|
41
|
+
(0, exit_js_1.exit)(code, configs === null || configs === void 0 ? void 0 : configs.quiet);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
exports.poku = poku;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.runTestFile = void 0;
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const runner_js_1 = require("../helpers/runner.js");
|
|
10
|
+
const indentation_js_1 = require("../helpers/indentation.js");
|
|
11
|
+
const format_js_1 = require("../helpers/format.js");
|
|
12
|
+
const logs_js_1 = require("../helpers/logs.js");
|
|
13
|
+
const runTestFile = (filePath, configs) => new Promise((resolve) => {
|
|
14
|
+
let output = '';
|
|
15
|
+
const showLogs = !(0, logs_js_1.isQuiet)(configs);
|
|
16
|
+
const showSuccess = (0, logs_js_1.showSuccesses)(configs);
|
|
17
|
+
const showFailure = (0, logs_js_1.showFailures)(configs);
|
|
18
|
+
const log = () => console.log(`${indentation_js_1.indentation.stdio}${output === null || output === void 0 ? void 0 : output.trim()}`);
|
|
19
|
+
const fileRelative = path_1.default.relative(process.cwd(), filePath);
|
|
20
|
+
showLogs &&
|
|
21
|
+
console.log(`${indentation_js_1.indentation.test}${format_js_1.format.info('→')} ${fileRelative}`);
|
|
22
|
+
const child = (0, child_process_1.spawn)((0, runner_js_1.runner)(filePath), [filePath], {
|
|
23
|
+
stdio: ['inherit', 'pipe', 'pipe'],
|
|
24
|
+
env: process.env,
|
|
25
|
+
});
|
|
26
|
+
child.stdout.on('data', (data) => {
|
|
27
|
+
output += data.toString();
|
|
28
|
+
});
|
|
29
|
+
child.stderr.on('data', (data) => {
|
|
30
|
+
output += data.toString();
|
|
31
|
+
});
|
|
32
|
+
child.on('close', (code) => {
|
|
33
|
+
if (showLogs &&
|
|
34
|
+
((code === 0 && showSuccess) || (code !== 0 && showFailure)))
|
|
35
|
+
log();
|
|
36
|
+
resolve(code === 0);
|
|
37
|
+
});
|
|
38
|
+
child.on('error', (err) => {
|
|
39
|
+
console.log(`Failed to start test: ${filePath}`, err);
|
|
40
|
+
resolve(false);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
exports.runTestFile = runTestFile;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.runTestsParallel = exports.runTests = void 0;
|
|
16
|
+
const path_1 = __importDefault(require("path"));
|
|
17
|
+
const os_1 = require("os");
|
|
18
|
+
const runner_js_1 = require("../helpers/runner.js");
|
|
19
|
+
const indentation_js_1 = require("../helpers/indentation.js");
|
|
20
|
+
const getFiles_js_1 = require("../helpers/getFiles.js");
|
|
21
|
+
const hr_js_1 = require("../helpers/hr.js");
|
|
22
|
+
const format_js_1 = require("../helpers/format.js");
|
|
23
|
+
const runTestFile_js_1 = require("./runTestFile.js");
|
|
24
|
+
const logs_js_1 = require("../helpers/logs.js");
|
|
25
|
+
const runTests = (dir, configs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
+
const cwd = process.cwd();
|
|
27
|
+
const testDir = path_1.default.join(cwd, dir);
|
|
28
|
+
const currentDir = path_1.default.relative(cwd, testDir);
|
|
29
|
+
const files = (0, getFiles_js_1.getFiles)(testDir, undefined, configs);
|
|
30
|
+
const totalTests = files.length;
|
|
31
|
+
const showLogs = !(0, logs_js_1.isQuiet)(configs);
|
|
32
|
+
let passed = true;
|
|
33
|
+
if (showLogs) {
|
|
34
|
+
(0, hr_js_1.hr)();
|
|
35
|
+
console.log(`${format_js_1.format.bold('Directory:')} ${format_js_1.format.underline(currentDir)}${os_1.EOL}`);
|
|
36
|
+
}
|
|
37
|
+
for (let i = 0; i < files.length; i++) {
|
|
38
|
+
const filePath = files[i];
|
|
39
|
+
const fileRelative = path_1.default.relative(cwd, filePath);
|
|
40
|
+
const testPassed = yield (0, runTestFile_js_1.runTestFile)(filePath, configs);
|
|
41
|
+
const testNumber = i + 1;
|
|
42
|
+
const counter = format_js_1.format.counter(testNumber, totalTests);
|
|
43
|
+
const command = `${(0, runner_js_1.runner)(fileRelative)} ${fileRelative}`;
|
|
44
|
+
const nextLine = i + 1 !== files.length ? os_1.EOL : '';
|
|
45
|
+
const log = `${counter}/${totalTests} ${command}${nextLine}`;
|
|
46
|
+
if (testPassed) {
|
|
47
|
+
showLogs &&
|
|
48
|
+
console.log(`${indentation_js_1.indentation.test}${format_js_1.format.success('✔')} ${log}`);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
showLogs && console.log(`${indentation_js_1.indentation.test}${format_js_1.format.fail('✖')} ${log}`);
|
|
52
|
+
passed = false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return passed;
|
|
56
|
+
});
|
|
57
|
+
exports.runTests = runTests;
|
|
58
|
+
const runTestsParallel = (dir, configs) => {
|
|
59
|
+
const cwd = process.cwd();
|
|
60
|
+
const testDir = path_1.default.join(cwd, dir);
|
|
61
|
+
const files = (0, getFiles_js_1.getFiles)(testDir, undefined, configs);
|
|
62
|
+
const showLogs = !(0, logs_js_1.isQuiet)(configs);
|
|
63
|
+
let passed = true;
|
|
64
|
+
return new Promise((resolve) => {
|
|
65
|
+
for (let i = 0; i < files.length; i++) {
|
|
66
|
+
const filePath = files[i];
|
|
67
|
+
const fileRelative = path_1.default.relative(cwd, filePath);
|
|
68
|
+
(0, runTestFile_js_1.runTestFile)(filePath, configs).then((testPassed) => {
|
|
69
|
+
const command = `${(0, runner_js_1.runner)(fileRelative)} ${fileRelative}`;
|
|
70
|
+
const log = command;
|
|
71
|
+
if (testPassed) {
|
|
72
|
+
showLogs &&
|
|
73
|
+
console.log(`${indentation_js_1.indentation.test}${format_js_1.format.success('✔')} ${log}`);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
showLogs &&
|
|
77
|
+
console.log(`${indentation_js_1.indentation.test}${format_js_1.format.fail('✖')} ${log}`);
|
|
78
|
+
passed = false;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
resolve(passed);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
exports.runTestsParallel = runTestsParallel;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Code = 0 | 1;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export type Configs = {
|
|
2
|
+
/**
|
|
3
|
+
* By setting `true`, **Poku** won't exit the process and will return the exit code (`0` or `1`).
|
|
4
|
+
*
|
|
5
|
+
* You can combine this option with **Poku**'s `exit` method or just use the result, for example, in `process.exit(code)`.
|
|
6
|
+
*
|
|
7
|
+
* @default false
|
|
8
|
+
*/
|
|
9
|
+
noExit?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Customize `stdout` options.
|
|
12
|
+
*/
|
|
13
|
+
log?: {
|
|
14
|
+
/**
|
|
15
|
+
* @default false
|
|
16
|
+
*/
|
|
17
|
+
success?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* @default true
|
|
20
|
+
*/
|
|
21
|
+
fail?: boolean;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* This option overwrites all `log` settings
|
|
25
|
+
*
|
|
26
|
+
* @default false
|
|
27
|
+
*/
|
|
28
|
+
quiet?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Filter by path to match only the files that should be performed
|
|
31
|
+
*
|
|
32
|
+
* @default /\.test\./i
|
|
33
|
+
*/
|
|
34
|
+
filter?: RegExp;
|
|
35
|
+
parallel?: boolean;
|
|
36
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const escapeRegExp: (string: string) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const filter: RegExp | null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const forceArray: <T>(input: T | T[]) => T[];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const format: {
|
|
2
|
+
counter: (current: number, total: number, pad?: string) => string;
|
|
3
|
+
bold: (value: string) => string;
|
|
4
|
+
underline: (value: string) => string;
|
|
5
|
+
info: (value: string) => string;
|
|
6
|
+
success: (value: string) => string;
|
|
7
|
+
fail: (value: string) => string;
|
|
8
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const hr: () => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const runner: (filename: string) => "tsx" | "node";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Code } from '../@types/code.js';
|
|
2
|
+
import { Configs } from '../@types/poku.js';
|
|
3
|
+
export declare function poku(targetDirs: string | string[], configs?: Configs): Promise<void>;
|
|
4
|
+
export declare function poku(targetDirs: string | string[], configs: Configs & {
|
|
5
|
+
noExit: true;
|
|
6
|
+
}): Promise<Code>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const checkNode: (version: number) => Promise<number>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "poku",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "🐷 This is Poku",
|
|
5
|
+
"main": "./lib/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "npx tsx --tsconfig ./tsconfig.test.json ./test/run.test.ts",
|
|
8
|
+
"test:docker": "cd ./test/docker && docker compose down; docker compose up --build --abort-on-container-exit",
|
|
9
|
+
"pretest:ci": "rm -rf ./ci; npx tsc -p tsconfig.test.json",
|
|
10
|
+
"test:ci": "npx tsx ./test/ci.test.ts",
|
|
11
|
+
"posttest:ci": "rm -rf ./ci",
|
|
12
|
+
"update": "npx npu; npm run init",
|
|
13
|
+
"prebuild": "rm -rf ./lib",
|
|
14
|
+
"build": "npx tsc",
|
|
15
|
+
"eslint:checker": "npx eslint . --ext .js,.ts",
|
|
16
|
+
"eslint:fix": "npx eslint . --fix --config ./.eslintrc.json",
|
|
17
|
+
"prettier:checker": "npx prettier --check .",
|
|
18
|
+
"prettier:fix": "npx prettier --write .github/workflows/*.yml ."
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/wellwelwel/poku.git"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"test",
|
|
27
|
+
"runner",
|
|
28
|
+
"isolate"
|
|
29
|
+
],
|
|
30
|
+
"author": "https://github.com/wellwelwel",
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/wellwelwel/poku/issues"
|
|
33
|
+
},
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=6.x"
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"lib"
|
|
39
|
+
],
|
|
40
|
+
"type": "commonjs",
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/node": "^20.11.17",
|
|
43
|
+
"@typescript-eslint/eslint-plugin": "^7.0.1",
|
|
44
|
+
"@typescript-eslint/parser": "^7.0.1",
|
|
45
|
+
"eslint": "^8.56.0",
|
|
46
|
+
"eslint-config-prettier": "^9.1.0",
|
|
47
|
+
"eslint-import-resolver-typescript": "^3.6.1",
|
|
48
|
+
"eslint-plugin-import": "^2.29.1",
|
|
49
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
50
|
+
"packages-update": "^1.2.1",
|
|
51
|
+
"prettier": "^3.2.5",
|
|
52
|
+
"tsx": "^4.7.1",
|
|
53
|
+
"typescript": "^5.3.3"
|
|
54
|
+
}
|
|
55
|
+
}
|