mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 07:43:12 +09:00
Slight improvements to existing tests
This commit is contained in:
1 parent
913887fd2c
commit
00dd22e59f
2 files changed
+24
-21
No files matched your search
+22
-19
@@ -3,26 +3,29 @@ var fileOps = require('./fileOps');
|
|||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
|
||||||
// create folders for testing
|
// create folders for testing
|
||||||
if (!fs.existsSync("lib/test")){
|
function setupTestingEnv(){
|
||||||
fs.mkdirSync("lib/test");
|
if (!fs.existsSync("lib/test")){
|
||||||
|
fs.mkdirSync("lib/test");
|
||||||
|
}
|
||||||
|
if (!fs.existsSync("lib/test/folder")){
|
||||||
|
fs.mkdirSync("lib/test/folder");
|
||||||
|
}
|
||||||
|
if (!fs.existsSync("lib/test/another folder")){
|
||||||
|
fs.mkdirSync("lib/test/another folder");
|
||||||
|
}
|
||||||
|
if (!fs.existsSync("lib/test/file.txt")){
|
||||||
|
fs.writeFileSync("lib/test/file.txt", "contents");
|
||||||
|
}
|
||||||
|
if (!fs.existsSync("lib/test/another file.txt")){
|
||||||
|
fs.writeFileSync("lib/test/another file.txt", "more contents");
|
||||||
|
}
|
||||||
|
// we need this xfile to test a branch in fileOps.getNewestFile()s propagation
|
||||||
|
if (!fs.existsSync("lib/test/xfile.txt")){
|
||||||
|
fs.writeFileSync("lib/test/xfile.txt", "contents");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!fs.existsSync("lib/test/folder")){
|
setupTestingEnv();
|
||||||
fs.mkdirSync("lib/test/folder");
|
setupTestingEnv(); // run twice to get branch coverage
|
||||||
}
|
|
||||||
if (!fs.existsSync("lib/test/another folder")){
|
|
||||||
fs.mkdirSync("lib/test/another folder");
|
|
||||||
}
|
|
||||||
if (!fs.existsSync("lib/test/file.txt")){
|
|
||||||
fs.writeFileSync("lib/test/file.txt", "contents");
|
|
||||||
}
|
|
||||||
if (!fs.existsSync("lib/test/another file.txt")){
|
|
||||||
fs.writeFileSync("lib/test/another file.txt", "more contents");
|
|
||||||
}
|
|
||||||
// we need this xfile to test a branch in fileOps.getNewestFile()s propagation
|
|
||||||
if (!fs.existsSync("lib/test/xfile.txt")){
|
|
||||||
fs.writeFileSync("lib/test/xfile.txt", "contents");
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("fileOps.js", function(){
|
describe("fileOps.js", function(){
|
||||||
describe("fileOps.getDirectoriesSync()", function(){
|
describe("fileOps.getDirectoriesSync()", function(){
|
||||||
it("gets an array of directory names from a path", function(){
|
it("gets an array of directory names from a path", function(){
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ describe("isJson.js()", function(){
|
|||||||
it("checks if a thing is valid JSON", function(){
|
it("checks if a thing is valid JSON", function(){
|
||||||
assert(isJson("string") === false);
|
assert(isJson("string") === false);
|
||||||
assert(isJson("{js_object_notation='very false'}") === false);
|
assert(isJson("{js_object_notation='very false'}") === false);
|
||||||
assert(isJson('{ "name":"John", "age":31, "city":"New York" }') === true);
|
assert(isJson('{ "name":"John", "age":31, "city":"New York" }') === true, "This is valid JSON, lib disagrees");
|
||||||
});
|
});
|
||||||
it("recognizes that true and false are both valid JSON", function(){
|
it("recognizes that true and false are both valid JSON", function(){
|
||||||
assert(isJson(true) === true);
|
assert(isJson(true) === true);
|
||||||
@@ -15,6 +15,6 @@ describe("isJson.js()", function(){
|
|||||||
assert(isJson(null) === true);
|
assert(isJson(null) === true);
|
||||||
});
|
});
|
||||||
it("Recognizes that JSON doesn't allow trailing commas (,)", function(){
|
it("Recognizes that JSON doesn't allow trailing commas (,)", function(){
|
||||||
assert(isJson('["a", "b", ]') === false);
|
assert(isJson('["a", "b", ]') === false, "JSON should not allow trailing commas");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user