@@ -4,13 +4,16 @@ import { convertComments, ConvertCommentsDependencies } from "./convertComments"
44const createStubDependencies = (
55 overrides : Partial < ConvertCommentsDependencies > = { } ,
66) : ConvertCommentsDependencies => ( {
7+ collectCommentFileNames : async ( ) => ( {
8+ include : [ "a.ts" ] ,
9+ } ) ,
710 convertFileComments : jest . fn ( ) ,
8- globAsync : jest . fn ( ) . mockResolvedValue ( [ "src/ a.ts" , "src/ b.ts" ] ) ,
11+ globAsync : jest . fn ( ) . mockResolvedValue ( [ "a.ts" , "b.ts" ] ) ,
912 ...overrides ,
1013} ) ;
1114
1215describe ( "convertComments" , ( ) => {
13- it ( "returns an empty result when --comments is not provided " , async ( ) => {
16+ it ( "returns an empty result when filePathGlobs is undefined " , async ( ) => {
1417 // Arrange
1518 const dependencies = createStubDependencies ( ) ;
1619
@@ -24,74 +27,48 @@ describe("convertComments", () => {
2427 } ) ;
2528 } ) ;
2629
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 ( ) => {
2831 // Arrange
29- const dependencies = createStubDependencies ( ) ;
32+ const error = new Error ( "Failure!" ) ;
33+ const dependencies = createStubDependencies ( {
34+ collectCommentFileNames : async ( ) => error ,
35+ } ) ;
3036
3137 // Act
3238 const result = await convertComments ( dependencies , true ) ;
3339
3440 // Assert
3541 expect ( result ) . toEqual ( {
36- errors : expect . arrayContaining ( [ expect . any ( Error ) ] ) ,
42+ errors : [ error ] ,
3743 status : ResultStatus . Failed ,
3844 } ) ;
3945 } ) ;
4046
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 ( ) => {
4248 // Arrange
49+ const globAsyncError = new Error ( ) ;
4350 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 ) ,
5652 } ) ;
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 ( ) ;
6253
6354 // Act
64- const result = await convertComments ( dependencies , true , {
65- include : [ "src/*.ts" ] ,
66- } ) ;
55+ const result = await convertComments ( dependencies , [ "*.ts" ] ) ;
6756
6857 // Assert
6958 expect ( result ) . toEqual ( {
70- data : [ "src/a.ts" , "src/b.ts" ] ,
71- status : ResultStatus . Succeeded ,
59+ errors : [ globAsyncError ] ,
60+ status : ResultStatus . Failed ,
7261 } ) ;
7362 } ) ;
7463
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 ( ) => {
7665 // 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 ( [ ] ) ,
8971 } ) ;
90- } ) ;
91-
92- it ( "returns an error when there are no file path globs" , async ( ) => {
93- // Arrange
94- const dependencies = createStubDependencies ( ) ;
9572
9673 // Act
9774 const result = await convertComments ( dependencies , [ ] ) ;
@@ -103,26 +80,29 @@ describe("convertComments", () => {
10380 } ) ;
10481 } ) ;
10582
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 ( ) => {
10784 // Arrange
108- const globAsyncError = new Error ( ) ;
10985 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" ] ) ,
11191 } ) ;
11292
11393 // Act
114- const result = await convertComments ( dependencies , [ "*.ts" ] ) ;
94+ const result = await convertComments ( dependencies , [ ] ) ;
11595
11696 // Assert
11797 expect ( result ) . toEqual ( {
118- errors : [ globAsyncError ] ,
98+ errors : expect . arrayContaining ( [ expect . any ( Error ) ] ) ,
11999 status : ResultStatus . Failed ,
120100 } ) ;
121101 } ) ;
122102
123103 it ( "returns the failure result when a file conversion fails" , async ( ) => {
124104 // Arrange
125- const fileConversionError = new Error ( ) ;
105+ const fileConversionError = new Error ( "Failure!" ) ;
126106 const dependencies = createStubDependencies ( {
127107 convertFileComments : jest . fn ( ) . mockResolvedValueOnce ( fileConversionError ) ,
128108 } ) ;
@@ -146,7 +126,7 @@ describe("convertComments", () => {
146126
147127 // Assert
148128 expect ( result ) . toEqual ( {
149- data : [ "src/ a.ts" , "src/ b.ts" ] ,
129+ data : [ "a.ts" , "b.ts" ] ,
150130 status : ResultStatus . Succeeded ,
151131 } ) ;
152132 } ) ;
0 commit comments