1
1
import test from 'ava' ;
2
- import { writeJson , readJson } from 'fs-extra' ;
2
+ import { writeFile , readFile } from 'fs-extra' ;
3
3
import tempy from 'tempy' ;
4
4
import execa from 'execa' ;
5
5
import { stub } from 'sinon' ;
@@ -21,28 +21,49 @@ test.afterEach.always(() => {
21
21
} ) ;
22
22
23
23
test . serial ( 'Updade package.json' , async t => {
24
+ const pkg = `{
25
+ "name": "test",
26
+ "description": "pacakage description",
27
+ "version":
28
+ "0.0.0-dev" ,
29
+ "arr": [
30
+ 1,
31
+ 2, 3
32
+ ]
33
+ }
34
+ ` ;
35
+
24
36
// Create package.json in repository root
25
- await writeJson ( './package.json' , { version : '0.0.0-dev' } ) ;
37
+ await writeFile ( './package.json' , pkg ) ;
26
38
27
39
await updatePackageVersion ( '1.0.0' , t . context . logger ) ;
28
40
29
41
// Verify package.json has been updated
30
- t . is ( ( await readJson ( './package.json' ) ) . version , '1.0.0' ) ;
42
+ t . is ( ( await readFile ( './package.json' ) ) . toString ( ) , pkg . replace ( '0.0.0-dev' , '1.0.0' ) ) ;
43
+
31
44
// Verify the logger has been called with the version updated
32
45
t . deepEqual ( t . context . log . args [ 0 ] , [ 'Wrote version %s to package.json' , '1.0.0' ] ) ;
33
46
} ) ;
34
47
35
48
test . serial ( 'Updade package.json and npm-shrinkwrap.json' , async t => {
49
+ const pkg = `{
50
+ "name": "test"
51
+ , "description":
52
+ "pacakage description",
53
+
54
+ "version": "0.0.0-dev"
55
+ }` ;
36
56
// Create package.json in repository root
37
- await writeJson ( './package.json' , { version : '0.0.0-dev' } ) ;
57
+ await writeFile ( './package.json' , pkg ) ;
38
58
// Create a npm-shrinkwrap.json file
39
59
await execa ( 'npm' , [ 'shrinkwrap' ] ) ;
60
+ const shrinkwrap = ( await readFile ( './npm-shrinkwrap.json' ) ) . toString ( ) ;
40
61
41
62
await updatePackageVersion ( '1.0.0' , t . context . logger ) ;
42
63
43
64
// Verify package.json and npm-shrinkwrap.json have been updated
44
- t . is ( ( await readJson ( './package.json' ) ) . version , ' 1.0.0') ;
45
- t . is ( ( await readJson ( './npm-shrinkwrap.json' ) ) . version , ' 1.0.0') ;
65
+ t . is ( ( await readFile ( './package.json' ) ) . toString ( ) , pkg . replace ( '0.0.0-dev' , ' 1.0.0') ) ;
66
+ t . is ( ( await readFile ( './npm-shrinkwrap.json' ) ) . toString ( ) , shrinkwrap . replace ( '0.0.0-dev' , ' 1.0.0') ) ;
46
67
// Verify the logger has been called with the version updated
47
68
t . deepEqual ( t . context . log . args [ 0 ] , [ 'Wrote version %s to package.json' , '1.0.0' ] ) ;
48
69
t . deepEqual ( t . context . log . args [ 1 ] , [ 'Wrote version %s to npm-shrinkwrap.json' , '1.0.0' ] ) ;
0 commit comments