stub mocha/chai for testing server

This commit is contained in:
Sorrel Bri 2020-01-08 13:25:28 -08:00 committed by sorrelbri
parent 6a373a1172
commit 24c4130f7f
5 changed files with 932 additions and 20 deletions

View file

@ -8,6 +8,11 @@ module.exports = {
connection: process.env.PG_CONNECTION_STRING connection: process.env.PG_CONNECTION_STRING
}, },
test: {
client: 'postgresql',
connection: process.env.PG_CONNECTION_STRING_TEST
},
staging: { staging: {
client: 'postgresql', client: 'postgresql',
connection: process.env.PG_CONNECTION_STRING, connection: process.env.PG_CONNECTION_STRING,

File diff suppressed because it is too large Load diff

View file

@ -4,13 +4,12 @@
"private": true, "private": true,
"scripts": { "scripts": {
"start": "node ./bin/www", "start": "node ./bin/www",
"test": "mocha ./test/*",
"make-migration": "./node_modules/.bin/knex migrate:make", "make-migration": "./node_modules/.bin/knex migrate:make",
"migrate": "./node_modules/.bin/knex migrate:latest", "migrate": "./node_modules/.bin/knex migrate:latest",
"seed": "./node_modules/.bin/knex seed:run" "seed": "./node_modules/.bin/knex seed:run"
}, },
"dependencies": { "dependencies": {
"chai": "^4.2.0",
"chai-http": "^4.3.0",
"cookie-parser": "~1.4.4", "cookie-parser": "~1.4.4",
"cors": "^2.8.5", "cors": "^2.8.5",
"debug": "~2.6.9", "debug": "~2.6.9",
@ -21,5 +20,10 @@
"morgan": "~1.9.1", "morgan": "~1.9.1",
"pg": "^7.17.0", "pg": "^7.17.0",
"socket.io": "^2.3.0" "socket.io": "^2.3.0"
},
"devDependencies": {
"chai": "^4.2.0",
"chai-http": "^4.3.0",
"mocha": "^7.0.0"
} }
} }

View file

@ -24,8 +24,9 @@ const corsOptions = {
app.options('*', cors(corsOptions)); app.options('*', cors(corsOptions));
app.use('*', cors(corsOptions)); app.use('*', cors(corsOptions));
// disable logging for tests
if (process.env.NODE_ENV !== 'test') app.use(logger('dev'));
app.use(logger('dev'));
app.use(express.json()); app.use(express.json());
app.use(express.urlencoded({ extended: false })); app.use(express.urlencoded({ extended: false }));
app.use(cookieParser()); app.use(cookieParser());

View file

@ -0,0 +1,20 @@
process.env.NODE_ENV = 'test';
const chai = require('chai');
const chaiHttp = require('chai-http');
const app = require('../server');
const should = chai.should();
chai.use(chaiHttp);
// ! to run tests from other testing modules
// import someTest from './endpoint/someTest';
describe('API Routes', function() {
// ! should be a function that returns tests to be run
// someTest(chai)
});