Skip to content

Commit

Permalink
chore: remove touch as dev dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak committed Nov 5, 2023
1 parent ee2b70e commit ed36b9b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 59 deletions.
48 changes: 0 additions & 48 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Expand Up @@ -132,7 +132,6 @@
"sinon": "^9.0.3",
"strip-ansi": "^6.0.0",
"svgo": "^1.3.2",
"touch": "^3.1.0",
"unexpected": "^11.14.0",
"unexpected-eventemitter": "^2.2.0",
"unexpected-map": "^2.0.0",
Expand Down
27 changes: 17 additions & 10 deletions test/integration/helpers.js
Expand Up @@ -2,12 +2,12 @@

const escapeRegExp = require('escape-string-regexp');
const os = require('os');
const fs = require('fs-extra');
const fs = require('fs');
const fsExtra = require('fs-extra');
const {format} = require('util');
const path = require('path');
const Base = require('../../lib/reporters/base');
const debug = require('debug')('mocha:test:integration:helpers');
const touch = require('touch');

/**
* Path to `mocha` executable
Expand Down Expand Up @@ -479,15 +479,22 @@ async function runMochaWatchJSONAsync(args, opts, change) {
);
}

const touchRef = new Date();

/**
* Synchronously touch a file. Creates
* the file and all its parent directories if necessary.
*
* @param {string} filepath - Path to file
*/
function touchFile(filepath) {
fs.ensureDirSync(path.dirname(filepath));
touch.sync(filepath);
fsExtra.ensureDirSync(path.dirname(filepath));
try {
fs.utimesSync(filepath, touchRef, touchRef);
} catch (e) {
const fd = fs.openSync(filepath, 'a');
fs.closeSync(fd);
}
}

/**
Expand All @@ -499,9 +506,9 @@ function touchFile(filepath) {
* @param {string} replacement - Replacement
*/
function replaceFileContents(filepath, pattern, replacement) {
const contents = fs.readFileSync(filepath, 'utf-8');
const contents = fsExtra.readFileSync(filepath, 'utf-8');
const newContents = contents.replace(pattern, replacement);
fs.writeFileSync(filepath, newContents, 'utf-8');
fsExtra.writeFileSync(filepath, newContents, 'utf-8');
}

/**
Expand All @@ -513,21 +520,21 @@ function replaceFileContents(filepath, pattern, replacement) {
*/
function copyFixture(fixtureName, dest) {
const fixtureSource = resolveFixturePath(fixtureName);
fs.ensureDirSync(path.dirname(dest));
fs.copySync(fixtureSource, dest);
fsExtra.ensureDirSync(path.dirname(dest));
fsExtra.copySync(fixtureSource, dest);
}

/**
* Creates a temporary directory
* @returns {Promise<CreateTempDirResult>} Temp dir path and cleanup function
*/
const createTempDir = async () => {
const dirpath = await fs.mkdtemp(path.join(os.tmpdir(), 'mocha-'));
const dirpath = await fsExtra.mkdtemp(path.join(os.tmpdir(), 'mocha-'));
return {
dirpath,
removeTempDir: async () => {
if (!process.env.MOCHA_TEST_KEEP_TEMP_DIRS) {
return fs.remove(dirpath);
return fsExtra.remove(dirpath);
}
}
};
Expand Down

0 comments on commit ed36b9b

Please sign in to comment.