@@ -4,45 +4,70 @@ import * as path from "path";
4
4
import { promisify } from "util" ;
5
5
6
6
import { createTestArgs } from "./createTestArgs" ;
7
- import { PromiseValue } from "../src/utils" ;
8
7
import { assertFileContents } from "./expectFileContains" ;
9
8
10
9
const exec = promisify ( cp . exec ) ;
11
10
const readFile = promisify ( fs . readFile ) ;
12
11
13
- export const createTests = ( cwd : string ) => {
12
+ export type TestSettings = {
13
+ /**
14
+ * Expected location of the output ESLint configuration file.
15
+ */
16
+ eslint ?: string ;
17
+
18
+ /**
19
+ * Any extra commands to pass to the CLI.
20
+ */
21
+ extraArgs ?: string [ ] ;
22
+ } ;
23
+
24
+ jest . setTimeout ( 10000 ) ;
25
+
26
+ const act = async ( testArgs : string [ ] ) => {
27
+ try {
28
+ return await exec ( `ts-node bin/tslint-to-eslint-config ${ testArgs . join ( " " ) } ` ) ;
29
+ } catch ( error ) {
30
+ return error ;
31
+ }
32
+ } ;
33
+
34
+ export const createTests = (
35
+ cwd : string ,
36
+ { eslint = "./.eslintrc.json" , extraArgs = [ ] } : TestSettings = { } ,
37
+ ) => {
14
38
const testName = path . basename ( cwd ) ;
15
39
const accept = "acceptTestChanges" in globalThis ;
16
40
const cwdPath = ( fileName : string ) => path . join ( cwd , fileName ) ;
17
41
const readTestFile = async ( fileName : string ) => ( await readFile ( cwdPath ( fileName ) ) ) . toString ( ) ;
18
42
19
43
describe ( testName , ( ) => {
20
- let result : PromiseValue < ReturnType < typeof exec > > ;
21
- beforeAll ( async ( ) => {
44
+ test ( "configuration output" , async ( ) => {
22
45
// Arrange
23
- const args = await createTestArgs ( cwd ) ;
46
+ const testArgs = await createTestArgs ( cwd , extraArgs ) ;
24
47
25
48
// Act
26
- try {
27
- result = await exec ( `ts-node bin/tslint-to-eslint-config ${ args } ` ) ;
28
- } catch ( error ) {
29
- result = error ;
30
- }
31
- } ) ;
49
+ await act ( testArgs ) ;
32
50
33
- test ( "configuration output" , async ( ) => {
34
- await assertFileContents (
35
- cwdPath ( "expected.json" ) ,
36
- await readTestFile ( ".eslintrc.json" ) ,
37
- accept ,
38
- ) ;
51
+ await assertFileContents ( cwdPath ( "expected.json" ) , await readTestFile ( eslint ) , accept ) ;
39
52
} ) ;
40
53
41
54
test ( "stderr" , async ( ) => {
55
+ // Arrange
56
+ const testArgs = await createTestArgs ( cwd , extraArgs ) ;
57
+
58
+ // Act
59
+ const result = await act ( testArgs ) ;
60
+
42
61
await assertFileContents ( cwdPath ( "stderr.txt" ) , result . stderr , accept ) ;
43
62
} ) ;
44
63
45
64
test ( "stdout" , async ( ) => {
65
+ // Arrange
66
+ const testArgs = await createTestArgs ( cwd , extraArgs ) ;
67
+
68
+ // Act
69
+ const result = await act ( testArgs ) ;
70
+
46
71
await assertFileContents ( cwdPath ( "stdout.txt" ) , result . stdout , accept ) ;
47
72
} ) ;
48
73
} ) ;
0 commit comments