Skip to content

Commit 187e90b

Browse files
committed
Add single test option
1 parent ccb99b0 commit 187e90b

File tree

3 files changed

+70
-25
lines changed

3 files changed

+70
-25
lines changed

Diff for: lib/CLI.js

+30-11
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,15 @@ export class CLI {
3939
* */
4040
run() {
4141
return __awaiter(this, void 0, void 0, function* () {
42+
const argv = this.argv;
4243
const system = this.system;
43-
if (this.argv.includes('-h') ||
44-
this.argv.includes('--help')) {
44+
if (argv.includes('-h') ||
45+
argv.includes('--help')) {
4546
console.info(CLI.HELP.join(system.EOL));
4647
return;
4748
}
48-
if (this.argv.includes('-v') ||
49-
this.argv.includes('--version')) {
49+
if (argv.includes('-v') ||
50+
argv.includes('--version')) {
5051
console.info(CLI.VERSION);
5152
return;
5253
}
@@ -61,19 +62,35 @@ export class CLI {
6162
try {
6263
console.info(`Testing ${this.source}...`);
6364
const result = yield System.exec(`npx tsc -p ${source}`);
64-
console.info(result);
65-
const files = System.getFiles(target, /\.js$/);
65+
if (result) {
66+
console.info(result);
67+
}
68+
let files = [];
69+
if (argv.includes('--only')) {
70+
const file = argv[argv.indexOf('--only') + 1];
71+
files = [(file.endsWith('.js') ? file : `${file}.js`)];
72+
}
73+
else {
74+
files = System.getFiles(target, /\.js$/);
75+
}
6676
for (const file of files) {
6777
yield import(System.join(System.CWD, target, file));
6878
}
6979
const tester = Tester.default;
7080
yield tester.start();
71-
for (const success of tester.successes) {
72-
console.log('✅', success);
81+
if (argv.includes('--verbose')) {
82+
for (const success of tester.successes) {
83+
console.info('✅', success);
84+
}
85+
for (const error of tester.errors) {
86+
console.error('🛑', error[0]);
87+
console.error(error[1]);
88+
}
7389
}
74-
for (const error of tester.errors) {
75-
console.log('🛑', error[0]);
76-
console.error(error[1]);
90+
console.info('✅ COMPLETED:', tester.successes.length);
91+
if (tester.errors.length) {
92+
console.error('🛑 FAILED:', tester.errors.length);
93+
process.exit(1);
7794
}
7895
}
7996
catch (error) {
@@ -115,6 +132,8 @@ export class CLI {
115132
'',
116133
' --help, -h Prints this help text.',
117134
'',
135+
' --only [path] Runs a single test in [source].',
136+
'',
118137
' --verbose Prints this help text.',
119138
'',
120139
' --version, -v Prints the version string.',

Diff for: package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"license": "MIT",
77
"name": "@typescriptlibs/tst",
88
"type": "module",
9-
"version": "0.0.1",
9+
"version": "0.0.2",
1010
"bin": "bin/tst.mjs",
1111
"main": "lib/index.js",
1212
"types": "lib/index.d.ts",
@@ -40,7 +40,7 @@
4040
"build": "tsc -p src/",
4141
"clean": "rm -rf lib tst-run",
4242
"release": "npm publish --access public",
43-
"test": "tst tst/",
43+
"test": "tst --verbose tst/",
4444
"watch": "tsc -b src/ -w"
4545
}
4646
}

Diff for: src/CLI.ts

+38-12
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,20 @@ export class CLI {
5454
* */
5555

5656
public async run (): Promise<void> {
57+
const argv = this.argv;
5758
const system = this.system;
5859

5960
if (
60-
this.argv.includes('-h') ||
61-
this.argv.includes('--help')
61+
argv.includes('-h') ||
62+
argv.includes('--help')
6263
) {
6364
console.info(CLI.HELP.join(system.EOL));
6465
return;
6566
}
6667

6768
if (
68-
this.argv.includes('-v') ||
69-
this.argv.includes('--version')
69+
argv.includes('-v') ||
70+
argv.includes('--version')
7071
) {
7172
console.info(CLI.VERSION);
7273
return;
@@ -86,10 +87,23 @@ export class CLI {
8687

8788
try {
8889
console.info(`Testing ${this.source}...`);
90+
8991
const result = await System.exec(`npx tsc -p ${source}`);
90-
console.info(result);
9192

92-
const files = System.getFiles(target, /\.js$/);
93+
if (result) {
94+
console.info(result);
95+
}
96+
97+
let files: Array<string> = [];
98+
99+
if (argv.includes('--only')) {
100+
const file = argv[argv.indexOf('--only') + 1];
101+
102+
files = [ ( file.endsWith('.js') ? file : `${file}.js` ) ]
103+
}
104+
else {
105+
files = System.getFiles(target, /\.js$/);
106+
}
93107

94108
for (const file of files) {
95109
await import(System.join(System.CWD, target, file));
@@ -99,14 +113,24 @@ export class CLI {
99113

100114
await tester.start();
101115

102-
for (const success of tester.successes) {
103-
console.log('✅', success);
116+
if (argv.includes('--verbose')) {
117+
for (const success of tester.successes) {
118+
console.info('✅', success);
119+
}
120+
for (const error of tester.errors) {
121+
console.error('🛑', error[0]);
122+
console.error(error[1]);
123+
}
104124
}
105-
106-
for (const error of tester.errors) {
107-
console.log('🛑', error[0]);
108-
console.error(error[1]);
125+
126+
console.info('✅ COMPLETED:', tester.successes.length)
127+
128+
if (tester.errors.length) {
129+
console.error('🛑 FAILED:', tester.errors.length);
130+
131+
process.exit(1);
109132
}
133+
110134
}
111135
catch (error) {
112136
console.error(error);
@@ -158,6 +182,8 @@ export namespace CLI {
158182
'',
159183
' --help, -h Prints this help text.',
160184
'',
185+
' --only [path] Runs a single test in [source].',
186+
'',
161187
' --verbose Prints this help text.',
162188
'',
163189
' --version, -v Prints the version string.',

0 commit comments

Comments
 (0)