Added unit tests via supertest, mocha
This commit is contained in:
46
index.js
46
index.js
@@ -1,44 +1,6 @@
|
|||||||
const express = require('express');
|
const app = require('./src/app');
|
||||||
const app = express();
|
|
||||||
const port = 3000;
|
|
||||||
|
|
||||||
// grab app and node.js process data
|
const PORT = process.env.PORT || 3000;
|
||||||
const pjson = require('./package.json');
|
app.listen(PORT, () => {
|
||||||
const { versions } = require('node:process');
|
console.log(`Listening on port ${PORT}`);
|
||||||
|
|
||||||
// register app and node.js versions with views;
|
|
||||||
app.locals.app_version = pjson.version;
|
|
||||||
app.locals.node_version = versions.node;
|
|
||||||
|
|
||||||
// initialize database
|
|
||||||
const sequelize = require('./src/models');
|
|
||||||
sequelize.sync({}).then(function(){
|
|
||||||
console.log('database has been synced');
|
|
||||||
}).catch(function(){
|
|
||||||
console.log('unable to sync database');
|
|
||||||
});
|
|
||||||
|
|
||||||
// enable sessions
|
|
||||||
const session = require("express-session");
|
|
||||||
app.use(session({ resave: true, secret: "123456", saveUninitialized: true }));
|
|
||||||
|
|
||||||
// enable body-parser to read form data
|
|
||||||
const bodyParser = require('body-parser');
|
|
||||||
app.use(bodyParser.urlencoded({ extended: true }));
|
|
||||||
|
|
||||||
// enable the Twig template engine
|
|
||||||
app.set('view engine', 'twig');
|
|
||||||
app.set('twig options', {
|
|
||||||
allowAsync: true,
|
|
||||||
strict_variables: false
|
|
||||||
});
|
|
||||||
|
|
||||||
// enable serving static files
|
|
||||||
app.use(express.static('public'));
|
|
||||||
|
|
||||||
// load routes to express
|
|
||||||
require('./src/routes')(app);
|
|
||||||
|
|
||||||
app.listen(port, () => {
|
|
||||||
console.log(`Leviathan listening on port ${port}`);
|
|
||||||
});
|
});
|
||||||
|
1363
package-lock.json
generated
1363
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -6,7 +6,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node index.js",
|
"start": "node index.js",
|
||||||
"dev": "nodemon ./index.js",
|
"dev": "nodemon ./index.js",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "mocha",
|
||||||
"grunt": "grunt"
|
"grunt": "grunt"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
@@ -28,13 +28,16 @@
|
|||||||
"twig": "^1.17.1"
|
"twig": "^1.17.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"chai": "^5.3.1",
|
||||||
"grunt": "^1.6.1",
|
"grunt": "^1.6.1",
|
||||||
"grunt-cli": "^1.5.0",
|
"grunt-cli": "^1.5.0",
|
||||||
"grunt-contrib-copy": "^1.0.0",
|
"grunt-contrib-copy": "^1.0.0",
|
||||||
"grunt-contrib-sass": "^2.0.0",
|
"grunt-contrib-sass": "^2.0.0",
|
||||||
"grunt-contrib-uglify": "^5.2.2",
|
"grunt-contrib-uglify": "^5.2.2",
|
||||||
"grunt-contrib-watch": "^1.1.0",
|
"grunt-contrib-watch": "^1.1.0",
|
||||||
|
"mocha": "^11.7.1",
|
||||||
"nodemon": "^3.1.10",
|
"nodemon": "^3.1.10",
|
||||||
"sass": "^1.89.2"
|
"sass": "^1.89.2",
|
||||||
|
"supertest": "^7.1.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
41
src/app.js
Normal file
41
src/app.js
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const app = express();
|
||||||
|
|
||||||
|
// grab app and node.js process data
|
||||||
|
const pjson = require('../package.json');
|
||||||
|
const { versions } = require('node:process');
|
||||||
|
|
||||||
|
// register app and node.js versions with views;
|
||||||
|
app.locals.app_version = pjson.version;
|
||||||
|
app.locals.node_version = versions.node;
|
||||||
|
|
||||||
|
// initialize database
|
||||||
|
const sequelize = require('./models');
|
||||||
|
sequelize.sync({}).then(function(){
|
||||||
|
console.log('database has been synced');
|
||||||
|
}).catch(function(){
|
||||||
|
console.log('unable to sync database');
|
||||||
|
});
|
||||||
|
|
||||||
|
// enable sessions
|
||||||
|
const session = require("express-session");
|
||||||
|
app.use(session({ resave: true, secret: "123456", saveUninitialized: true }));
|
||||||
|
|
||||||
|
// enable body-parser to read form data
|
||||||
|
const bodyParser = require('body-parser');
|
||||||
|
app.use(bodyParser.urlencoded({ extended: true }));
|
||||||
|
|
||||||
|
// enable the Twig template engine
|
||||||
|
app.set('view engine', 'twig');
|
||||||
|
app.set('twig options', {
|
||||||
|
allowAsync: true,
|
||||||
|
strict_variables: false
|
||||||
|
});
|
||||||
|
|
||||||
|
// enable serving static files
|
||||||
|
app.use(express.static('public'));
|
||||||
|
|
||||||
|
// load routes to express
|
||||||
|
require('./routes')(app);
|
||||||
|
|
||||||
|
module.exports = app;
|
10
test/app.test.js
Normal file
10
test/app.test.js
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
const request = require('supertest');
|
||||||
|
const { expect } = require('chai');
|
||||||
|
const app = require('../src/app');
|
||||||
|
|
||||||
|
describe('GET /', () => {
|
||||||
|
it('should run the app server', async () => {
|
||||||
|
const res = await request(app).get('/');
|
||||||
|
expect(res.status).to.equal(200);
|
||||||
|
});
|
||||||
|
});
|
Reference in New Issue
Block a user