@@ -4,45 +4,70 @@ import * as path from "path";
44import { promisify } from "util" ;
55
66import { createTestArgs } from "./createTestArgs" ;
7- import { PromiseValue } from "../src/utils" ;
87import { assertFileContents } from "./expectFileContains" ;
98
109const exec = promisify ( cp . exec ) ;
1110const readFile = promisify ( fs . readFile ) ;
1211
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+ ) => {
1438 const testName = path . basename ( cwd ) ;
1539 const accept = "acceptTestChanges" in globalThis ;
1640 const cwdPath = ( fileName : string ) => path . join ( cwd , fileName ) ;
1741 const readTestFile = async ( fileName : string ) => ( await readFile ( cwdPath ( fileName ) ) ) . toString ( ) ;
1842
1943 describe ( testName , ( ) => {
20- let result : PromiseValue < ReturnType < typeof exec > > ;
21- beforeAll ( async ( ) => {
44+ test ( "configuration output" , async ( ) => {
2245 // Arrange
23- const args = await createTestArgs ( cwd ) ;
46+ const testArgs = await createTestArgs ( cwd , extraArgs ) ;
2447
2548 // 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 ) ;
3250
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 ) ;
3952 } ) ;
4053
4154 test ( "stderr" , async ( ) => {
55+ // Arrange
56+ const testArgs = await createTestArgs ( cwd , extraArgs ) ;
57+
58+ // Act
59+ const result = await act ( testArgs ) ;
60+
4261 await assertFileContents ( cwdPath ( "stderr.txt" ) , result . stderr , accept ) ;
4362 } ) ;
4463
4564 test ( "stdout" , async ( ) => {
65+ // Arrange
66+ const testArgs = await createTestArgs ( cwd , extraArgs ) ;
67+
68+ // Act
69+ const result = await act ( testArgs ) ;
70+
4671 await assertFileContents ( cwdPath ( "stdout.txt" ) , result . stdout , accept ) ;
4772 } ) ;
4873 } ) ;
0 commit comments