Skip to content

Commit

Permalink
Remove the rimraf dependency in favor of the built-in Node.js `fs.r…
Browse files Browse the repository at this point in the history
…mSync` in the test folder

In Node.js 14.14.0 the `fs.rmSync` function was added that removes files
and directories. The `recursive` option is used to remove directories
and their contents, making it a drop-in replacement for the `rimraf`
dependency we use.

Given that PDF.js now requires Node.js 18+ we can be sure that this
option is available, so we can safely remove `rimraf` and reduce the
number of project dependencies in the test folder.

This commit also gets rid of the indirection via the `removeDirSync`
test helper function by simply calling `fs.rmSync` directly.

Co-authored-by: Wojciech Maj <[email protected]>
  • Loading branch information
timvandermeij and wojtekmaj committed Apr 14, 2024
1 parent e08de77 commit a562c41
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
15 changes: 6 additions & 9 deletions test/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
/* eslint-disable no-var */

import { copySubtreeSync, ensureDirSync, removeDirSync } from "./testutils.mjs";
import { copySubtreeSync, ensureDirSync } from "./testutils.mjs";
import {
downloadManifestFiles,
verifyManifestFiles,
Expand All @@ -25,14 +25,11 @@ import os from "os";
import path from "path";
import puppeteer from "puppeteer";
import readline from "readline";
import rimraf from "rimraf";
import { translateFont } from "./font/ttxdriver.mjs";
import url from "url";
import { WebServer } from "./webserver.mjs";
import yargs from "yargs";

const rimrafSync = rimraf.sync;

function parseOptions() {
const parsedArgs = yargs(process.argv)
.usage("Usage: $0")
Expand Down Expand Up @@ -213,7 +210,7 @@ function updateRefImages() {
console.log(" Updating ref/ ... ");
copySubtreeSync(refsTmpDir, refsDir);
if (removeTmp) {
removeDirSync(refsTmpDir);
fs.rmSync(refsTmpDir, { recursive: true, force: true });
}
console.log("done");
}
Expand Down Expand Up @@ -324,7 +321,7 @@ async function startRefTest(masterMode, showRefImages) {
fs.unlinkSync(eqLog);
}
if (fs.existsSync(testResultDir)) {
removeDirSync(testResultDir);
fs.rmSync(testResultDir, { recursive: true, force: true });
}

startTime = Date.now();
Expand Down Expand Up @@ -358,7 +355,7 @@ async function startRefTest(masterMode, showRefImages) {
function checkRefsTmp() {
if (masterMode && fs.existsSync(refsTmpDir)) {
if (options.noPrompts) {
removeDirSync(refsTmpDir);
fs.rmSync(refsTmpDir, { recursive: true, force: true });
setup();
return;
}
Expand All @@ -370,7 +367,7 @@ async function startRefTest(masterMode, showRefImages) {
"SHOULD THIS SCRIPT REMOVE tmp/? THINK CAREFULLY [yn] ",
function (answer) {
if (answer.toLowerCase() === "y") {
removeDirSync(refsTmpDir);
fs.rmSync(refsTmpDir, { recursive: true, force: true });
}
setup();
reader.close();
Expand Down Expand Up @@ -1038,7 +1035,7 @@ async function closeSession(browser) {
});
if (allClosed) {
if (tempDir) {
rimrafSync(tempDir);
fs.rmSync(tempDir, { recursive: true, force: true });
}
onAllSessionsClosed?.();
}
Expand Down
12 changes: 1 addition & 11 deletions test/testutils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@

import fs from "fs";
import path from "path";
import rimraf from "rimraf";

const rimrafSync = rimraf.sync;

function removeDirSync(dir) {
fs.readdirSync(dir); // Will throw if dir is not a directory
rimrafSync(dir, {
disableGlob: true,
});
}

function copySubtreeSync(src, dest) {
const files = fs.readdirSync(src);
Expand Down Expand Up @@ -63,4 +53,4 @@ function ensureDirSync(dir) {
}
}

export { copySubtreeSync, ensureDirSync, removeDirSync };
export { copySubtreeSync, ensureDirSync };

0 comments on commit a562c41

Please sign in to comment.