From 09ada29881cf6251cfddc503b0f53f01f07de90f Mon Sep 17 00:00:00 2001 From: jongleberry Date: Wed, 4 Nov 2015 11:15:18 -0800 Subject: [PATCH] test: add a babel example --- Makefile | 3 ++- package.json | 3 ++- test/babel/.babelrc | 3 +++ test/babel/_test.js | 42 ++++++++++++++++++++++++++++++++++++++++++ test/babel/index.js | 6 ++++++ 5 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 test/babel/.babelrc create mode 100644 test/babel/_test.js create mode 100644 test/babel/index.js diff --git a/Makefile b/Makefile index a0c97bc..44a89df 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,8 @@ REQUIRED = --require should --require should-http TESTS = test/application/* \ test/context/* \ test/request/* \ - test/response/* + test/response/* \ + test/babel/index.js lint: @./node_modules/.bin/eslint lib test diff --git a/package.json b/package.json index 7213ac5..84c6150 100644 --- a/package.json +++ b/package.json @@ -42,8 +42,9 @@ "vary": "^1.0.0" }, "devDependencies": { - "babel": "^5.0.0", + "babel-core": "^6.0.20", "babel-eslint": "^4.1.3", + "babel-preset-stage-3": "^6.0.15", "eslint": "^1.6.0", "eslint-config-standard": "^4.4.0", "eslint-plugin-standard": "^1.3.1", diff --git a/test/babel/.babelrc b/test/babel/.babelrc new file mode 100644 index 0000000..1d63d54 --- /dev/null +++ b/test/babel/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["stage-3"] +} diff --git a/test/babel/_test.js b/test/babel/_test.js new file mode 100644 index 0000000..6459c49 --- /dev/null +++ b/test/babel/_test.js @@ -0,0 +1,42 @@ +'use strict'; + +const request = require('supertest'); +const Koa = require('../..'); + +describe('require("babel-core/register")', () => { + describe('app.use(fn)', () => { + it('should compose middleware w/ async functions', done => { + const app = new Koa(); + const calls = []; + + app.use(async function (ctx, next){ + calls.push(1); + await next(); + calls.push(6); + }); + + app.use(async function (ctx, next){ + calls.push(2); + await next(); + calls.push(5); + }); + + app.use(async function (ctx, next){ + calls.push(3); + await next(); + calls.push(4); + }); + + const server = app.listen(); + + request(server) + .get('/') + .expect(404) + .end(err => { + if (err) return done(err); + calls.should.eql([1, 2, 3, 4, 5, 6]); + done(); + }); + }); + }); +}); diff --git a/test/babel/index.js b/test/babel/index.js new file mode 100644 index 0000000..939dd71 --- /dev/null +++ b/test/babel/index.js @@ -0,0 +1,6 @@ +'ues strict'; + +// http://babeljs.io/docs/setup/#babel_register + +require('babel-core/register'); +require('./_test.js');