@@ -4,13 +4,16 @@ import { convertComments, ConvertCommentsDependencies } from "./convertComments"
4
4
const createStubDependencies = (
5
5
overrides : Partial < ConvertCommentsDependencies > = { } ,
6
6
) : ConvertCommentsDependencies => ( {
7
+ collectCommentFileNames : async ( ) => ( {
8
+ include : [ "a.ts" ] ,
9
+ } ) ,
7
10
convertFileComments : jest . fn ( ) ,
8
- globAsync : jest . fn ( ) . mockResolvedValue ( [ "src/ a.ts" , "src/ b.ts" ] ) ,
11
+ globAsync : jest . fn ( ) . mockResolvedValue ( [ "a.ts" , "b.ts" ] ) ,
9
12
...overrides ,
10
13
} ) ;
11
14
12
15
describe ( "convertComments" , ( ) => {
13
- it ( "returns an empty result when --comments is not provided " , async ( ) => {
16
+ it ( "returns an empty result when filePathGlobs is undefined " , async ( ) => {
14
17
// Arrange
15
18
const dependencies = createStubDependencies ( ) ;
16
19
@@ -24,74 +27,48 @@ describe("convertComments", () => {
24
27
} ) ;
25
28
} ) ;
26
29
27
- it ( "returns an error when --comments is given as a boolean value without a TypeScript configuration " , async ( ) => {
30
+ it ( "returns the failure result when collectCommentFileNames fails " , async ( ) => {
28
31
// Arrange
29
- const dependencies = createStubDependencies ( ) ;
32
+ const error = new Error ( "Failure!" ) ;
33
+ const dependencies = createStubDependencies ( {
34
+ collectCommentFileNames : async ( ) => error ,
35
+ } ) ;
30
36
31
37
// Act
32
38
const result = await convertComments ( dependencies , true ) ;
33
39
34
40
// Assert
35
41
expect ( result ) . toEqual ( {
36
- errors : expect . arrayContaining ( [ expect . any ( Error ) ] ) ,
42
+ errors : [ error ] ,
37
43
status : ResultStatus . Failed ,
38
44
} ) ;
39
45
} ) ;
40
46
41
- it ( "includes TypeScript files when --comments is given as a boolean value with a TypeScript files configuration " , async ( ) => {
47
+ it ( "returns the failure result when a file path glob fails " , async ( ) => {
42
48
// Arrange
49
+ const globAsyncError = new Error ( ) ;
43
50
const dependencies = createStubDependencies ( {
44
- globAsync : jest . fn ( ) . mockResolvedValue ( [ "src/a.ts" ] ) ,
45
- } ) ;
46
-
47
- // Act
48
- const result = await convertComments ( dependencies , true , {
49
- files : [ "src/a.ts" ] ,
50
- } ) ;
51
-
52
- // Assert
53
- expect ( result ) . toEqual ( {
54
- data : [ "src/a.ts" ] ,
55
- status : ResultStatus . Succeeded ,
51
+ globAsync : jest . fn ( ) . mockResolvedValueOnce ( globAsyncError ) ,
56
52
} ) ;
57
- } ) ;
58
-
59
- it ( "includes TypeScript inclusions when --comments is given as a boolean value with a TypeScript include configuration" , async ( ) => {
60
- // Arrange
61
- const dependencies = createStubDependencies ( ) ;
62
53
63
54
// Act
64
- const result = await convertComments ( dependencies , true , {
65
- include : [ "src/*.ts" ] ,
66
- } ) ;
55
+ const result = await convertComments ( dependencies , [ "*.ts" ] ) ;
67
56
68
57
// Assert
69
58
expect ( result ) . toEqual ( {
70
- data : [ "src/a.ts" , "src/b.ts" ] ,
71
- status : ResultStatus . Succeeded ,
59
+ errors : [ globAsyncError ] ,
60
+ status : ResultStatus . Failed ,
72
61
} ) ;
73
62
} ) ;
74
63
75
- it ( "excludes TypeScript exclusions when --comments is given as a boolean value with a TypeScript excludes configuration " , async ( ) => {
64
+ it ( "returns an error when there are no resultant file paths " , async ( ) => {
76
65
// Arrange
77
- const dependencies = createStubDependencies ( ) ;
78
-
79
- // Act
80
- const result = await convertComments ( dependencies , true , {
81
- exclude : [ "src/b.ts" ] ,
82
- include : [ "src/*.ts" ] ,
83
- } ) ;
84
-
85
- // Assert
86
- expect ( result ) . toEqual ( {
87
- data : [ "src/a.ts" ] ,
88
- status : ResultStatus . Succeeded ,
66
+ const dependencies = createStubDependencies ( {
67
+ collectCommentFileNames : async ( ) => ( {
68
+ include : [ ] ,
69
+ } ) ,
70
+ globAsync : jest . fn ( ) . mockResolvedValueOnce ( [ ] ) ,
89
71
} ) ;
90
- } ) ;
91
-
92
- it ( "returns an error when there are no file path globs" , async ( ) => {
93
- // Arrange
94
- const dependencies = createStubDependencies ( ) ;
95
72
96
73
// Act
97
74
const result = await convertComments ( dependencies , [ ] ) ;
@@ -103,26 +80,29 @@ describe("convertComments", () => {
103
80
} ) ;
104
81
} ) ;
105
82
106
- it ( "returns the failure result when a file path glob fails " , async ( ) => {
83
+ it ( "returns an error when there all globbed file paths are excluded " , async ( ) => {
107
84
// Arrange
108
- const globAsyncError = new Error ( ) ;
109
85
const dependencies = createStubDependencies ( {
110
- globAsync : jest . fn ( ) . mockResolvedValueOnce ( globAsyncError ) ,
86
+ collectCommentFileNames : async ( ) => ( {
87
+ exclude : [ "*.ts" ] ,
88
+ include : [ "a.ts" ] ,
89
+ } ) ,
90
+ globAsync : jest . fn ( ) . mockResolvedValueOnce ( [ "a.ts" ] ) ,
111
91
} ) ;
112
92
113
93
// Act
114
- const result = await convertComments ( dependencies , [ "*.ts" ] ) ;
94
+ const result = await convertComments ( dependencies , [ ] ) ;
115
95
116
96
// Assert
117
97
expect ( result ) . toEqual ( {
118
- errors : [ globAsyncError ] ,
98
+ errors : expect . arrayContaining ( [ expect . any ( Error ) ] ) ,
119
99
status : ResultStatus . Failed ,
120
100
} ) ;
121
101
} ) ;
122
102
123
103
it ( "returns the failure result when a file conversion fails" , async ( ) => {
124
104
// Arrange
125
- const fileConversionError = new Error ( ) ;
105
+ const fileConversionError = new Error ( "Failure!" ) ;
126
106
const dependencies = createStubDependencies ( {
127
107
convertFileComments : jest . fn ( ) . mockResolvedValueOnce ( fileConversionError ) ,
128
108
} ) ;
@@ -146,7 +126,7 @@ describe("convertComments", () => {
146
126
147
127
// Assert
148
128
expect ( result ) . toEqual ( {
149
- data : [ "src/ a.ts" , "src/ b.ts" ] ,
129
+ data : [ "a.ts" , "b.ts" ] ,
150
130
status : ResultStatus . Succeeded ,
151
131
} ) ;
152
132
} ) ;
0 commit comments