最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Node.js環(huán)境下Koa2添加travis ci持續(xù)集成工具的方法

 更新時間:2017年06月19日 11:28:15   作者:durban  
這篇文章主要給大家介紹了在Node.js環(huán)境下Koa2添加travis ci持續(xù)集成工具的方法,文中介紹的非常詳細,對大家具有一定的參考學(xué)習(xí)價值,需要的朋友們下面跟著小編一起來學(xué)習(xí)學(xué)習(xí)吧。

前言

因為最近使用koa2做項目測試開發(fā),所以想整合下travis ci,網(wǎng)上資料也比較少,于是自己就整了個,做個記錄。分享出來供大家參考學(xué)習(xí),下面來看看詳細的介紹吧。

方法如下:

先來看下travis.yml的配置

language: node_js
node_js:
 - "6"
before_script:
 - ./node_modules/.bin/knex migrate:latest --knexfile='./app/knexfile.js'
script:
 - npm run test

因為是接口測試,所以首先需要做表創(chuàng)建等操作。

測試的命令:

NODE_ENV=production NODE_CONFIG_DIR='./app/config/' ./node_modules/.bin/mocha --require 'babel-polyfill' --compilers js:babel-register ./app/test/**/*.js

主要是測試這里,使用了supertest,大概看下是如何調(diào)用的。

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');

需要將koa實例暴漏出來,不然在做travis ci的集成后,啟動了項目,測試的時候依然找不到具體訪問地址。

來看下我的index.js

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;

暴漏出來,再supertest中才可以獨立啟動server測試。

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。

相關(guān)文章

  • CentOS 安裝NodeJS V8.0.0的方法

    CentOS 安裝NodeJS V8.0.0的方法

    這篇文章主要介紹了CentOS 安裝NodeJS V8.0.0的方法,需要的朋友可以參考下
    2017-06-06
  • Windows下安裝Bun像Node或Deno的現(xiàn)代JS運行時

    Windows下安裝Bun像Node或Deno的現(xiàn)代JS運行時

    這篇文章主要為大家介紹了一款像Node或Deno的現(xiàn)代JavaScript運行時的bun在Windows下安裝過程詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-07-07
  • 深入理解Commonjs規(guī)范及Node模塊實現(xiàn)

    深入理解Commonjs規(guī)范及Node模塊實現(xiàn)

    本篇文章主要介紹了深入理解Commonjs規(guī)范及Node模塊實現(xiàn),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-05-05
  • Nodejs-child_process模塊詳細介紹

    Nodejs-child_process模塊詳細介紹

    Node.js的child進程模塊允許創(chuàng)建并行任務(wù),提高應(yīng)用性能,介紹了exec、execFile、spawn、fork等方法,解釋了它們的使用場景和優(yōu)勢,通過子進程模塊,可以執(zhí)行外部命令、腳本或創(chuàng)建新的Node.js實例,感興趣的朋友跟隨小編一起看看吧
    2024-09-09
  • nodejs 圖片預(yù)覽和上傳的示例代碼

    nodejs 圖片預(yù)覽和上傳的示例代碼

    本篇文章主要介紹了nodejs 圖片預(yù)覽和上傳的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-09-09
  • 前端如何更好的展示后端返回的十萬條數(shù)據(jù)

    前端如何更好的展示后端返回的十萬條數(shù)據(jù)

    這篇文章主要為大家介紹了前端如何更好的展示后端返回的十萬條數(shù)據(jù),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步早日升職加薪
    2021-11-11
  • node-sass常見報錯的問題及解決方法

    node-sass常見報錯的問題及解決方法

    在安裝node-sass時,經(jīng)常會遇到下載慢、版本不匹配或python錯誤等問題,使用淘寶鏡像加速下載、通過nvm管理node版本或指定node-sass版本號安裝,都能有效解決這些問題,若遇到python相關(guān)錯誤,檢查node版本是否合適通??梢越鉀Q,感興趣的朋友一起看看本文吧
    2024-09-09
  • node.js基于dgram數(shù)據(jù)報模塊創(chuàng)建UDP服務(wù)器和客戶端操作示例

    node.js基于dgram數(shù)據(jù)報模塊創(chuàng)建UDP服務(wù)器和客戶端操作示例

    這篇文章主要介紹了node.js基于dgram數(shù)據(jù)報模塊創(chuàng)建UDP服務(wù)器和客戶端操作,結(jié)合實例形式分析了node.js使用dgram數(shù)據(jù)報模塊創(chuàng)建UDP服務(wù)器和客戶端,以及進行UDP廣播、組播相關(guān)操作技巧,需要的朋友可以參考下
    2020-02-02
  • Node.js中的events事件模塊知識點總結(jié)

    Node.js中的events事件模塊知識點總結(jié)

    在本篇文章里小編給大家整理的是一篇關(guān)于Node.js中的events事件模塊知識點總結(jié)內(nèi)容,有興趣的朋友們可以跟著學(xué)習(xí)下。
    2021-12-12
  • NodeJS遠程代碼執(zhí)行

    NodeJS遠程代碼執(zhí)行

    這篇文章主要介紹了NodeJS遠程代碼執(zhí)行方法的相關(guān)資料,需要的朋友可以參考下
    2016-08-08

最新評論

敦化市| 巫山县| 拜泉县| 雅江县| 永寿县| 措勤县| 丹棱县| 建阳市| 固安县| 丰城市| 英超| 昌黎县| 孝昌县| 鄄城县| 成安县| 福清市| 吐鲁番市| 从江县| 金门县| 剑阁县| 门头沟区| 浏阳市| 眉山市| 德州市| 剑阁县| 灌南县| 益阳市| 巫溪县| 任丘市| 藁城市| 西乡县| 凯里市| 旌德县| 永清县| 岳阳县| 禹城市| 荥经县| 达拉特旗| 台中县| 呈贡县| 高平市|