99
1010'use strict'
1111
12- const fs = require ( 'fs' )
12+ const { writeFile } = require ( 'fs' )
1313const pad = require ( 'pad-left' )
14- const path = require ( 'path' )
14+ const { dirname , isAbsolute , join } = require ( 'path' )
1515const mkdirp = require ( 'mkdirp' )
1616const nodeCleanup = require ( 'node-cleanup' )
1717const instructions = [
@@ -138,9 +138,9 @@ module.exports = grunt => {
138138 . reduce ( ( scenarios , scenario ) =>
139139 scenarios . concat ( grunt . file . expand ( scenario ) ) , [ ] )
140140 . reduce ( ( scenarios , scenario ) => {
141- grunt . verbose . writeln ( 'Load scenario "' + scenario + '".' )
142- if ( ! path . isAbsolute ( scenario ) ) {
143- scenario = path . join ( currentDirectory , scenario )
141+ grunt . log . ok ( 'Load scenario "' + scenario + '".' )
142+ if ( ! isAbsolute ( scenario ) ) {
143+ scenario = join ( currentDirectory , scenario )
144144 }
145145 return scenarios . concat ( require ( scenario ) )
146146 } , commands || [ ] )
@@ -263,15 +263,16 @@ module.exports = grunt => {
263263 if ( file ) {
264264 let fileName = file . toLowerCase ( )
265265 fileName = fileName . endsWith ( '.html' ) ||
266- fileName . endsWith ( '.htm' ) ? file : file + '.html'
266+ fileName . endsWith ( '.htm' ) ? file : file + '.html'
267267 if ( fileNumbering ) {
268268 fileName = numberFileName ( fileName )
269269 }
270- fileName = path . join ( snapshots , fileName )
270+ fileName = join ( snapshots , fileName )
271271 grunt . log . ok ( 'Write snapshot to "' + fileName + '".' )
272- return ensureDirectory ( snapshots )
272+ const directory = dirname ( fileName )
273+ return ensureDirectory ( directory )
273274 . then ( ( ) => new Promise ( ( resolve , reject ) =>
274- fs . writeFile ( fileName , commandOptions . doctype + html ,
275+ writeFile ( fileName , commandOptions . doctype + html ,
275276 error => {
276277 if ( error ) {
277278 reject ( error )
@@ -294,11 +295,12 @@ module.exports = grunt => {
294295 if ( fileNumbering ) {
295296 fileName = numberFileName ( fileName )
296297 }
297- fileName = path . join ( screenshots , fileName + '.png' )
298+ fileName = join ( screenshots , fileName + '.png' )
298299 grunt . log . ok ( 'Write screenshot to "' + fileName + '".' )
299- return ensureDirectory ( screenshots )
300+ const directory = dirname ( fileName )
301+ return ensureDirectory ( directory )
300302 . then ( ( ) => new Promise ( ( resolve , reject ) =>
301- fs . writeFile ( fileName , Buffer . from ( png . value , 'base64' ) ,
303+ writeFile ( fileName , Buffer . from ( png . value , 'base64' ) ,
302304 error => {
303305 if ( error ) {
304306 reject ( error )
0 commit comments