From 494c4b2a9da5f551af7ddb7b20c0d7aea3ccf789 Mon Sep 17 00:00:00 2001 From: Stephane BARALE Date: Fri, 2 Dec 2016 01:30:51 +0100 Subject: [PATCH] Adding test, update version and README --- .gitignore | 2 ++ README.md | 47 +++++++++++++++++++++++++++++++++++++++++++++ meteor-koa-tests.js | 28 +++++++++++++++++++-------- meteor-koa.js | 4 +++- package.js | 15 +++++++++++---- 5 files changed, 83 insertions(+), 13 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c016443 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.build* +.npm diff --git a/README.md b/README.md index e69de29..e1947ed 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,47 @@ +# `ssr-wpo:meteor-koa` +[Koa](http://koajs.com/) next generation web framework with Meteor + +## Table of contents +- [Installation](#installation) +- [Api](#api) +- [Example](#example) +- [Additional koa packages](#additional) +- [Testing](#testing) + +## Installation +```bash +$ meteor add ssr-wpo:meteor-koa +``` + +## Api +See [koa api](https://github.com/koajs/koa/tree/v2.x) for more details. + +## Example +`meteor-koa` is only available on server side. (`Meteor.isServer`) + +```javascript +import { koa } from 'meteor/ssr-wpo:meteor-koa'; + +const app = koa(); + +app.use((ctx) => { + ctx.body = 'Hello World'; +}); +``` + +## Additional koa packages +Koa has many additional packages listed [here](https://github.com/koajs/koa/wiki). + +You can use them with `meteor-koa`, just simply add them with `npm` in your meteor project: +```bash +$ meteor npm install +``` + +## Testing +```bash +$ meteor test-packages ./ --driver-package practicalmeteor:mocha +``` +### With [spacejam](https://www.npmjs.com/package/spacejam) +```bash +$ spacejam-mocha ./ +``` diff --git a/meteor-koa-tests.js b/meteor-koa-tests.js index b489f21..c7d8de8 100644 --- a/meteor-koa-tests.js +++ b/meteor-koa-tests.js @@ -1,11 +1,23 @@ -// Import Tinytest from the tinytest Meteor package. -import { Tinytest } from "meteor/tinytest"; +import { WebApp } from 'meteor/webapp'; -// Import and rename a variable exported by meteor-koa.js. -import { name as packageName } from "meteor/meteor-koa"; +import { assert } from 'meteor/practicalmeteor:chai'; -// Write your tests here! -// Here is an example. -Tinytest.add('meteor-koa - example', function (test) { - test.equal(packageName, "meteor-koa"); +import { koa } from 'meteor/meteor-koa'; +import { createRequest } from 'meteor/meteor-koa-testing'; + +const app = koa(); + +app.use((ctx) => { + ctx.body = 'Hello World'; +}); + +const request = createRequest(app.listen()); + +describe('meteor koa - Hello World', function () { + it('should say "Hello World"', function (done) { + request + .get('/') + .expect(200) + .expect('Hello World', done); + }); }); diff --git a/meteor-koa.js b/meteor-koa.js index 270c4c7..22f94b2 100644 --- a/meteor-koa.js +++ b/meteor-koa.js @@ -5,6 +5,8 @@ import { WebApp } from 'meteor/webapp'; export const koa = function () { const app = new Koa(); - WebApp.connectHandlers.use(Meteor.bindEnvironment(app.callback())); + if (!Meteor.isPackageTest) { + WebApp.connectHandlers.use(Meteor.bindEnvironment(app.callback())); + } return app; }; diff --git a/package.js b/package.js index b2c7391..d828fd6 100644 --- a/package.js +++ b/package.js @@ -1,8 +1,8 @@ Package.describe({ name: 'meteor-koa', - version: '0.0.1', + version: '0.1.0', // Brief, one-line summary of the package. - summary: 'Koa next generation web framework for Meteor', + summary: 'Koa next generation web framework with Meteor', // URL to the Git repository containing the source code for this package. git: 'https://github.com/ssr-server/meteor-koa', // By default, Meteor will default to using README.md for documentation. @@ -26,7 +26,14 @@ Package.onUse(function(api) { Package.onTest(function(api) { api.use('ecmascript'); - api.use('tinytest'); + + api.use('webapp', 'server'); + + api.use('practicalmeteor:mocha'); + api.use('practicalmeteor:chai'); + api.use('meteor-koa'); - api.mainModule('meteor-koa-tests.js'); + api.use('meteor-koa-testing'); + + api.mainModule('meteor-koa-tests.js', 'server'); });