Skip to content

Commit 99f8d44

Browse files
committed
feat(test): additional arg -c (count) and more fancy test output
1 parent c9fe27e commit 99f8d44

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/helpers/MakeTaskRequest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as http from "http";
22
import * as fs from "fs";
33

4-
export default function (testName: string, address: string, authkey: string|null = null) {
4+
export default function (testName: string, address: string, authkey: string|null = null, testSerialId: string|number|null = null) {
55
const url = new URL(address);
66

77
try {
@@ -37,7 +37,7 @@ export default function (testName: string, address: string, authkey: string|null
3737
}
3838

3939
const req = http.request(connection, res => {
40-
console.log(`Status Code: ${res.statusCode}`)
40+
console.log(`\n\n${testSerialId !== null ? `Run #${testSerialId}\n` : ''}HTTP Code: ${res.statusCode}`)
4141

4242
res.on('data', d => {
4343
process.stdout.write(d)

src/test.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import CommandLineArgs from "command-line-args";
22
import MakeTaskRequest from "./helpers/MakeTaskRequest";
3+
import {ISODate} from "./helpers/ISODate";
34
import Config from "./types/Config";
45
import {readFileSync} from "fs";
56
import fs from "fs";
@@ -10,6 +11,7 @@ const optionDefinitions = [
1011
{name: 'exact', alias: 'e', type: String, multiple: true},
1112
{name: 'remote', alias: 'r'},
1213
{name: 'key', alias: 'k'},
14+
{name: 'count', alias: 'c', default: 1, type: Number},
1315
];
1416

1517
const args = CommandLineArgs(optionDefinitions);
@@ -28,8 +30,10 @@ Arguments:
2830
-e, --exact Run exact test by name
2931
-r, --remote Set target server (default: http://127.0.0.1:8080)
3032
-k, --key Override AUTH_KEY in requests
33+
-c, --count How much times to run each test (default: 1)
3134
3235
Examples:
36+
npm run test -- -e "example" -c 5
3337
npm run test -- -e "example" -e "another"
3438
npm run test -- --all
3539
`);
@@ -44,15 +48,25 @@ Examples:
4448
if (args.exact !== undefined && args.exact.length) {
4549
console.log('Running exact tests');
4650
args.exact.forEach((testName: string) => {
47-
MakeTaskRequest(testName, address, authkey);
51+
for (let i = 0; i < args.count; i++) {
52+
console.log(`Running: ${testName} #${i + 1} At: ${new ISODate()}`);
53+
(async () => {
54+
MakeTaskRequest(testName, address, authkey, i + 1);
55+
})();
56+
}
4857
});
4958
} else if (args.all !== undefined) {
5059
console.log('Running all tests');
5160
const dir = __dirname + '/../test/';
5261
fs.readdir(dir, (err, files) => {
5362
files.forEach(fileName => {
54-
console.log('Running:' + fileName);
55-
MakeTaskRequest(fileName, address, authkey);
63+
console.log('Current tests:' + fileName);
64+
for (let i = 0; i < args.count; i++) {
65+
console.log(`Running: ${fileName} #${i + 1} At: ${new ISODate()}`);
66+
(async () => {
67+
MakeTaskRequest(fileName, address, authkey, i + 1);
68+
})();
69+
}
5670
});
5771
});
5872
}

0 commit comments

Comments
 (0)