mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-23 00:13:13 +09:00
Added the first tests for master.js
This commit is contained in:
1 parent
0e1a7cdb4a
commit
a1db24bd91
4 files changed
+1332
-70
No files matched your search
@@ -461,14 +461,8 @@ app.get("/api/getFactorioLocale", function(req,res){
|
|||||||
getFactorioLocale.asObject(config.factorioDirectory, "en", (err, factorioLocale) => res.send(factorioLocale));
|
getFactorioLocale.asObject(config.factorioDirectory, "en", (err, factorioLocale) => res.send(factorioLocale));
|
||||||
});
|
});
|
||||||
|
|
||||||
// endpoint for getting the chartjs library
|
|
||||||
app.get("/chart.js", function(req, res) {
|
|
||||||
res.header("Access-Control-Allow-Origin", "*");
|
|
||||||
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
|
||||||
// Check it and send it
|
|
||||||
res.end(fs.readFileSync("node_modules/chartjs/chart.js"));
|
|
||||||
});
|
|
||||||
|
|
||||||
var server = app.listen(config.masterPort || 8080, function () {
|
var server = app.listen(config.masterPort || 8080, function () {
|
||||||
console.log("Listening on port %s...", server.address().port);
|
console.log("Listening on port %s...", server.address().port);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
module.exports = app;
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
var app = require('./master.js'),
|
||||||
|
assert = require('assert'),
|
||||||
|
request = require('supertest');
|
||||||
|
const validateHTML = require('html5-validator');
|
||||||
|
|
||||||
|
|
||||||
|
describe('Master server endpoint testing', function() {
|
||||||
|
describe('#GET /api/getFactorioLocale', function() {
|
||||||
|
it('should get the basegame factorio locale', function(done) {
|
||||||
|
request(app).get('/api/getFactorioLocale')
|
||||||
|
.end(function(err, res) {
|
||||||
|
assert.equal(res.statusCode, 200);
|
||||||
|
|
||||||
|
let object = res.body;
|
||||||
|
|
||||||
|
// test that it is actual factorio locale, copied from getFactorioLocale.spec.js
|
||||||
|
assert.equal(typeof object, "object");
|
||||||
|
assert.equal(object["entity-name"]["fish"], "Fish");
|
||||||
|
assert.equal(object["entity-name"]["small-lamp"], "Lamp");
|
||||||
|
Object.keys(object).forEach(key => {
|
||||||
|
// first level of the nested object is always an object
|
||||||
|
assert.equal(typeof object[key], "object");
|
||||||
|
|
||||||
|
Object.keys(object[key]).forEach(key2 => {
|
||||||
|
// second level of the nested object is always a string, nearly always truthy
|
||||||
|
if(key2 != "so-long-and-thanks-for-all-the-fish"){
|
||||||
|
assert.ok(object[key][key2]);
|
||||||
|
assert.equal(typeof object[key][key2], "string");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
// describe("#GET /api/")
|
||||||
|
describe("#GET static website data", function() {
|
||||||
|
it("sends some HTML when accessing /", function(done){
|
||||||
|
request(app).get("/").end(function(err,res){
|
||||||
|
assert.equal(res.statusCode, 200);
|
||||||
|
validateHTML(res.text).then(result => {
|
||||||
|
assert(result.messages.length === 0, "there are HTML errors on the page, please fix: "+JSON.stringify(result.messages));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it("sends some HTML when accessing /nodes",function(done){
|
||||||
|
request(app).get("/nodes").end(function(err,res){
|
||||||
|
assert.equal(res.statusCode, 200);
|
||||||
|
validateHTML(res.text).then(result => {
|
||||||
|
assert(result.messages.length === 0, "there are HTML errors on the page, please fix: "+JSON.stringify(result.messages));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it("sends some HTML when accessing /settings",function(done){
|
||||||
|
request(app).get("/settings").end(function(err,res){
|
||||||
|
assert.equal(res.statusCode, 200);
|
||||||
|
validateHTML(res.text).then(result => {
|
||||||
|
assert(result.messages.length === 0, "there are HTML errors on the page, please fix: "+JSON.stringify(result.messages));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it("sends some HTML when accessing /nodeDetails",function(done){
|
||||||
|
request(app).get("/nodeDetails").end(function(err,res){
|
||||||
|
assert.equal(res.statusCode, 200);
|
||||||
|
validateHTML(res.text).then(result => {
|
||||||
|
assert(result.messages.length === 0, "there are HTML errors on the page, please fix: "+JSON.stringify(result.messages));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Generated
+1248
-57
File diff suppressed because it is too large.
Load diff
+7
-5
@@ -15,11 +15,11 @@
|
|||||||
"author": "Danielv123",
|
"author": "Danielv123",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"averaged-timeseries": "^1.2.4",
|
"averaged-timeseries": "^1.3.0",
|
||||||
"body-parser": "^1.18.2",
|
"body-parser": "^1.18.2",
|
||||||
"canvasjs": "^1.8.1",
|
"canvasjs": "^1.8.1",
|
||||||
"child_process": "^1.0.2",
|
"child_process": "^1.0.2",
|
||||||
"codecov": "^2.3.0",
|
"codecov": "^2.3.1",
|
||||||
"deepmerge": "^1.5.2",
|
"deepmerge": "^1.5.2",
|
||||||
"ejs": "^2.5.7",
|
"ejs": "^2.5.7",
|
||||||
"express": "^4.16.2",
|
"express": "^4.16.2",
|
||||||
@@ -30,6 +30,7 @@
|
|||||||
"fs-extra": "^1.0.0",
|
"fs-extra": "^1.0.0",
|
||||||
"getmac": "^1.2.1",
|
"getmac": "^1.2.1",
|
||||||
"hash-files": "^1.1.1",
|
"hash-files": "^1.1.1",
|
||||||
|
"html5-validator": "^1.0.6",
|
||||||
"ini": "^1.3.4",
|
"ini": "^1.3.4",
|
||||||
"leveldown": "^1.9.0",
|
"leveldown": "^1.9.0",
|
||||||
"linvodb": "0.0.0",
|
"linvodb": "0.0.0",
|
||||||
@@ -51,8 +52,9 @@
|
|||||||
"istanbul": "^0.4.5",
|
"istanbul": "^0.4.5",
|
||||||
"mocha": "^3.5.3",
|
"mocha": "^3.5.3",
|
||||||
"mocha-sinon": "^2.0.0",
|
"mocha-sinon": "^2.0.0",
|
||||||
"mock-fs": "^4.3.0",
|
"mock-fs": "^4.4.2",
|
||||||
"nock": "^9.0.22",
|
"nock": "^9.0.25",
|
||||||
"sinon": "^2.4.1"
|
"sinon": "^2.4.1",
|
||||||
|
"supertest": "^3.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user