1
- 'use strict'
2
-
3
- var cp = require ( 'child_process' )
4
- var path = require ( 'path' )
5
- var promisify = require ( 'util' ) . promisify
6
- var test = require ( 'tape' )
7
- var rimraf = promisify ( require ( 'rimraf' ) )
8
- var vfile = require ( 'to-vfile' )
9
- var processor = require ( './processor.js' ) ( )
1
+ import cp from 'child_process'
2
+ import { promises as fsPromises } from 'fs'
3
+ import path from 'path'
4
+ import { promisify } from 'util'
5
+ import test from 'tape'
6
+ import vfile from 'to-vfile'
7
+ import { processor } from './processor.js'
10
8
11
9
var exec = promisify ( cp . exec )
12
10
@@ -45,7 +43,7 @@ test('diff() (travis)', function (t) {
45
43
. then ( ( ) => exec ( 'git config --global user.email' ) . catch ( setEmailAndName ) )
46
44
// Add initial file.
47
45
. then ( ( ) =>
48
- processor . process ( vfile ( { path : 'example.txt' , contents : stepOne } ) )
46
+ processor ( ) . process ( vfile ( { path : 'example.txt' , contents : stepOne } ) )
49
47
)
50
48
. then ( ( file ) => {
51
49
t . deepEqual (
@@ -70,7 +68,9 @@ test('diff() (travis)', function (t) {
70
68
. then ( ( result ) => {
71
69
final = result . stdout . trim ( )
72
70
process . env . TRAVIS_COMMIT_RANGE = [ initial , final ] . join ( '...' )
73
- return processor . process ( vfile ( { path : 'example.txt' , contents : stepTwo } ) )
71
+ return processor ( ) . process (
72
+ vfile ( { path : 'example.txt' , contents : stepTwo } )
73
+ )
74
74
} )
75
75
. then ( ( file ) => {
76
76
t . deepEqual (
@@ -81,7 +81,7 @@ test('diff() (travis)', function (t) {
81
81
} )
82
82
// Again!
83
83
. then ( ( ) =>
84
- processor . process ( vfile ( { path : 'example.txt' , contents : stepTwo } ) )
84
+ processor ( ) . process ( vfile ( { path : 'example.txt' , contents : stepTwo } ) )
85
85
)
86
86
. then ( ( file ) => {
87
87
t . deepEqual (
@@ -92,7 +92,7 @@ test('diff() (travis)', function (t) {
92
92
} )
93
93
// Unstaged files.
94
94
. then ( ( ) =>
95
- processor . process ( vfile ( { path : 'missing.txt' , contents : other } ) )
95
+ processor ( ) . process ( vfile ( { path : 'missing.txt' , contents : other } ) )
96
96
)
97
97
. then ( ( file ) => {
98
98
t . deepEqual (
@@ -112,7 +112,7 @@ test('diff() (travis)', function (t) {
112
112
113
113
process . env . TRAVIS_COMMIT_RANGE = [ initial , final ] . join ( '...' )
114
114
115
- return processor . process (
115
+ return processor ( ) . process (
116
116
vfile ( { path : 'example.txt' , contents : stepThree } )
117
117
)
118
118
} )
@@ -123,7 +123,7 @@ test('diff() (travis)', function (t) {
123
123
'should deal with multiple patches'
124
124
)
125
125
126
- return processor . process ( vfile ( { path : 'new.txt' , contents : other } ) )
126
+ return processor ( ) . process ( vfile ( { path : 'new.txt' , contents : other } ) )
127
127
} )
128
128
. then ( ( file ) => {
129
129
t . deepEqual (
@@ -132,7 +132,7 @@ test('diff() (travis)', function (t) {
132
132
'should deal with new files'
133
133
)
134
134
135
- return processor . process ( vfile ( { path : 'new.txt' , contents : other } ) )
135
+ return processor ( ) . process ( vfile ( { path : 'new.txt' , contents : other } ) )
136
136
} )
137
137
// Restore
138
138
. then ( restore , restore )
@@ -143,9 +143,10 @@ test('diff() (travis)', function (t) {
143
143
144
144
function restore ( ) {
145
145
delete process . env . TRAVIS_COMMIT_RANGE
146
- return rimraf ( '.git' )
147
- . then ( ( ) => rimraf ( 'new.txt' ) )
148
- . then ( ( ) => rimraf ( 'example.txt' ) )
146
+ return fsPromises
147
+ . rm ( '.git' , { recursive : true } )
148
+ . then ( ( ) => fsPromises . rm ( 'new.txt' ) )
149
+ . then ( ( ) => fsPromises . rm ( 'example.txt' ) )
149
150
}
150
151
} )
151
152
@@ -175,7 +176,9 @@ test('diff() (GitHub Actions)', function (t) {
175
176
. then ( ( ) => exec ( 'git rev-parse HEAD' ) )
176
177
. then ( ( result ) => {
177
178
process . env . GITHUB_SHA = result . stdout . trim ( )
178
- return processor . process ( vfile ( { path : 'example.txt' , contents : stepTwo } ) )
179
+ return processor ( ) . process (
180
+ vfile ( { path : 'example.txt' , contents : stepTwo } )
181
+ )
179
182
} )
180
183
. then ( ( file ) => {
181
184
t . deepEqual (
@@ -202,7 +205,9 @@ test('diff() (GitHub Actions)', function (t) {
202
205
process . env . GITHUB_SHA = result . stdout . trim ( )
203
206
process . env . GITHUB_BASE_REF = 'refs/heads/' + main
204
207
process . env . GITHUB_HEAD_REF = 'refs/heads/other-branch'
205
- return processor . process ( vfile ( { path : 'example.txt' , contents : stepFour } ) )
208
+ return processor ( ) . process (
209
+ vfile ( { path : 'example.txt' , contents : stepFour } )
210
+ )
206
211
} )
207
212
. then ( ( file ) => {
208
213
t . deepEqual (
@@ -222,7 +227,9 @@ test('diff() (GitHub Actions)', function (t) {
222
227
delete process . env . GITHUB_SHA
223
228
delete process . env . GITHUB_BASE_REF
224
229
delete process . env . GITHUB_HEAD_REF
225
- return rimraf ( '.git' ) . then ( ( ) => rimraf ( 'example.txt' ) )
230
+ return fsPromises
231
+ . rm ( '.git' , { recursive : true } )
232
+ . then ( ( ) => fsPromises . rm ( 'example.txt' ) )
226
233
}
227
234
} )
228
235
0 commit comments