1
- import { createStubFileSystem } from "../adapters/fileSystem.stub " ;
1
+ import { createStubExec } from "../adapters/exec.stubs " ;
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 = {
8
- fileSystem : createStubFileSystem ( {
9
- data : "{}" ,
10
- } ) ,
11
- } ;
7
+ const dependencies = { exec : createStubExec ( ) } ;
12
8
13
9
// Act
14
10
await findPackagesConfiguration ( dependencies , undefined ) ;
15
11
16
12
// Assert
17
- expect ( dependencies . fileSystem . readFile ) . toHaveBeenLastCalledWith ( `./package.json` ) ;
13
+ expect ( dependencies . exec ) . toHaveBeenLastCalledWith ( `cat " ./package.json" ` ) ;
18
14
} ) ;
19
15
20
- it ( "uses the configuration file from the packages command when one is provided" , async ( ) => {
16
+ it ( "includes a configuration file in the packages command when one is provided" , async ( ) => {
21
17
// Arrange
22
- const dependencies = {
23
- fileSystem : createStubFileSystem ( {
24
- data : "{}" ,
25
- } ) ,
26
- } ;
18
+ const dependencies = { exec : createStubExec ( ) } ;
27
19
const config = "./custom/package.json" ;
28
20
29
21
// Act
30
22
await findPackagesConfiguration ( dependencies , config ) ;
31
23
32
24
// Assert
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 ) ;
25
+ expect ( dependencies . exec ) . toHaveBeenLastCalledWith ( `cat "./custom/package.json"` ) ;
51
26
} ) ;
52
27
53
28
it ( "applies packages defaults when none are provided" , async ( ) => {
54
29
// Arrange
55
- const dependencies = {
56
- fileSystem : createStubFileSystem ( {
57
- data : "{}" ,
58
- } ) ,
59
- } ;
30
+ const dependencies = { exec : createStubExec ( { stdout : "{}" } ) } ;
60
31
const config = "./package.json" ;
61
32
62
33
// Act
@@ -68,28 +39,4 @@ describe("findPackagesConfiguration", () => {
68
39
devDependencies : { } ,
69
40
} ) ;
70
41
} ) ;
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
- } ) ;
95
42
} ) ;
0 commit comments