22
33const escapeRegExp = require ( 'escape-string-regexp' ) ;
44const os = require ( 'os' ) ;
5- const fs = require ( 'fs-extra' ) ;
5+ const fs = require ( 'fs' ) ;
6+ const fsExtra = require ( 'fs-extra' ) ;
67const { format} = require ( 'util' ) ;
78const path = require ( 'path' ) ;
89const Base = require ( '../../lib/reporters/base' ) ;
910const debug = require ( 'debug' ) ( 'mocha:test:integration:helpers' ) ;
10- const touch = require ( 'touch' ) ;
1111
1212/**
1313 * Path to `mocha` executable
@@ -479,15 +479,22 @@ async function runMochaWatchJSONAsync(args, opts, change) {
479479 ) ;
480480}
481481
482+ const touchRef = new Date ( ) ;
483+
482484/**
483485 * Synchronously touch a file. Creates
484486 * the file and all its parent directories if necessary.
485487 *
486488 * @param {string } filepath - Path to file
487489 */
488490function touchFile ( filepath ) {
489- fs . ensureDirSync ( path . dirname ( filepath ) ) ;
490- touch . sync ( filepath ) ;
491+ fsExtra . ensureDirSync ( path . dirname ( filepath ) ) ;
492+ try {
493+ fs . utimesSync ( filepath , touchRef , touchRef ) ;
494+ } catch ( e ) {
495+ const fd = fs . openSync ( filepath , 'a' ) ;
496+ fs . closeSync ( fd ) ;
497+ }
491498}
492499
493500/**
@@ -499,9 +506,9 @@ function touchFile(filepath) {
499506 * @param {string } replacement - Replacement
500507 */
501508function replaceFileContents ( filepath , pattern , replacement ) {
502- const contents = fs . readFileSync ( filepath , 'utf-8' ) ;
509+ const contents = fsExtra . readFileSync ( filepath , 'utf-8' ) ;
503510 const newContents = contents . replace ( pattern , replacement ) ;
504- fs . writeFileSync ( filepath , newContents , 'utf-8' ) ;
511+ fsExtra . writeFileSync ( filepath , newContents , 'utf-8' ) ;
505512}
506513
507514/**
@@ -513,21 +520,21 @@ function replaceFileContents(filepath, pattern, replacement) {
513520 */
514521function copyFixture ( fixtureName , dest ) {
515522 const fixtureSource = resolveFixturePath ( fixtureName ) ;
516- fs . ensureDirSync ( path . dirname ( dest ) ) ;
517- fs . copySync ( fixtureSource , dest ) ;
523+ fsExtra . ensureDirSync ( path . dirname ( dest ) ) ;
524+ fsExtra . copySync ( fixtureSource , dest ) ;
518525}
519526
520527/**
521528 * Creates a temporary directory
522529 * @returns {Promise<CreateTempDirResult> } Temp dir path and cleanup function
523530 */
524531const createTempDir = async ( ) => {
525- const dirpath = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , 'mocha-' ) ) ;
532+ const dirpath = await fsExtra . mkdtemp ( path . join ( os . tmpdir ( ) , 'mocha-' ) ) ;
526533 return {
527534 dirpath,
528535 removeTempDir : async ( ) => {
529536 if ( ! process . env . MOCHA_TEST_KEEP_TEMP_DIRS ) {
530- return fs . remove ( dirpath ) ;
537+ return fsExtra . remove ( dirpath ) ;
531538 }
532539 }
533540 } ;
0 commit comments