language: node_js node_js: - "6" before_script: - ./node_modules/.bin/knex migrate:latest --knexfile='./app/knexfile.js' script: - npm run test
NODE_ENV=production NODE_CONFIG_DIR='./app/config/' ./node_modules/.bin/mocha --require 'babel-polyfill' --compilers js:babel-register ./app/test/**/*.js
const request = require('supertest');
const should = require('should');
const index = require('../../index');
let app = request(index.listen());
describe('/api/persons', function() {
let personId;
it('POST /api/persons - create person success and respond with 200', function(done) {
app.post('/api/persons')
.send({
'firstName': 'Jennifer',
'lastName': 'Lawrence',
'age': 24
})
.expect(200)
.expect(function(res) {
(res.body.id > 0).should.be.true;
})
.end(function(err, res) {
if (err) {
return done(err);
}
let resJson = JSON.parse(res.text);
personId = resJson.id;
done();
})
});
it('GET /api/persons - fetch persons item', function(done) {
app.get('/api/persons')
.expect(200)
.expect(function(res) {
(res.body.length > 0).should.be.true;
})
.end(function(err, res) {
if (err) {
return done(err);
}
done();
})
});
it('GET /api/persons/:id - fetch a person', function(done) {
app.get(`/api/persons/${personId}`)
.expect(200)
.expect(function(res) {
(res.body.id == personId).should.be.true;
})
.end(function(err, res) {
if (err) {
return done(err);
}
done();
})
});
it('DELETE /api/persons/:id - delete a person', function(done) {
app.delete(`/api/persons/${personId}`)
.expect(200)
.end(function(err, res) {
if (err) {
return done(err);
}
done();
})
});
it('GET /api/persons/:id - fetch a person should 404', function(done) {
app.get(`/api/persons/${personId}`)
.expect(404)
.end(function(err, res) {
if (err) {
return done(err);
}
done();
})
});
});
const index = require('../../index');
import Knex from 'knex';
import {
Model
} from 'objection';
import knexConfig from './knexfile';
import config from 'config';
import Koa from 'koa';
import koaLogger from 'koa-logger';
import bodyParser from 'koa-bodyparser';
import render from 'koa-ejs';
import co from 'co';
import koaStatic from "koa2-static"
import router from './router';
const path = require('path');
// initial knex
const knex = Knex(knexConfig.development);
Model.knex(knex);
// initial app
const app = new Koa();
// initial render
render(app, {
root: path.join(__dirname + '/view'),
layout: 'template',
viewExt: 'ejs',
cache: true,
debug: true
});
app.context.render = co.wrap(app.context.render);
// initial static
app.use(koaLogger())
.use(bodyParser())
.use(router.routes())
.use(koaStatic({
path: '/web',
root: __dirname + "/../static"
}));
module.exports = app;
module.exports = app;
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有