11import { removeSync } from 'fs-extra' ;
22import { getWrappers , SourceWrapper } from './get-wrappers' ;
33import mock = require( 'mock-fs' ) ;
4+ import { toJson , withJson } from '../../../test/mock' ;
45
56describe ( 'getWrappers' , ( ) => {
67 afterEach ( ( ) => {
@@ -13,21 +14,22 @@ describe('getWrappers', () => {
1314
1415 beforeEach ( ( ) => {
1516 mock ( {
16- 'package.json' : JSON . stringify ( { name : 'root' } ) ,
17- 'cli/a/package.json' : JSON . stringify ( { name : 'cli-a' } ) ,
18- 'cli/b/package.json' : JSON . stringify ( { name : 'cli-b' } ) ,
19- 'lerna.json' : JSON . stringify ( { packages : [ 'lerna/*' ] } ) ,
20- 'lerna/a/package.json' : JSON . stringify ( { name : 'lerna-a' } ) ,
21- 'lerna/b/package.json' : JSON . stringify ( { name : 'lerna-b' } ) ,
22- 'packages/a/package.json' : JSON . stringify ( { name : 'packages-a' } ) ,
23- 'packages/b/package.json' : JSON . stringify ( { name : 'packages-b' } ) ,
17+ 'package.json' : toJson ( { name : 'root' } ) ,
18+ 'cli/a/package.json' : toJson ( { name : 'cli-a' } ) ,
19+ 'cli/b/package.json' : toJson ( { name : 'cli-b' } ) ,
20+ 'lerna.json' : toJson ( { packages : [ 'lerna/*' ] } ) ,
21+ 'lerna/a/package.json' : toJson ( { name : 'lerna-a' } ) ,
22+ 'lerna/b/package.json' : toJson ( { name : 'lerna-b' } ) ,
23+ 'packages/a/package.json' : toJson ( { name : 'packages-a' } ) ,
24+ 'packages/b/package.json' : toJson ( { name : 'packages-b' } ) ,
2425 } ) ;
2526 } ) ;
2627
27- const getShape = ( name : string , filePath : string ) : SourceWrapper => ( {
28- contents : { name } ,
29- filePath : `${ process . cwd ( ) } /${ filePath } ` ,
30- } ) ;
28+ const getShape = ( name : string , filePath : string ) : SourceWrapper =>
29+ withJson ( {
30+ contents : { name } ,
31+ filePath : `${ process . cwd ( ) } /${ filePath } ` ,
32+ } ) ;
3133
3234 it ( 'prefers CLI' , ( ) => {
3335 const program = { source : [ 'cli/*/package.json' ] } ;
@@ -64,16 +66,16 @@ describe('getWrappers', () => {
6466 describe ( 'when configuration is an array' , ( ) => {
6567 beforeEach ( ( ) => {
6668 mock ( {
67- 'package.json' : JSON . stringify ( { workspaces : [ 'as-array/*' ] } ) ,
68- 'as-array/a/package.json' : JSON . stringify ( { name : 'packages-a' } ) ,
69- 'as-array/b/package.json' : JSON . stringify ( { name : 'packages-b' } ) ,
69+ 'package.json' : toJson ( { workspaces : [ 'as-array/*' ] } ) ,
70+ 'as-array/a/package.json' : toJson ( { name : 'packages-a' } ) ,
71+ 'as-array/b/package.json' : toJson ( { name : 'packages-b' } ) ,
7072 } ) ;
7173 } ) ;
7274
7375 it ( 'should resolve correctly' , ( ) => {
7476 const program = { source : [ ] } ;
7577 expect ( getWrappers ( program ) ) . toEqual ( [
76- { contents : { workspaces : [ 'as-array/*' ] } , filePath : `${ process . cwd ( ) } /package.json` } ,
78+ withJson ( { contents : { workspaces : [ 'as-array/*' ] } , filePath : `${ process . cwd ( ) } /package.json` } ) ,
7779 getShape ( 'packages-a' , 'as-array/a/package.json' ) ,
7880 getShape ( 'packages-b' , 'as-array/b/package.json' ) ,
7981 ] ) ;
@@ -83,16 +85,19 @@ describe('getWrappers', () => {
8385 describe ( 'when configuration is an object' , ( ) => {
8486 beforeEach ( ( ) => {
8587 mock ( {
86- 'package.json' : JSON . stringify ( { workspaces : { packages : [ 'as-object/*' ] } } ) ,
87- 'as-object/a/package.json' : JSON . stringify ( { name : 'packages-a' } ) ,
88- 'as-object/b/package.json' : JSON . stringify ( { name : 'packages-b' } ) ,
88+ 'package.json' : toJson ( { workspaces : { packages : [ 'as-object/*' ] } } ) ,
89+ 'as-object/a/package.json' : toJson ( { name : 'packages-a' } ) ,
90+ 'as-object/b/package.json' : toJson ( { name : 'packages-b' } ) ,
8991 } ) ;
9092 } ) ;
9193
9294 it ( 'should resolve correctly' , ( ) => {
9395 const program = { source : [ ] } ;
9496 expect ( getWrappers ( program ) ) . toEqual ( [
95- { contents : { workspaces : { packages : [ 'as-object/*' ] } } , filePath : `${ process . cwd ( ) } /package.json` } ,
97+ withJson ( {
98+ contents : { workspaces : { packages : [ 'as-object/*' ] } } ,
99+ filePath : `${ process . cwd ( ) } /package.json` ,
100+ } ) ,
96101 getShape ( 'packages-a' , 'as-object/a/package.json' ) ,
97102 getShape ( 'packages-b' , 'as-object/b/package.json' ) ,
98103 ] ) ;
@@ -107,17 +112,17 @@ describe('getWrappers', () => {
107112
108113 beforeEach ( ( ) => {
109114 mock ( {
110- 'package.json' : JSON . stringify ( { name : 'root' } ) ,
115+ 'package.json' : toJson ( { name : 'root' } ) ,
111116 'pnpm-workspace.yaml' : [ 'packages:' , ' - "./*"' ] . join ( '\n' ) ,
112- 'a/package.json' : JSON . stringify ( { name : 'package-a' } ) ,
113- 'b/package.json' : JSON . stringify ( { name : 'package-b' } ) ,
117+ 'a/package.json' : toJson ( { name : 'package-a' } ) ,
118+ 'b/package.json' : toJson ( { name : 'package-b' } ) ,
114119 } ) ;
115120 } ) ;
116121
117122 it ( 'should resolve correctly' , ( ) => {
118123 const program = { source : [ ] } ;
119124 expect ( getWrappers ( program ) ) . toEqual ( [
120- { contents : { name : 'root' } , filePath : `${ process . cwd ( ) } /package.json` } ,
125+ withJson ( { contents : { name : 'root' } , filePath : `${ process . cwd ( ) } /package.json` } ) ,
121126 getShape ( 'package-a' , 'a/package.json' ) ,
122127 getShape ( 'package-b' , 'b/package.json' ) ,
123128 ] ) ;
0 commit comments