@@ -3,7 +3,7 @@ import {promises as fsPromises} from 'fs'
33import path from 'path'
44import { promisify } from 'util'
55import test from 'tape'
6- import vfile from 'to-vfile'
6+ import { toVFile } from 'to-vfile'
77import { processor } from './processor.js'
88
99var exec = promisify ( cp . exec )
@@ -43,7 +43,7 @@ test('diff() (travis)', function (t) {
4343 . then ( ( ) => exec ( 'git config --global user.email' ) . catch ( setEmailAndName ) )
4444 // Add initial file.
4545 . then ( ( ) =>
46- processor ( ) . process ( vfile ( { path : 'example.txt' , contents : stepOne } ) )
46+ processor ( ) . process ( toVFile ( { path : 'example.txt' , value : stepOne } ) )
4747 )
4848 . then ( ( file ) => {
4949 t . deepEqual (
@@ -52,7 +52,7 @@ test('diff() (travis)', function (t) {
5252 'should set messages'
5353 )
5454
55- return vfile . write ( file )
55+ return toVFile . write ( file )
5656 } )
5757 . then ( ( ) => exec ( 'git add example.txt' ) )
5858 . then ( ( ) => exec ( 'git commit -m one' ) )
@@ -61,16 +61,14 @@ test('diff() (travis)', function (t) {
6161 initial = result . stdout . trim ( )
6262 } )
6363 // Change files.
64- . then ( ( ) => vfile . write ( { path : 'example.txt' , contents : stepTwo } ) )
64+ . then ( ( ) => toVFile . write ( { path : 'example.txt' , value : stepTwo } ) )
6565 . then ( ( ) => exec ( 'git add example.txt' ) )
6666 . then ( ( ) => exec ( 'git commit -m two' ) )
6767 . then ( ( ) => exec ( 'git rev-parse HEAD' ) )
6868 . then ( ( result ) => {
6969 final = result . stdout . trim ( )
7070 process . env . TRAVIS_COMMIT_RANGE = [ initial , final ] . join ( '...' )
71- return processor ( ) . process (
72- vfile ( { path : 'example.txt' , contents : stepTwo } )
73- )
71+ return processor ( ) . process ( toVFile ( { path : 'example.txt' , value : stepTwo } ) )
7472 } )
7573 . then ( ( file ) => {
7674 t . deepEqual (
@@ -81,7 +79,7 @@ test('diff() (travis)', function (t) {
8179 } )
8280 // Again!
8381 . then ( ( ) =>
84- processor ( ) . process ( vfile ( { path : 'example.txt' , contents : stepTwo } ) )
82+ processor ( ) . process ( toVFile ( { path : 'example.txt' , value : stepTwo } ) )
8583 )
8684 . then ( ( file ) => {
8785 t . deepEqual (
@@ -92,7 +90,7 @@ test('diff() (travis)', function (t) {
9290 } )
9391 // Unstaged files.
9492 . then ( ( ) =>
95- processor ( ) . process ( vfile ( { path : 'missing.txt' , contents : other } ) )
93+ processor ( ) . process ( toVFile ( { path : 'missing.txt' , value : other } ) )
9694 )
9795 . then ( ( file ) => {
9896 t . deepEqual (
@@ -102,8 +100,8 @@ test('diff() (travis)', function (t) {
102100 )
103101 } )
104102 // New file.
105- . then ( ( ) => vfile . write ( { path : 'example.txt' , contents : stepThree } ) )
106- . then ( ( ) => vfile . write ( { path : 'new.txt' , contents : other } ) )
103+ . then ( ( ) => toVFile . write ( { path : 'example.txt' , value : stepThree } ) )
104+ . then ( ( ) => toVFile . write ( { path : 'new.txt' , value : other } ) )
107105 . then ( ( ) => exec ( 'git add example.txt new.txt' ) )
108106 . then ( ( ) => exec ( 'git commit -m three' ) )
109107 . then ( ( ) => exec ( 'git rev-parse HEAD' ) )
@@ -113,7 +111,7 @@ test('diff() (travis)', function (t) {
113111 process . env . TRAVIS_COMMIT_RANGE = [ initial , final ] . join ( '...' )
114112
115113 return processor ( ) . process (
116- vfile ( { path : 'example.txt' , contents : stepThree } )
114+ toVFile ( { path : 'example.txt' , value : stepThree } )
117115 )
118116 } )
119117 . then ( ( file ) => {
@@ -123,7 +121,7 @@ test('diff() (travis)', function (t) {
123121 'should deal with multiple patches'
124122 )
125123
126- return processor ( ) . process ( vfile ( { path : 'new.txt' , contents : other } ) )
124+ return processor ( ) . process ( toVFile ( { path : 'new.txt' , value : other } ) )
127125 } )
128126 . then ( ( file ) => {
129127 t . deepEqual (
@@ -132,7 +130,7 @@ test('diff() (travis)', function (t) {
132130 'should deal with new files'
133131 )
134132
135- return processor ( ) . process ( vfile ( { path : 'new.txt' , contents : other } ) )
133+ return processor ( ) . process ( toVFile ( { path : 'new.txt' , value : other } ) )
136134 } )
137135 // Restore
138136 . then ( restore , restore )
@@ -141,12 +139,15 @@ test('diff() (travis)', function (t) {
141139 ( error ) => t . ifErr ( error , 'should not fail' )
142140 )
143141
144- function restore ( ) {
142+ function restore ( error ) {
145143 delete process . env . TRAVIS_COMMIT_RANGE
146- return fsPromises
147- . rm ( '.git' , { recursive : true } )
148- . then ( ( ) => fsPromises . rm ( 'new.txt' ) )
149- . then ( ( ) => fsPromises . rm ( 'example.txt' ) )
144+ return Promise . allSettled ( [
145+ fsPromises . rm ( '.git' , { recursive : true , force : true } ) ,
146+ fsPromises . rm ( 'new.txt' , { force : true } ) ,
147+ fsPromises . rm ( 'example.txt' , { force : true } )
148+ ] ) . then ( ( ) => {
149+ if ( error instanceof Error ) throw error
150+ } )
150151 }
151152} )
152153
@@ -166,19 +167,17 @@ test('diff() (GitHub Actions)', function (t) {
166167
167168 exec ( 'git init' )
168169 // Add initial file.
169- . then ( ( ) => vfile . write ( { path : 'example.txt' , contents : stepOne } ) )
170+ . then ( ( ) => toVFile . write ( { path : 'example.txt' , value : stepOne } ) )
170171 . then ( ( ) => exec ( 'git add example.txt' ) )
171172 . then ( ( ) => exec ( 'git commit -m one' ) )
172173 // Change file.
173- . then ( ( ) => vfile . write ( { path : 'example.txt' , contents : stepTwo } ) )
174+ . then ( ( ) => toVFile . write ( { path : 'example.txt' , value : stepTwo } ) )
174175 . then ( ( ) => exec ( 'git add example.txt' ) )
175176 . then ( ( ) => exec ( 'git commit -m two' ) )
176177 . then ( ( ) => exec ( 'git rev-parse HEAD' ) )
177178 . then ( ( result ) => {
178179 process . env . GITHUB_SHA = result . stdout . trim ( )
179- return processor ( ) . process (
180- vfile ( { path : 'example.txt' , contents : stepTwo } )
181- )
180+ return processor ( ) . process ( toVFile ( { path : 'example.txt' , value : stepTwo } ) )
182181 } )
183182 . then ( ( file ) => {
184183 t . deepEqual (
@@ -194,10 +193,10 @@ test('diff() (GitHub Actions)', function (t) {
194193 exec ( 'git checkout -b other-branch' )
195194 } )
196195 // Change file.
197- . then ( ( ) => vfile . write ( { path : 'example.txt' , contents : stepThree } ) )
196+ . then ( ( ) => toVFile . write ( { path : 'example.txt' , value : stepThree } ) )
198197 . then ( ( ) => exec ( 'git add example.txt' ) )
199198 . then ( ( ) => exec ( 'git commit -m three' ) )
200- . then ( ( ) => vfile . write ( { path : 'example.txt' , contents : stepFour } ) )
199+ . then ( ( ) => toVFile . write ( { path : 'example.txt' , value : stepFour } ) )
201200 . then ( ( ) => exec ( 'git add example.txt' ) )
202201 . then ( ( ) => exec ( 'git commit -m four' ) )
203202 . then ( ( ) => exec ( 'git rev-parse HEAD' ) )
@@ -206,7 +205,7 @@ test('diff() (GitHub Actions)', function (t) {
206205 process . env . GITHUB_BASE_REF = 'refs/heads/' + main
207206 process . env . GITHUB_HEAD_REF = 'refs/heads/other-branch'
208207 return processor ( ) . process (
209- vfile ( { path : 'example.txt' , contents : stepFour } )
208+ toVFile ( { path : 'example.txt' , value : stepFour } )
210209 )
211210 } )
212211 . then ( ( file ) => {
@@ -223,13 +222,16 @@ test('diff() (GitHub Actions)', function (t) {
223222 ( error ) => t . ifErr ( error , 'should not fail' )
224223 )
225224
226- function restore ( ) {
225+ function restore ( error ) {
227226 delete process . env . GITHUB_SHA
228227 delete process . env . GITHUB_BASE_REF
229228 delete process . env . GITHUB_HEAD_REF
230- return fsPromises
231- . rm ( '.git' , { recursive : true } )
232- . then ( ( ) => fsPromises . rm ( 'example.txt' ) )
229+ return Promise . allSettled ( [
230+ fsPromises . rm ( '.git' , { recursive : true , force : true } ) ,
231+ fsPromises . rm ( 'example.txt' , { force : true } )
232+ ] ) . then ( ( ) => {
233+ if ( error instanceof Error ) throw error
234+ } )
233235 }
234236} )
235237
0 commit comments