@@ -6,6 +6,7 @@ import pathExists from 'path-exists';
66import readPkg from 'read-pkg' ;
77// import copy from 'cpy';
88import tempfile from 'tempfile' ;
9+ import rimraf from 'rimraf' ;
910
1011const cli = path . resolve ( 'lib/cli.js' ) ;
1112const read = file => new Promise ( ( resolve , reject ) => {
@@ -148,111 +149,127 @@ test('Transform html stdin options use witch modules', async t => {
148149} ) ;
149150
150151test ( 'Transform html stdin options' , async t => {
152+ const outputPath = 'test/expected/by-config/options/output.html' ;
153+ rimraf . sync ( outputPath ) ;
151154 t . plan ( 2 ) ;
152155 await execa ( cli , [
153156 '-c' ,
154157 'test/fixtures/by-config/options/.config'
155158 ] ) ;
156- t . true ( await pathExists ( 'test/expected/by-config/options/output.html' ) ) ;
159+ t . true ( await pathExists ( outputPath ) ) ;
157160 t . is (
158- ( await read ( 'test/expected/by-config/options/output.html' ) ) ,
161+ ( await read ( outputPath ) ) ,
159162 ( await read ( 'test/fixtures/by-config/options/input.html' ) )
160163 ) ;
161164} ) ;
162165
163166test ( 'Transform html stdin options only config one-io' , async t => {
167+ const outputPath = 'test/expected/by-config/one-io/output.html' ;
168+ rimraf . sync ( outputPath ) ;
164169 t . plan ( 2 ) ;
165170 await execa ( cli , [
166171 '-c' ,
167172 'test/fixtures/by-config/one-io/.config'
168173 ] ) ;
169- t . true ( await pathExists ( 'test/expected/by-config/one-io/output.html' ) ) ;
174+ t . true ( await pathExists ( outputPath ) ) ;
170175 t . is (
171- ( await read ( 'test/expected/by-config/one-io/output.html' ) ) ,
176+ ( await read ( outputPath ) ) ,
172177 ( await read ( 'test/fixtures/by-config/one-io/input.html' ) )
173178 ) ;
174179} ) ;
175180
176181test ( 'Transform html stdin options only config two-io to dir' , async t => {
182+ const outputPath1 = 'test/expected/by-config/two-io/input-1.html' ;
183+ const outputPath2 = 'test/expected/by-config/two-io/input-2.html' ;
184+ rimraf . sync ( outputPath1 ) ;
185+ rimraf . sync ( outputPath2 ) ;
177186 t . plan ( 4 ) ;
178187 await execa ( cli , [
179188 '-c' ,
180189 'test/fixtures/by-config/two-io/.config'
181190 ] ) ;
182- t . true ( await pathExists ( 'test/expected/by-config/two-io/input-1.html' ) ) ;
183- t . true ( await pathExists ( 'test/expected/by-config/two-io/input-2.html' ) ) ;
191+ t . true ( await pathExists ( outputPath1 ) ) ;
192+ t . true ( await pathExists ( outputPath2 ) ) ;
184193 t . is (
185- ( await read ( 'test/expected/by-config/two-io/input-1.html' ) ) ,
194+ ( await read ( outputPath1 ) ) ,
186195 ( await read ( 'test/fixtures/by-config/two-io/input-1.html' ) )
187196 ) ;
188197 t . is (
189- ( await read ( 'test/expected/by-config/two-io/input-2.html' ) ) ,
198+ ( await read ( outputPath2 ) ) ,
190199 ( await read ( 'test/fixtures/by-config/two-io/input-2.html' ) )
191200 ) ;
192201} ) ;
193202
194203test ( 'Transform html stdin options only config one-io-by-pattern' , async t => {
204+ const outputPath = 'test/expected/by-config/one-io-by-pattern/input-1.html' ;
205+ rimraf . sync ( outputPath ) ;
195206 t . plan ( 2 ) ;
196207 await execa ( cli , [
197208 '-c' ,
198209 'test/fixtures/by-config/one-io-by-pattern/.config'
199210 ] ) ;
200- t . true ( await pathExists ( 'test/expected/by-config/one-io-by-pattern/input-1.html' ) ) ;
211+ t . true ( await pathExists ( outputPath ) ) ;
201212 t . is (
202- ( await read ( 'test/expected/by-config/one-io-by-pattern/input-1.html' ) ) ,
213+ ( await read ( outputPath ) ) ,
203214 ( await read ( 'test/fixtures/by-config/one-io-by-pattern/input-1.html' ) )
204215 ) ;
205216} ) ;
206217
207218test ( 'Transform html stdin options only config one-io anf plugins array' , async t => {
219+ const outputPath = 'test/expected/by-config/one-io-and-plugins-array/output.html' ;
220+ rimraf . sync ( outputPath ) ;
208221 t . plan ( 2 ) ;
209222 await execa ( cli , [
210223 '-c' ,
211224 'test/fixtures/by-config/one-io-and-plugins-array/posthtml.config.js'
212225 ] ) ;
213- t . true ( await pathExists ( 'test/expected/by-config/one-io-and-plugins-array/output.html' ) ) ;
226+ t . true ( await pathExists ( outputPath ) ) ;
214227 t . is (
215- ( await read ( 'test/expected/by-config/one-io-and-plugins-array/output.html' ) ) ,
228+ ( await read ( outputPath ) ) ,
216229 ( await read ( 'test/fixtures/by-config/one-io-and-plugins-array/input.html' ) )
217230 ) ;
218231} ) ;
219232
220233test ( 'Output with keeping the folder structure with allInOutput option' , async t => {
234+ const outputPath = 'test/expected/output-nesting' ;
235+ rimraf . sync ( outputPath ) ;
221236 t . plan ( 3 ) ;
222237 await execa ( cli , [
223238 'test/fixtures/input-nesting/**/*.html' ,
224239 '-o' ,
225- 'test/expected/output-nesting' ,
240+ outputPath ,
226241 '-a'
227242 ] ) ;
228- t . true ( await pathExists ( 'test/expected/output-nesting' ) ) ;
243+ t . true ( await pathExists ( outputPath ) ) ;
229244 t . is (
230245 ( await read ( 'test/fixtures/input-nesting/input-nesting.html' ) ) ,
231- ( await read ( 'test/expected/output-nesting/ test/fixtures/input-nesting/input-nesting.html' ) )
246+ ( await read ( ` ${ outputPath } / test/fixtures/input-nesting/input-nesting.html` ) )
232247 ) ;
233248 t . is (
234249 ( await read ( 'test/fixtures/input-nesting/input-nesting-child/input-nesting.html' ) ) ,
235- ( await read ( 'test/expected/output-nesting/ test/fixtures/input-nesting/input-nesting-child/input-nesting.html' ) )
250+ ( await read ( ` ${ outputPath } / test/fixtures/input-nesting/input-nesting-child/input-nesting.html` ) )
236251 ) ;
237252} ) ;
238253
239254test ( 'Specify the root of the output folder structure with root option' , async t => {
255+ const outputPath = 'test/expected/output-nesting-root' ;
256+ rimraf . sync ( outputPath ) ;
240257 t . plan ( 3 ) ;
241258 await execa ( cli , [
242- 'test/fixtures/input-nesting/ **/*.html' ,
259+ '**/*.html' ,
243260 '-o' ,
244- 'test/expected/output-nesting-root' ,
261+ outputPath ,
245262 '-a' ,
246263 '-r' ,
247264 'test/fixtures/input-nesting'
248265 ] ) ;
249- t . true ( await pathExists ( 'test/expected/output-nesting-root' ) ) ;
266+ t . true ( await pathExists ( outputPath ) ) ;
250267 t . is (
251268 ( await read ( 'test/fixtures/input-nesting/input-nesting.html' ) ) ,
252- ( await read ( 'test/expected/output-nesting-root/ input-nesting.html' ) )
269+ ( await read ( ` ${ outputPath } / input-nesting.html` ) )
253270 ) ;
254271 t . is (
255272 ( await read ( 'test/fixtures/input-nesting/input-nesting-child/input-nesting.html' ) ) ,
256- ( await read ( 'test/expected/output-nesting-root/ input-nesting-child/input-nesting.html' ) )
273+ ( await read ( ` ${ outputPath } / input-nesting-child/input-nesting.html` ) )
257274 ) ;
258275} ) ;
0 commit comments