Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Commit

Permalink
Switch to Jest for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
samtgarson committed Jun 13, 2017
1 parent f4da12c commit 4f2133b
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 35 deletions.
8 changes: 4 additions & 4 deletions bin/micro-start
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ const complete = () => {
spinner.succeed('Built!')
console.log(`
Next steps:
${chalk.magenta(`cd ${name}`)}
${chalk.magenta('yarn init')}
${chalk.magenta('yarn')}
${chalk.magenta('git init')}
${chalk.magenta(`> cd ${name}`)}
${chalk.magenta('> yarn init')}
${chalk.magenta('> yarn')}
${chalk.magenta('> git init')}
Happy microservicing! 👌`)
}
Expand Down
7 changes: 0 additions & 7 deletions build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ if (WATCH) {
runner = run()
}
})

process.once('SIGINT', () => {
log()
log(chalk.yellow('👋 Goodbye'))
if (runner) runner.once('exit', process.exit)
else process.exit()
})
} else {
const starter = ora('Building...').start()
webpack(config).run(() => {
Expand Down
28 changes: 14 additions & 14 deletions package.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
"micro": "^6.1.0"
},
"devDependencies": {
"ava": "^0.17.0",
"babel-jest": "^19.0.0",
"babel-core": "^6.21.0",
"babel-loader": "^6.2.10",
"babel-polyfill": "^6.20.0",
"babel-preset-stage-2": "^6.18.0",
"babel-register": "^6.18.0",
"chalk": "^1.1.3",
"eslint-config-samtgarson": "^0.0.2",
"jest": "^19.0.2",
"nodemon": "^1.11.0",
"ora": "^1.1.0",
"request": "^2.79.0",
Expand All @@ -30,8 +31,8 @@
"start": "node .",
"dev": "node build --watch",
"build": "node build",
"test": "ava && xo",
"test:spec": "ava",
"test": "jest && xo",
"test:spec": "jest",
"test:lint": "xo"
},
"xo": {
Expand All @@ -58,17 +59,16 @@
"stage-2"
]
},
"ava": {
"files": [
"test/**/*.test.js"
],
"source": [
"src/**/*.js"
],
"require": [
"babel-register",
"babel-polyfill"
"jest": {
"moduleFileExtensions": ["js"],
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/babel-jest"
},
"setupFiles": [
"<rootDir>/test/setup.js"
],
"babel": "inherit"
"testMatch": [
"<rootDir>/test/**/*.test.js"
]
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "micro-starter",
"version": "0.0.4",
"version": "0.1.0",
"description": "Start your micro app",
"main": "index.js",
"repository": "samtgarson/micro-starter",
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Basic starter kit for a Node microservice using [Micro](https://github.com/zeit/

- 🔷 [Micro](https://github.com/zeit/micro) for no fluff HTTP serving
- 📦 [Webpack](https://webpack.github.io/) for bundling with ES7 syntax
- 🚀 [AVA](https://github.com/avajs/ava) for speedy and easy to write tests
- 🃏 [Jest](https://github.com/facebook/jest) for speedy and easy to write tests
- ❤️ [XO](https://github.com/sindresorhus/xo) for no fuss linting
- 🤓 Development setup including file watching and server restarting for happy devs

Expand All @@ -30,7 +30,7 @@ micro-start my-app-name # create a new project directory ready for microservicin

### Testing

- `yarn test:spec`: Run tests with AVA
- `yarn test:spec`: Run tests with Jest
- `yarn test:lint`: Lint your code with XO
- `yarn test`: Run it all

Expand Down
19 changes: 12 additions & 7 deletions test/main.test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import test from 'ava'
import listen from 'test-listen'
import request from 'request-promise'
import get from 'request-promise'
import srv from '../src/main'

let url
test.before(async () => {
beforeEach(async () => {
url = await listen(srv)
})

test('hello world', async (t) => {
const body = await request(url)
const expected = 'hello world!'
t.is(body, expected)
afterEach(async () => {
await srv.close()
})

describe('the app', () => {
it('responds correctly', async () => {
const body = await get(url)
const expected = 'hello world!'
expect(body).toBe(expected)
})
})
1 change: 1 addition & 0 deletions test/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('babel-polyfill')

0 comments on commit 4f2133b

Please sign in to comment.