@@ -3,7 +3,7 @@ import * as path from "path"
33
44import { spawnSafeSync } from "../src/spawnSafe"
55import { executeEffects } from "../src/patch/apply"
6- import { parsePatch } from "../src/patch/parse"
6+ import { parsePatchFile } from "../src/patch/parse"
77import { reversePatch } from "../src/patch/reverse"
88
99import { TestCase , Files } from "./testCases"
@@ -38,6 +38,11 @@ jest.mock("fs-extra", () => {
3838 getWorkingFiles ( ) [ to ] = getWorkingFiles ( ) [ from ]
3939 delete getWorkingFiles ( ) [ from ]
4040 } ) ,
41+ statSync : jest . fn ( path => getWorkingFiles ( ) [ path ] ) ,
42+ chmodSync : jest . fn ( ( path , mode ) => {
43+ const { contents } = getWorkingFiles ( ) [ path ]
44+ getWorkingFiles ( ) [ path ] = { contents, mode }
45+ } ) ,
4146 }
4247} )
4348
@@ -85,12 +90,14 @@ export function executeTestCase(testCase: TestCase) {
8590 writeFiles ( tmpDir . name , testCase . cleanFiles )
8691
8792 spawnSafeSync ( "git" , [ "add" , "-A" ] , { cwd : tmpDir . name } )
88- spawnSafeSync ( "git" , [ "commit" , "-m" , "blah" ] , {
89- cwd : tmpDir . name ,
90- } )
91- spawnSafeSync ( "git" , [ "rm" , "-rf" , "*" ] , {
93+ spawnSafeSync ( "git" , [ "commit" , "--allow-empty" , "-m" , "blah" ] , {
9294 cwd : tmpDir . name ,
9395 } )
96+ if ( Object . keys ( testCase . cleanFiles ) . length > 0 ) {
97+ spawnSafeSync ( "git" , [ "rm" , "-rf" , "*" ] , {
98+ cwd : tmpDir . name ,
99+ } )
100+ }
94101
95102 writeFiles ( tmpDir . name , testCase . modifiedFiles )
96103 spawnSafeSync ( "git" , [ "add" , "-A" ] , { cwd : tmpDir . name } )
@@ -113,8 +120,8 @@ export function executeTestCase(testCase: TestCase) {
113120
114121 it ( "looks the same whether parsed with blank lines or not" , ( ) => {
115122 reportingFailures ( ( ) => {
116- expect ( parsePatch ( patchFileContents ) ) . toEqual (
117- parsePatch ( patchFileContentsWithBlankLines ) ,
123+ expect ( parsePatchFile ( patchFileContents ) ) . toEqual (
124+ parsePatchFile ( patchFileContentsWithBlankLines ) ,
118125 )
119126 } )
120127 } )
@@ -124,7 +131,7 @@ export function executeTestCase(testCase: TestCase) {
124131 it ( "works forwards" , ( ) => {
125132 fs . setWorkingFiles ( { ...testCase . cleanFiles } )
126133 reportingFailures ( ( ) => {
127- const effects = parsePatch ( patchFileContents )
134+ const effects = parsePatchFile ( patchFileContents )
128135 executeEffects ( effects , { dryRun : false } )
129136 expect ( fs . getWorkingFiles ( ) ) . toEqual ( testCase . modifiedFiles )
130137 } )
@@ -133,7 +140,7 @@ export function executeTestCase(testCase: TestCase) {
133140 it ( "works backwards" , ( ) => {
134141 fs . setWorkingFiles ( { ...testCase . modifiedFiles } )
135142 reportingFailures ( ( ) => {
136- const effects = reversePatch ( parsePatch ( patchFileContents ) )
143+ const effects = reversePatch ( parsePatchFile ( patchFileContents ) )
137144 executeEffects ( effects , { dryRun : false } )
138145 expect ( fs . getWorkingFiles ( ) ) . toEqual ( testCase . cleanFiles )
139146 } )
0 commit comments