Last active
December 28, 2017 18:29
-
-
Save JumpLink/030ff047f909183b3973cb91d1f63172 to your computer and use it in GitHub Desktop.
Server application in TypeScript with Koa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// example code for this tutorial: https://jumplink.eu/blog/post/serveranwendung-direkt-typescript-entwickeln-und-testen | |
import 'mocha'; | |
import ChaiHttp = require('chai-http'); | |
import * as chai from 'chai'; | |
chai.use(ChaiHttp); | |
describe('test route', function() { | |
it('should response with status 200', function(done) { | |
chai.request('http://localhost:3000') | |
.get('/') | |
.end((err, res) => { | |
chai.expect(err).to.be.null; | |
chai.expect(res).to.have.status(200); | |
done(err); | |
}); | |
}); | |
it('should response Hello World', function(done) { | |
chai.request('http://localhost:3000') | |
.get('/') | |
.end((err, res) => { | |
chai.expect(res).to.be.text; | |
chai.assert.equal(res.text, 'Hello World'); | |
done(err); | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as Koa from 'koa'; | |
const app = new Koa(); | |
app.use(async ctx => { | |
ctx.body = 'Hello World'; | |
}); | |
app.listen(3000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "typescript-test", | |
"version": "1.0.0", | |
"description": "Beispielprojekt für eine Serveranwendung in TypeScript", | |
"main": "index.ts", | |
"author": "Pascal Garber", | |
"license": "MIT", | |
"scripts": { | |
"start": "ts-node index.ts", | |
"test": "mocha -r ts-node/register **/*.spec.ts", | |
"watch": "nodemon -e ts -x 'npm run start'", | |
"watch-test": "nodemon -e ts -x 'npm run test'" | |
}, | |
"dependencies": { | |
"@types/chai": "^4.0.10", | |
"@types/chai-http": "^3.0.3", | |
"@types/koa": "^2.0.43", | |
"@types/mocha": "^2.2.45", | |
"chai": "^4.1.2", | |
"chai-http": "^3.0.0", | |
"koa": "^2.4.1", | |
"mocha": "^4.0.1", | |
"nodemon": "^1.14.3", | |
"ts-node": "^4.1.0", | |
"typescript": "^2.6.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment