Skip to content

Commit 33c584f

Browse files
committed
Add test:transpileOnly command
1 parent 882f60b commit 33c584f

File tree

4 files changed

+52
-12
lines changed

4 files changed

+52
-12
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ are using it from a `package.json` script, you can simply write `typescript-scri
7676

7777
Accepts all the usual [mocha CLI flags and options](https://mochajs.org/#command-line-usage).
7878

79+
- `test:transpileOnly`
80+
81+
Same as the `test` command, except it uses the `transpileOnly` function of the TSC compiler
82+
to make it extra fast (this works by only transpiling the code but not checking for errors)
83+
7984
- `compile`
8085

8186
Runs the `tsc` compiler.

index.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@
22

33
"use strict";
44

5-
import { compile, format, help, init, lint, run, test } from "./scripts";
5+
import {
6+
compile,
7+
format,
8+
help,
9+
init,
10+
lint,
11+
run,
12+
test,
13+
testTranspileOnly
14+
} from "./scripts";
615

716
const args = process.argv.slice(2);
817
const scriptName = args[0];
@@ -55,6 +64,12 @@ switch (scriptName) {
5564
break;
5665
}
5766

67+
case "test:transpileOnly": {
68+
const status = testTranspileOnly();
69+
process.exit(status);
70+
break;
71+
}
72+
5873
default:
5974
help();
6075
process.exit(1);

scripts/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ import help from "./help";
44
import init from "./init";
55
import lint from "./lint";
66
import run from "./run";
7-
import test from "./test";
7+
import test, { testTranspileOnly } from "./test";
88

9-
export { compile, format, help, init, lint, run, test };
9+
export { compile, format, help, init, lint, run, test, testTranspileOnly };

scripts/test.ts

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,10 @@ import { appDirectory } from "./utils";
55

66
const args = process.argv.slice(3);
77

8-
function test(): number {
8+
const runMochaProcess = (args: string[]) => {
99
const result = spawn.sync(
1010
path.join(appDirectory, "./node_modules/.bin/mocha"),
11-
[
12-
"-r",
13-
"ts-node/register",
14-
"--watch-extensions",
15-
"ts",
16-
"--recursive",
17-
...args
18-
], // TODO improve this so that sane default mocha flags are set
11+
args,
1912
{ stdio: "inherit" }
2013
);
2114

@@ -24,6 +17,33 @@ function test(): number {
2417
}
2518

2619
return typeof result.status === "number" ? result.status : 1;
20+
};
21+
22+
function test(): number {
23+
const result = runMochaProcess([
24+
"-r",
25+
"ts-node/register",
26+
"--watch-extensions",
27+
"ts",
28+
"--recursive",
29+
...args
30+
]);
31+
32+
return result;
33+
}
34+
35+
function testTranspileOnly(): number {
36+
const result = runMochaProcess([
37+
"-r",
38+
"ts-node/register/transpile-only",
39+
"--watch-extensions",
40+
"ts",
41+
"--recursive",
42+
...args
43+
]);
44+
45+
return result;
2746
}
2847

2948
export default test;
49+
export { testTranspileOnly };

0 commit comments

Comments
 (0)