Skip to content

Commit bbdb9b9

Browse files
committed
Updated the keywords in package.json and added testcases to make sure all files are present and that no files are missing
1 parent ea38e80 commit bbdb9b9

File tree

2 files changed

+46
-24
lines changed

2 files changed

+46
-24
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@
4141
"client",
4242
"cli",
4343
"srt",
44-
".srt",
4544
"txt",
46-
".txt",
4745
"sub",
48-
".sub",
46+
"html",
47+
"csv",
48+
"tsv",
4949
"utf8",
5050
"utf-8",
5151
"cp-1250",

testing/language-encoding.test.js

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,54 @@
11
const languageEncoding = require("../src/index-node.js");
2-
const fs = require('fs');
2+
const fs = require("fs");
33

4+
// Make sure all files that package.json requires are present
5+
// Checking for CLI, Node.js and Browser/UNPKG
6+
checkLocation("bin", "cli.js");
7+
checkLocation("src", "index-node.js");
8+
checkLocation("umd", "language-encoding.min.js");
9+
10+
// Test all files in my 'language folders' dataset
411
const folderPath = "/home/gignu/Documents/Subtitle Database/Language Folders/";
512
const testFiles = getFiles(folderPath);
613

714
testFiles.forEach((file) => {
8-
languageEncoding(file, true)
9-
.then(fileInfo => {
10-
if (fileInfo.ratio <= 0.85) {
11-
console.log("Test case failed:");
12-
console.log(fileInfo);
13-
process.exit(1);
14-
}
15-
})
16-
.catch(error => { console.log(error); });
15+
languageEncoding(file, true)
16+
.then((fileInfo) => {
17+
if (fileInfo.ratio <= 0.85) {
18+
console.log("Test case failed:");
19+
console.log(fileInfo);
20+
process.exit(1);
21+
}
22+
})
23+
.catch((error) => {
24+
console.log(error);
25+
});
1726
});
1827

1928
// Recursively find all files in a folder and all it's subdirectories
2029
function getFiles(dir, files_) {
21-
files_ = files_ || [];
22-
var files = fs.readdirSync(dir);
23-
for (var i in files) {
24-
var name = dir + '/' + files[i];
25-
if (fs.statSync(name).isDirectory()) {
26-
getFiles(name, files_);
27-
} else {
28-
files_.push(name);
29-
}
30+
files_ = files_ || [];
31+
var files = fs.readdirSync(dir);
32+
for (var i in files) {
33+
var name = dir + "/" + files[i];
34+
if (fs.statSync(name).isDirectory()) {
35+
getFiles(name, files_);
36+
} else {
37+
files_.push(name);
3038
}
31-
return files_;
32-
}
39+
}
40+
return files_;
41+
}
42+
43+
function checkLocation(folder, file) {
44+
const dir = fs.readdirSync(
45+
"/home/gignu/GitHub/Detect-File-Encoding-and-Language/" + folder
46+
);
47+
const fileFound = dir.some((fileName) => fileName === file);
48+
if (!fileFound) {
49+
console.log(
50+
`According to my test file, ${file} is supposed to be located here: /home/gignu/GitHub/Detect-File-Encoding-and-Language/${folder}`
51+
);
52+
process.exit(1);
53+
}
54+
}

0 commit comments

Comments
 (0)