1
0
Fork 0

Setup tests

This commit is contained in:
Ethanell 2020-06-08 12:20:17 +02:00
parent 4f3447b2e4
commit b9613f16a9
8 changed files with 946 additions and 6 deletions

16
.gitlab-ci.yml Normal file
View file

@ -0,0 +1,16 @@
image: node:latest
services:
- postgres:latest
variables:
POSTGRES_DB: "letu"
POSTGRES_USER: "letu"
POSTGRES_PASSWORD: "letu"
POSTGRES_HOST_AUTH_METHOD: trust
NODE_ENV: "test"
all_tests:
script:
- npm install
- npm test

View file

@ -8,11 +8,10 @@ const config = require(__dirname + "/../config/config.json")["database"];
const db = {};
let sequelize;
if (config.use_env_variable) {
sequelize = new Sequelize(process.env[config.use_env_variable], config);
} else {
sequelize = new Sequelize(config.database, config.username, config.password, config);
}
if (process.env.NODE_ENV === "test")
sequelize = new Sequelize("sqlite::memory:");
else
sequelize = new Sequelize(require(__dirname + "/../config/config.json").database);
fs
.readdirSync(__dirname)

875
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -3,7 +3,8 @@
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
"start": "node ./bin/www",
"test": "NODE_ENV=test mocha"
},
"dependencies": {
"cookie-parser": "~1.4.4",
@ -17,5 +18,12 @@
"sequelize": "^5.21.12",
"sequelize-cli": "^5.5.1",
"socket.io": "^2.3.0"
},
"devDependencies": {
"chai": "^4.2.0",
"mocha": "^7.2.0",
"request": "^2.88.2",
"sqlite3": "^5.0.0",
"supertest": "^5.0.0"
}
}

1
test/mocha.opts Normal file
View file

@ -0,0 +1 @@
--timeout 100000

33
test/test-pages.js Normal file
View file

@ -0,0 +1,33 @@
let request = require("supertest");
let wipeDatabase = require("./utils/wipeDatabase");
async function setup() {
let app = require("../app");
let models = require("../models");
await models.sequelize.sync();
await wipeDatabase(models);
return [app, models];
}
async function clean() {
await wipeDatabase(models);
await models.sequelize.close();
for (let e of ["../app", "../models"])
delete require.cache[require.resolve(e)];
}
before(async () => {
[app, models] = await setup();
})
it("Main page content", async () => {
await request(app)
.get("/")
.expect(200);
});
after(() => {
return clean;
});

View file

@ -0,0 +1,8 @@
async function wipeDatabase(models) {
for (let model in models) {
if (["sequelize", "Sequelize"].indexOf(model) < 0)
await models[model].destroy({where: {}});
}
}
module.exports = wipeDatabase;