Skip to content

Commit

Permalink
tests(index): use glob for post-test directory cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Frazer Smith committed Apr 10, 2020
1 parent db1fcd6 commit 5d16e5a
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 146 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-jest": "^23.8.2",
"eslint-plugin-json": "^2.1.1",
"glob": "^7.1.6",
"jest": "^25.2.7",
"jsdoc-to-markdown": "^5.0.3",
"jsinspect": "^0.12.7",
Expand Down
69 changes: 7 additions & 62 deletions src/index.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const fs = require('fs');
const glob = require('glob');
const path = require('path');
const { Poppler } = require('./index');

Expand All @@ -7,68 +8,12 @@ const file = `${testDirectory}pdf_1.3_NHS_Constitution.pdf`;

function clean() {
return new Promise((resolve) => {
if (fs.existsSync(`${testDirectory}pdf_1.3_NHS_Constitution.html`)) {
fs.unlinkSync(`${testDirectory}pdf_1.3_NHS_Constitution.html`);
}
if (fs.existsSync(`${testDirectory}pdf_1.3_NHS_Constitution.ps`)) {
fs.unlinkSync(`${testDirectory}pdf_1.3_NHS_Constitution.ps`);
}
if (fs.existsSync(`${testDirectory}pdf_1.3_NHS_Constitution-01.ppm`)) {
fs.unlinkSync(`${testDirectory}pdf_1.3_NHS_Constitution-01.ppm`);
}
if (
fs.existsSync(
`${testDirectory}pdf_1.3_NHS_Constitution_attached.pdf`
)
) {
fs.unlinkSync(
`${testDirectory}pdf_1.3_NHS_Constitution_attached.pdf`
);
}
if (
fs.existsSync(`${testDirectory}pdf_1.3_NHS_Constitution_ind.html`)
) {
fs.unlinkSync(`${testDirectory}pdf_1.3_NHS_Constitution_ind.html`);
}
if (fs.existsSync(`${testDirectory}pdf_1.3_NHS_Constitutions.html`)) {
fs.unlinkSync(`${testDirectory}pdf_1.3_NHS_Constitutions.html`);
}
if (fs.existsSync(`${testDirectory}pdf_1.3_NHS_Constitution.svg`)) {
fs.unlinkSync(`${testDirectory}pdf_1.3_NHS_Constitution.svg`);
}
if (fs.existsSync(`${testDirectory}pdf_1.3_NHS_Constitution.txt`)) {
fs.unlinkSync(`${testDirectory}pdf_1.3_NHS_Constitution.txt`);
}
if (
fs.existsSync(
`${testDirectory}pdf_1.3_NHS_Constitution-extract-1.pdf`
)
) {
fs.unlinkSync(
`${testDirectory}pdf_1.3_NHS_Constitution-extract-1.pdf`
);
}
if (
fs.existsSync(
`${testDirectory}pdf_1.3_NHS_Constitution-extract-2.pdf`
)
) {
fs.unlinkSync(
`${testDirectory}pdf_1.3_NHS_Constitution-extract-2.pdf`
);
}
if (
fs.existsSync(
`${testDirectory}pdf_1.3_NHS_Constitution-extract-3.pdf`
)
) {
fs.unlinkSync(
`${testDirectory}pdf_1.3_NHS_Constitution-extract-3.pdf`
);
}
if (fs.existsSync(`${testDirectory}united.pdf`)) {
fs.unlinkSync(`${testDirectory}united.pdf`);
}
const files = glob.GlobSync(
`${testDirectory}!(test.txt|pdf_1.3_NHS_Constitution.pdf|pdf_1.3_NHS_Constitution_attached_detach.pdf|pdf_1.7_NHS_Constitution_Handbook.pdf)`
).found;
files.forEach((foundFile) => {
fs.unlinkSync(foundFile);
});
resolve('done');
});
}
Expand Down
Loading

0 comments on commit 5d16e5a

Please sign in to comment.