Skip to content

Commit

Permalink
test(emptydir): add minimal testing of task emptyDir
Browse files Browse the repository at this point in the history
test for #8
  • Loading branch information
atao60 committed Jan 24, 2021
1 parent 571d6fc commit eaadb82
Showing 1 changed file with 56 additions and 18 deletions.
74 changes: 56 additions & 18 deletions test/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ function createTempDir(format: string, path = TMP_DIR, suffix = 'fse-cli-test-')
}
}

const DEBUG = env.CLI_TEST_DEBUG && env.CLI_TEST_DEBUG === 'true';

describe("The fs-extra CLI", () => {

describe("Calling CLI", () => {
Expand All @@ -35,9 +37,9 @@ describe("The fs-extra CLI", () => {
const args = {};
const userInputs = [];
const options = {
// env: { DEBUG: true }, // false by default
// timeout: 200, // 100 ms by default
// maxTimeout: 0 // 10 s by default; if "0" then no timeout
// maxTimeout: 0, // 10 s by default; if "0" then no timeout
env: { DEBUG } // false by default
};
const foundRegex = new RegExp('^ERROR:\\s+No\\s+task\\s+specified', 'm');
run(
Expand All @@ -62,9 +64,9 @@ describe("The fs-extra CLI", () => {
const args = { app: [unknownTask] };
const userInputs = [];
const options = {
// env: { DEBUG: true }, // false by default
// timeout: 200, // 100 ms by default
// maxTimeout: 0 // 10 s by default; if "0" then no timeout
// maxTimeout: 0, // 10 s by default; if "0" then no timeout
env: { DEBUG } // false by default
};
const foundRegex = new RegExp(`^ERROR:\\s+Unknown\\s+task\\s+'${unknownTask}'`, 'm');
run(
Expand All @@ -83,6 +85,42 @@ describe("The fs-extra CLI", () => {
});
});

describe("Calling 'emptyDir'", () => {
it("When existing directory, it will be purged", function (done) { // don't pass 'done' as argument! with async/await
const dirToBePurged = createTempDir("Test 'Purge a directory', unable to create a temporary directory based on '%s' & '%s': %s");
const fileToBeRemoved = join(dirToBePurged, 'toBeRemoved.txt');
closeSync(openSync(fileToBeRemoved, 'w'));
const script = `${LIB_DIR}`; // ie index.js
const args = { app: ['emptyDir', dirToBePurged] };
const userInputs = [];
const options = {
// timeout: 200, // 100 ms by default
// maxTimeout: 0, // 10 s by default; if "0" then no timeout
env: { DEBUG } // false by default
};
run(
script,
args,
userInputs,
options
)
.then(() => {
expect(existsSync(dirToBePurged), "directory should still exists").to.be.true;
expect(!existsSync(fileToBeRemoved), "file should have been removed").to.be.true;
done();
})
.catch(error => {
done(error);
})
.finally(() => {
try {
rmdirSync(dirToBePurged, { recursive: true });
} catch (e) { /* do nothing */ }
});

});
});

describe("Calling 'remove'", () => {
// first check if the jog is done
it("When existing directory, it will be removed", function (done) { // don't pass 'done' as argument! with async/await
Expand All @@ -92,9 +130,9 @@ describe("The fs-extra CLI", () => {
const args = { app: ['remove', dirToBeRemoved] };
const userInputs = [];
const options = {
// env: { DEBUG: true }, // false by default
// timeout: 200, // 100 ms by default
// maxTimeout: 0 // 10 s by default; if "0" then no timeout
// maxTimeout: 0, // 10 s by default; if "0" then no timeout
env: { DEBUG } // false by default
};
run(
script,
Expand Down Expand Up @@ -127,9 +165,9 @@ describe("The fs-extra CLI", () => {
const args = { app: ['mkdirp', dirToBeCreated] };
const userInputs = [];
const options = {
// env: { DEBUG: true }, // false by default
// timeout: 200, // 100 ms by default
// maxTimeout: 0 // 10 s by default; if "0" then no timeout
// maxTimeout: 0, // 10 s by default; if "0" then no timeout
env: { DEBUG } // false by default
};
run(
script,
Expand Down Expand Up @@ -164,9 +202,9 @@ describe("The fs-extra CLI", () => {
const args = { app: ['ensureFile', fileToBeCreated] };
const userInputs = [];
const options = {
// env: { DEBUG: true }, // false by default
// timeout: 200, // 100 ms by default
// maxTimeout: 0 // 10 s by default; if "0" then no timeout
// maxTimeout: 0 , // 10 s by default; if "0" then no timeout
env: { DEBUG } // false by default
};
run(
script,
Expand Down Expand Up @@ -220,9 +258,9 @@ describe("The fs-extra CLI", () => {
const args = { app: ['copy', fileToBeCopied, fileCopy] };
const userInputs = [];
const options = {
// env: { DEBUG: true }, // false by default
// timeout: 200, // 100 ms by default
// maxTimeout: 0 // 10 s by default; if "0" then no timeout
// maxTimeout: 0, // 10 s by default; if "0" then no timeout
env: { DEBUG } // false by default
};
run(
script,
Expand Down Expand Up @@ -278,9 +316,9 @@ describe("The fs-extra CLI", () => {
const args = { app: ['move', fileToBeMovedPath, movedFilePath] };
const userInputs = [];
const options = {
// env: { DEBUG: true }, // false by default
// timeout: 200, // 100 ms by default
// maxTimeout: 0 // 10 s by default; if "0" then no timeout
// maxTimeout: 0, // 10 s by default; if "0" then no timeout
env: { DEBUG } // false by default
};
run(
script,
Expand Down Expand Up @@ -320,9 +358,9 @@ describe("The fs-extra CLI", () => {
const args = { app: ['version'] };
const userInputs = [];
const options = {
// env: { DEBUG: true }, // false by default
// timeout: 200, // 100 ms by default
// maxTimeout: 0 // 10 s by default; if "0" then no timeout
// maxTimeout: 0, // 10 s by default; if "0" then no timeout
env: { DEBUG } // false by default
};
const foundRegex = new RegExp(`^@atao60/fse-cli\\s+${semverPattern}\\s+\\(fs-extra\\s+${semverPattern}\\)$`);
run(
Expand All @@ -349,9 +387,9 @@ describe("The fs-extra CLI", () => {
const userInputs = [];
const options = {
// timeout: 200, // 100 ms by default
// maxTimeout: 0, // 10 s by default; if "0" then no timeout
// maxTimeout: 0, // 10 s by default; if "0" then no timeout
env: {
// DEBUG: true, // false by default
DEBUG, // false by default
FORCE_COLOR: supportsColor.stdout.level //
}
};
Expand Down

0 comments on commit eaadb82

Please sign in to comment.