1- import { createStubFileSystem } from "../adapters/fileSystem.stub " ;
1+ import { createStubExec } from "../adapters/exec.stubs " ;
22import { findPackagesConfiguration } from "./findPackagesConfiguration" ;
33
44describe ( "findPackagesConfiguration" , ( ) => {
55 it ( "defaults the configuration file when one isn't provided" , async ( ) => {
66 // Arrange
7- const dependencies = {
8- fileSystem : createStubFileSystem ( {
9- data : "{}" ,
10- } ) ,
11- } ;
7+ const dependencies = { exec : createStubExec ( ) } ;
128
139 // Act
1410 await findPackagesConfiguration ( dependencies , undefined ) ;
1511
1612 // Assert
17- expect ( dependencies . fileSystem . readFile ) . toHaveBeenLastCalledWith ( `./package.json` ) ;
13+ expect ( dependencies . exec ) . toHaveBeenLastCalledWith ( `cat " ./package.json" ` ) ;
1814 } ) ;
1915
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 ( ) => {
2117 // Arrange
22- const dependencies = {
23- fileSystem : createStubFileSystem ( {
24- data : "{}" ,
25- } ) ,
26- } ;
18+ const dependencies = { exec : createStubExec ( ) } ;
2719 const config = "./custom/package.json" ;
2820
2921 // Act
3022 await findPackagesConfiguration ( dependencies , config ) ;
3123
3224 // 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"` ) ;
5126 } ) ;
5227
5328 it ( "applies packages defaults when none are provided" , async ( ) => {
5429 // Arrange
55- const dependencies = {
56- fileSystem : createStubFileSystem ( {
57- data : "{}" ,
58- } ) ,
59- } ;
30+ const dependencies = { exec : createStubExec ( { stdout : "{}" } ) } ;
6031 const config = "./package.json" ;
6132
6233 // Act
@@ -68,28 +39,4 @@ describe("findPackagesConfiguration", () => {
6839 devDependencies : { } ,
6940 } ) ;
7041 } ) ;
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- } ) ;
9542} ) ;
0 commit comments