Skip to content

Commit

Permalink
Merge pull request #40 from jaredwray/removing-del-module-as-no-longe…
Browse files Browse the repository at this point in the history
…r-needed

removing del module as no longer needed
  • Loading branch information
jaredwray committed Nov 16, 2023
2 parents d9398b0 + b459d8e commit 2eefad8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"devDependencies": {
"c8": "^8.0.1",
"chai": "^4.3.10",
"del": "^6.0.0",
"eslint": "^8.50.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-mocha": "^10.2.0",
Expand Down
36 changes: 26 additions & 10 deletions test/specs/cache.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var expect = require('chai').expect;
var path = require('path');
var write = require('write').sync;
var fs = require('fs');
var fileEntryCache = require('../../cache');

function expand() {
Expand All @@ -11,8 +12,27 @@ function expand() {
});
}

function deleteFileSync(filePath) {
if (fs.existsSync(filePath)) {
const stats = fs.statSync(filePath);

if (stats.isDirectory()) {
// Recursively delete directory contents
fs.readdirSync(filePath).forEach(file => {
const curPath = path.join(filePath, file);
deleteFileSync(curPath);
});

// Delete the directory itself
fs.rmdirSync(filePath);
} else {
// Delete file
fs.unlinkSync(filePath);
}
}
}

var fixturesDir = path.resolve(__dirname, '../fixtures');
var del = require('del').sync;

var fixtureFiles = [
{
Expand All @@ -36,7 +56,7 @@ var fixtureFiles = [
var cache;

var delCacheAndFiles = function () {
del(fixturesDir, { force: true });
deleteFileSync(fixturesDir);
cache && cache.deleteCacheFile();
};

Expand Down Expand Up @@ -250,19 +270,15 @@ describe('file-entry-cache', function () {
var files = expand(path.resolve(__dirname, '../fixtures/*.txt'));
cache.normalizeEntries(files);

del(path.resolve(__dirname, '../fixtures/f2.txt'), {
force: true,
});
deleteFileSync(path.resolve(__dirname, '../fixtures/f2.txt'));

cache.reconcile();

// the f2.txt file is in the cache
expect(cache.cache.getKey(path.resolve(__dirname, '../fixtures/f2.txt'))).to.equal(undefined);

// now delete the entry
del(path.resolve(__dirname, '../fixtures/f3.txt'), {
force: true,
});
deleteFileSync(path.resolve(__dirname, '../fixtures/f3.txt'));

// load the cache again
cache = fileEntryCache.create('testCache');
Expand Down Expand Up @@ -348,7 +364,7 @@ describe('file-entry-cache', function () {

cache.getFileDescriptor(file);
cache.reconcile();
del(file);
deleteFileSync(file);
expect(cache.getFileDescriptor(file).notFound).to.be.true;
});
});
Expand All @@ -374,7 +390,7 @@ describe('file-entry-cache', function () {
cache.reconcile();

write(filenames[0], 'everybody can change');
del(filenames[1]);
deleteFileSync(filenames[1]);

expect(cache.analyzeFiles(filenames)).to.deep.equal(expectedAfterChanges);
});
Expand Down

0 comments on commit 2eefad8

Please sign in to comment.