1
- import { createStubExec } from "../adapters/exec.stubs " ;
1
+ import { createStubFileSystem } from "../adapters/fileSystem.stub " ;
2
2
import { findPackagesConfiguration } from "./findPackagesConfiguration" ;
3
3
4
4
describe ( "findPackagesConfiguration" , ( ) => {
5
5
it ( "defaults the configuration file when one isn't provided" , async ( ) => {
6
6
// Arrange
7
- const dependencies = { exec : createStubExec ( ) } ;
7
+ const dependencies = {
8
+ fileSystem : createStubFileSystem ( {
9
+ data : "{}"
10
+ } )
11
+ }
8
12
9
13
// Act
10
14
await findPackagesConfiguration ( dependencies , undefined ) ;
11
15
12
16
// Assert
13
- expect ( dependencies . exec ) . toHaveBeenLastCalledWith ( `cat " ./package.json" ` ) ;
17
+ expect ( dependencies . fileSystem . readFile ) . toHaveBeenLastCalledWith ( `./package.json` ) ;
14
18
} ) ;
15
19
16
- it ( "includes a configuration file in the packages command when one is provided" , async ( ) => {
20
+ it ( "uses the configuration file from the packages command when one is provided" , async ( ) => {
17
21
// Arrange
18
- const dependencies = { exec : createStubExec ( ) } ;
22
+ const dependencies = {
23
+ fileSystem : createStubFileSystem ( {
24
+ data : "{}"
25
+ } )
26
+ }
19
27
const config = "./custom/package.json" ;
20
28
21
29
// Act
22
30
await findPackagesConfiguration ( dependencies , config ) ;
23
31
24
32
// Assert
25
- expect ( dependencies . exec ) . toHaveBeenLastCalledWith ( `cat "./custom/package.json"` ) ;
33
+ expect ( dependencies . fileSystem . readFile ) . toHaveBeenLastCalledWith ( `./custom/package.json` ) ;
34
+ } ) ;
35
+
36
+ it ( "returns an error when readFile returns an error" , async ( ) => {
37
+ // Arrange
38
+ const error = new Error ( "Oh no!" ) ;
39
+ const dependencies = {
40
+ fileSystem : createStubFileSystem ( {
41
+ data : error
42
+ } )
43
+ }
44
+ const config = "./custom/package.json" ;
45
+
46
+ // Act
47
+ const result = await findPackagesConfiguration ( dependencies , config ) ;
48
+
49
+ // Assert
50
+ expect ( result ) . toBe ( error ) ;
26
51
} ) ;
27
52
28
53
it ( "applies packages defaults when none are provided" , async ( ) => {
29
54
// Arrange
30
- const dependencies = { exec : createStubExec ( { stdout : "{}" } ) } ;
55
+ const dependencies = {
56
+ fileSystem : createStubFileSystem ( {
57
+ data : "{}"
58
+ } )
59
+ }
31
60
const config = "./package.json" ;
32
61
33
62
// Act
@@ -39,4 +68,28 @@ describe("findPackagesConfiguration", () => {
39
68
devDependencies : { } ,
40
69
} ) ;
41
70
} ) ;
71
+
72
+ it ( "uses existing package data when it exists" , async ( ) => {
73
+ // Arrange
74
+ const data = {
75
+ dependencies : {
76
+ eslint : "^11.22.33" ,
77
+ } ,
78
+ devDependencies : {
79
+ tslint : "^12.34.56"
80
+ }
81
+ }
82
+ const dependencies = {
83
+ fileSystem : createStubFileSystem ( {
84
+ data : JSON . stringify ( data )
85
+ } )
86
+ }
87
+ const config = "./package.json" ;
88
+
89
+ // Act
90
+ const result = await findPackagesConfiguration ( dependencies , config ) ;
91
+
92
+ // Assert
93
+ expect ( result ) . toEqual ( data ) ;
94
+ } ) ;
42
95
} ) ;
0 commit comments