11// @flow
2- import execa from ' execa' ;
3- import path from ' path' ;
4- import fs from 'fs' ;
5- import snapshotDiff from ' snapshot-diff' ;
6- import upgrade from ' ../upgrade' ;
7- import { fetch } from ' ../helpers' ;
8- import logger from ' ../../../tools/logger' ;
2+ import execa from " execa" ;
3+ import path from " path" ;
4+ import fs from "fs" ;
5+ import snapshotDiff from " snapshot-diff" ;
6+ import upgrade from " ../upgrade" ;
7+ import { fetch } from " ../helpers" ;
8+ import logger from " ../../../tools/logger" ;
99
10- jest . mock ( ' https' ) ;
11- jest . mock ( 'fs' ) ;
12- jest . mock ( ' path' ) ;
13- jest . mock ( ' execa' , ( ) => {
10+ jest . mock ( " https" ) ;
11+ jest . mock ( "fs" ) ;
12+ jest . mock ( " path" ) ;
13+ jest . mock ( " execa" , ( ) => {
1414 const module = jest . fn ( ( command , args ) => {
15- mockPushLog ( '$' , ' execa' , command , args ) ;
16- if ( command === ' npm' && args [ 3 ] === ' --json' ) {
15+ mockPushLog ( "$" , " execa" , command , args ) ;
16+ if ( command === " npm" && args [ 3 ] === " --json" ) {
1717 return Promise . resolve ( {
18- stdout : '{"react": "16.6.3"}' ,
18+ stdout : '{"react": "16.6.3"}'
1919 } ) ;
2020 }
21- return Promise . resolve ( { stdout : '' } ) ;
21+ return Promise . resolve ( { stdout : "" } ) ;
2222 } ) ;
2323 return module ;
2424} ) ;
2525jest . mock (
26- ' /project/root/node_modules/react-native/package.json' ,
27- ( ) => ( { name : ' react-native' , version : ' 0.57.8' } ) ,
28- { virtual : true } ,
26+ " /project/root/node_modules/react-native/package.json" ,
27+ ( ) => ( { name : " react-native" , version : " 0.57.8" } ) ,
28+ { virtual : true }
2929) ;
3030jest . mock (
31- ' /project/root/package.json' ,
32- ( ) => ( { name : ' TestApp' , dependencies : { ' react-native' : ' ^0.57.8' } } ) ,
33- { virtual : true } ,
31+ " /project/root/package.json" ,
32+ ( ) => ( { name : " TestApp" , dependencies : { " react-native" : " ^0.57.8" } } ) ,
33+ { virtual : true }
3434) ;
35- jest . mock ( ' ../../../tools/PackageManager' , ( ) =>
35+ jest . mock ( " ../../../tools/PackageManager" , ( ) =>
3636 jest . fn ( ( ) => ( {
3737 install : args => {
38- mockPushLog ( ' $ yarn add' , ...args ) ;
39- } ,
40- } ) ) ,
38+ mockPushLog ( " $ yarn add" , ...args ) ;
39+ }
40+ } ) )
4141) ;
42- jest . mock ( ' ../helpers' , ( ) => ( {
43- ...jest . requireActual ( ' ../helpers' ) ,
44- fetch : jest . fn ( ( ) => Promise . resolve ( ' patch' ) ) ,
42+ jest . mock ( " ../helpers" , ( ) => ( {
43+ ...jest . requireActual ( " ../helpers" ) ,
44+ fetch : jest . fn ( ( ) => Promise . resolve ( " patch" ) )
4545} ) ) ;
46- jest . mock ( ' ../../../tools/logger' , ( ) => ( {
47- info : jest . fn ( ( ...args ) => mockPushLog ( ' info' , args ) ) ,
48- error : jest . fn ( ( ...args ) => mockPushLog ( ' error' , args ) ) ,
49- warn : jest . fn ( ( ...args ) => mockPushLog ( ' warn' , args ) ) ,
50- success : jest . fn ( ( ...args ) => mockPushLog ( ' success' , args ) ) ,
51- log : jest . fn ( ( ...args ) => mockPushLog ( args ) ) ,
46+ jest . mock ( " ../../../tools/logger" , ( ) => ( {
47+ info : jest . fn ( ( ...args ) => mockPushLog ( " info" , args ) ) ,
48+ error : jest . fn ( ( ...args ) => mockPushLog ( " error" , args ) ) ,
49+ warn : jest . fn ( ( ...args ) => mockPushLog ( " warn" , args ) ) ,
50+ success : jest . fn ( ( ...args ) => mockPushLog ( " success" , args ) ) ,
51+ log : jest . fn ( ( ...args ) => mockPushLog ( args ) )
5252} ) ) ;
5353
54- const currentVersion = ' 0.57.8' ;
55- const newVersion = ' 0.58.4' ;
56- const olderVersion = ' 0.56.0' ;
54+ const currentVersion = " 0.57.8" ;
55+ const newVersion = " 0.58.4" ;
56+ const olderVersion = " 0.56.0" ;
5757const ctx = {
58- root : ' /project/root' ,
59- reactNativePath : '' ,
58+ root : " /project/root" ,
59+ reactNativePath : ""
6060} ;
6161const opts = {
62- legacy : false ,
62+ legacy : false
6363} ;
6464
6565const samplePatch = jest
66- . requireActual ( 'fs' )
67- . readFileSync ( path . join ( __dirname , ' ./sample.patch' ) , ' utf8' ) ;
66+ . requireActual ( "fs" )
67+ . readFileSync ( path . join ( __dirname , " ./sample.patch" ) , " utf8" ) ;
6868
6969let logs = [ ] ;
7070const mockPushLog = ( ...args ) =>
71- logs . push ( args . map ( x => ( Array . isArray ( x ) ? x . join ( ' ' ) : x ) ) . join ( ' ' ) ) ;
72- const flushOutput = ( ) => logs . join ( '\n' ) ;
71+ logs . push ( args . map ( x => ( Array . isArray ( x ) ? x . join ( " " ) : x ) ) . join ( " " ) ) ;
72+ const flushOutput = ( ) => logs . join ( "\n" ) ;
7373
7474beforeEach ( ( ) => {
7575 jest . clearAllMocks ( ) ;
7676 // $FlowFixMe
77- fs . writeFileSync = jest . fn ( filename => mockPushLog ( ' [fs] write' , filename ) ) ;
77+ fs . writeFileSync = jest . fn ( filename => mockPushLog ( " [fs] write" , filename ) ) ;
7878 // $FlowFixMe
79- fs . unlinkSync = jest . fn ( ( ...args ) => mockPushLog ( ' [fs] unlink' , args ) ) ;
79+ fs . unlinkSync = jest . fn ( ( ...args ) => mockPushLog ( " [fs] unlink" , args ) ) ;
8080 logs = [ ] ;
8181} ) ;
8282
83- test ( ' uses latest version of react-native when none passed' , async ( ) => {
83+ test ( " uses latest version of react-native when none passed" , async ( ) => {
8484 await upgrade . func ( [ ] , ctx , opts ) ;
85- expect ( execa ) . toBeCalledWith ( ' npm' , [ ' info' , ' react-native' , ' version' ] ) ;
85+ expect ( execa ) . toBeCalledWith ( " npm" , [ " info" , " react-native" , " version" ] ) ;
8686} ) ;
8787
88- test ( ' errors when invalid version passed' , async ( ) => {
89- await upgrade . func ( [ ' next' ] , ctx , opts ) ;
88+ test ( " errors when invalid version passed" , async ( ) => {
89+ await upgrade . func ( [ " next" ] , ctx , opts ) ;
9090 expect ( logger . error ) . toBeCalledWith (
91- 'Provided version "next" is not allowed. Please pass a valid semver version' ,
91+ 'Provided version "next" is not allowed. Please pass a valid semver version'
9292 ) ;
9393} ) ;
9494
95- test ( ' errors when older version passed' , async ( ) => {
95+ test ( " errors when older version passed" , async ( ) => {
9696 await upgrade . func ( [ olderVersion ] , ctx , opts ) ;
9797 expect ( logger . error ) . toBeCalledWith (
98- `Trying to upgrade from newer version "${ currentVersion } " to older "${ olderVersion } "` ,
98+ `Trying to upgrade from newer version "${ currentVersion } " to older "${ olderVersion } "`
9999 ) ;
100100} ) ;
101101
102- test ( ' warns when dependency upgrade version is in semver range' , async ( ) => {
102+ test ( " warns when dependency upgrade version is in semver range" , async ( ) => {
103103 await upgrade . func ( [ currentVersion ] , ctx , opts ) ;
104104 expect ( logger . warn ) . toBeCalledWith (
105- `Specified version "${ currentVersion } " is already installed in node_modules and it satisfies "^0.57.8" semver range. No need to upgrade` ,
105+ `Specified version "${ currentVersion } " is already installed in node_modules and it satisfies "^0.57.8" semver range. No need to upgrade`
106106 ) ;
107107} ) ;
108108
109- test ( ' fetches empty patch and installs deps' , async ( ) => {
110- ( fetch : any ) . mockImplementation ( ( ) => Promise . resolve ( '' ) ) ;
109+ test ( " fetches empty patch and installs deps" , async ( ) => {
110+ ( fetch : any ) . mockImplementation ( ( ) => Promise . resolve ( "" ) ) ;
111111 await upgrade . func ( [ newVersion ] , ctx , opts ) ;
112112 expect ( flushOutput ( ) ) . toMatchInlineSnapshot ( `
113113"info Fetching diff between v0.57.8 and v0.58.4...
@@ -123,13 +123,13 @@ success Upgraded React Native to v0.58.4 🎉. Now you can review and commit the
123123` ) ;
124124} ) ;
125125
126- test ( ' fetches regular patch, adds remote, applies patch, installs deps, removes remote,' , async ( ) => {
126+ test ( " fetches regular patch, adds remote, applies patch, installs deps, removes remote," , async ( ) => {
127127 ( fetch : any ) . mockImplementation ( ( ) => Promise . resolve ( samplePatch ) ) ;
128128 await upgrade . func ( [ newVersion ] , ctx , opts ) ;
129129 expect ( flushOutput ( ) ) . toMatchInlineSnapshot ( `
130130"info Fetching diff between v0.57.8 and v0.58.4...
131131[fs] write tmp-upgrade-rn.patch
132- $ execa git remote add tmp-rn-diff-purge https://github.com/pvinis /rn-diff-purge.git
132+ $ execa git remote add tmp-rn-diff-purge https://github.com/react-native-community /rn-diff-purge.git
133133$ execa git fetch --no-tags tmp-rn-diff-purge
134134$ execa git apply --check tmp-upgrade-rn.patch --exclude=package.json -p2 --3way
135135info Applying diff...
@@ -148,45 +148,45 @@ success Upgraded React Native to v0.58.4 🎉. Now you can review and commit the
148148` ) ;
149149 expect (
150150 snapshotDiff ( samplePatch , fs . writeFileSync . mock . calls [ 0 ] [ 1 ] , {
151- contextLines : 1 ,
152- } ) ,
153- ) . toMatchSnapshot ( ' RnDiffApp is replaced with app name (TestApp)' ) ;
151+ contextLines : 1
152+ } )
153+ ) . toMatchSnapshot ( " RnDiffApp is replaced with app name (TestApp)" ) ;
154154} ) ;
155- test ( ' cleans up if patching fails,' , async ( ) => {
155+ test ( " cleans up if patching fails," , async ( ) => {
156156 ( fetch : any ) . mockImplementation ( ( ) => Promise . resolve ( samplePatch ) ) ;
157157 ( execa : any ) . mockImplementation ( ( command , args ) => {
158- mockPushLog ( '$' , ' execa' , command , args ) ;
159- if ( command === ' npm' && args [ 3 ] === ' --json' ) {
158+ mockPushLog ( "$" , " execa" , command , args ) ;
159+ if ( command === " npm" && args [ 3 ] === " --json" ) {
160160 return Promise . resolve ( {
161- stdout : '{"react": "16.6.3"}' ,
161+ stdout : '{"react": "16.6.3"}'
162162 } ) ;
163163 }
164- if ( command === ' git' && args [ 0 ] === ' apply' ) {
164+ if ( command === " git" && args [ 0 ] === " apply" ) {
165165 return Promise . reject ( {
166166 code : 1 ,
167- stderr : ' error: .flowconfig: does not exist in index\n' ,
167+ stderr : " error: .flowconfig: does not exist in index\n"
168168 } ) ;
169169 }
170- return Promise . resolve ( { stdout : '' } ) ;
170+ return Promise . resolve ( { stdout : "" } ) ;
171171 } ) ;
172172 try {
173173 await upgrade . func ( [ newVersion ] , ctx , opts ) ;
174174 } catch ( error ) {
175175 expect ( error . message ) . toBe (
176- ' Upgrade failed. Please see the messages above for details' ,
176+ " Upgrade failed. Please see the messages above for details"
177177 ) ;
178178 }
179179 expect ( flushOutput ( ) ) . toMatchInlineSnapshot ( `
180180"info Fetching diff between v0.57.8 and v0.58.4...
181181[fs] write tmp-upgrade-rn.patch
182- $ execa git remote add tmp-rn-diff-purge https://github.com/pvinis /rn-diff-purge.git
182+ $ execa git remote add tmp-rn-diff-purge https://github.com/react-native-community /rn-diff-purge.git
183183$ execa git fetch --no-tags tmp-rn-diff-purge
184184$ execa git apply --check tmp-upgrade-rn.patch --exclude=package.json -p2 --3way
185185info Applying diff (excluding: package.json, .flowconfig)...
186186$ execa git apply tmp-upgrade-rn.patch --exclude=package.json --exclude=.flowconfig -p2 --3way
187187[2merror: .flowconfig: does not exist in index[22m
188188error Automatically applying diff failed
189- info Here's the diff we tried to apply: https://github.com/pvinis /rn-diff-purge/compare/version/0.57.8...version/0.58.4
189+ info Here's the diff we tried to apply: https://github.com/react-native-community /rn-diff-purge/compare/version/0.57.8...version/0.58.4
190190info You may find release notes helpful: https://github.com/facebook/react-native/releases/tag/v0.58.4
191191[fs] unlink tmp-upgrade-rn.patch
192192warn Continuing after failure. Most of the files are upgraded but you will need to deal with some conflicts manually
0 commit comments