Skip to content
This repository has been archived by the owner on Feb 27, 2022. It is now read-only.

Commit

Permalink
feat(*): implement suite and test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed May 29, 2017
0 parents commit 831b174
Show file tree
Hide file tree
Showing 13 changed files with 1,023 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# editorconfig.org
root = true

[*]
indent_size = 2
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
coverage
node_modules
.DS_Store
npm-debug.log
.nyc_output
9 changes: 9 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
coverage
node_modules
.DS_Store
npm-debug.log
test
.travis.yml
.editorconfig
benchmarks
.nyc_output
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: node_js
node_js:
- node
- 7.0.0
sudo: false
install:
- npm install
notifications:
slack:
secure: m91zkX2cLVDRDMBAUnR1d+hbZqtSHXLkuPencHadhJ3C3wm53Box8U25co/goAmjnW5HNJ1SMSIg+DojtgDhqTbReSh5gSbU0uU8YaF8smbvmUv3b2Q8PRCA7f6hQiea+a8+jAb7BOvwh66dV4Al/1DJ2b4tCjPuVuxQ96Wll7Pnj1S7yW/Hb8fQlr9wc+INXUZOe8erFin+508r5h1L4Xv0N5ZmNw+Gqvn2kPJD8f/YBPpx0AeZdDssTL0IOcol1+cDtDzMw5PAkGnqwamtxhnsw+i8OW4avFt1GrRNlz3eci5Cb3NQGjHxJf+JIALvBeSqkOEFJIFGqwAXMctJ9q8/7XyXk7jVFUg5+0Z74HIkBwdtLwi/BTyXMZAgsnDjndmR9HsuBP7OSTJF5/V7HCJZAaO9shEgS8DwR78owv9Fr5er5m9IMI+EgSH3qtb8iuuQaPtflbk+cPD3nmYbDqmPwkSCXcXRfq3IxdcV9hkiaAw52AIqqhnAXJWZfL6+Ct32i2mtSaov9FYtp/G0xb4tjrUAsDUd/AGmMJNEBVoHtP7mKjrVQ35cEtFwJr/8SmZxGvOaJXPaLs43dhXKa2tAGl11wF02d+Rz1HhbOoq9pJvJuqkLAVvRdBHUJrB4/hnTta5B0W5pe3mIgLw3AmOpk+s/H4hAP4Hp0gOWlPA=
88 changes: 88 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@

# Testing In AdonisJs

Testing in AdonisJs should be natural, simple and intutive enough that even a entry level guy can write tests.

One should be able to do follow

1. Load entire adonisjs app.
2. Run custom code before the test-runner and after the test-runner.
3. Run stuff before the test-suite and after the test-suite
4. Use any service providers.
5. Fake ioc container bindings.
6. Use middleware for testing


## Dummy syntax.

```js
const Runner = use('Test/Runner')

// Applied on all the suites and also re-initiatied for each
// suite since context is passed along.
Runner.trait([''])
```

```js
const Suite = use('Test/Suite')()

Suite.trait('Lucid/AutoRoll')
Suite.trait('Test/Chrome', options)
Suite.traits([{ 'Test/Chrome': options }])

Suite.before(function () {
})

Suite.after(function () {
})

Suite.beforeEach(function () {
})

Suite.afterEach(function () {
})

Suite.test('sadasd', async (assert, { browser }) => {
await browser.visit('')
})

Suite.test('sadasd', async (assert, { browser }) => {
await browser.visit('')
})
```

Each trait will received following to setup lifecycle

```js
function chromeTrait (suiteInstance) {
suiteInstance.beforeEach(() => {
})

Context.getter('browser', function () {
return new Browser()
}, true)
}
```

Also with class

```js
class ChromeTrait {
static get inject () {

}

handle (suiteInstance) {
suiteInstance.beforeEach(() => {
})
}
}
```

In nutshell we have

1. Test Runner - The guy which starts and ends the tests
2. Test Suite - Each suite can have traits, which are called as soon as user calls `test.trait()`
3. Context ( set for each test ) - Each tests has it's own context

Rest all is JAPA and other tools
22 changes: 22 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
environment:
matrix:
- nodejs_version: 'Stable'
- nodejs_version: '7'

init:
git config --global core.autocrlf true

install:
- ps: Install-Product node $env:nodejs_version
- npm install

test_script:
- node --version
- npm --version
- npm run test:win

build: off
clone_depth: 1

matrix:
fast_finish: true
49 changes: 49 additions & 0 deletions lib/props.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
'use strict'

/*
* adonis-vow
*
* (c) Harminder Virk <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

let DEFAULT_TIMEOUT = 2000
let BAIL_TESTS = false
let EMITTER = new (require('events'))()
let GREP_TERM = null

module.exports = {
get timeout () {
return DEFAULT_TIMEOUT
},

set timeout (timeout) {
DEFAULT_TIMEOUT = timeout
},

get bail () {
return BAIL_TESTS
},

set bail (state) {
BAIL_TESTS = !!state
},

get emitter () {
return EMITTER
},

set emitter (emitterInstance) {
EMITTER = emitterInstance
},

get grep () {
return GREP_TERM
},

set grep (term) {
GREP_TERM = term
}
}
37 changes: 37 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "adonis-vow",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"lint": "standard",
"pretest": "npm run lint",
"posttest": "npm run coverage",
"test:local": "DEBUG=adonis:vow node --harmony-async-await ./node_modules/.bin/japa",
"test": "./node_modules/.bin/nyc npm run test:local",
"test:win": "set DEBUG=adonis:vow && node --harmony-async-await ./node_modules/japa-cli/index.js",
"coverage": "nyc report --reporter=text-lcov | coveralls"
},
"keywords": [],
"author": "",
"license": "MIT",
"devDependencies": {
"adonis-fold": "git+https://github.com/poppinss/adonis-fold.git#dawn",
"adonis-sink": "^1.0.2",
"coveralls": "^2.13.1",
"cz-conventional-changelog": "^2.0.0",
"japa": "git+https://github.com/thetutlage/japa.git#develop",
"japa-cli": "^1.0.1",
"nyc": "^10.3.2",
"standard": "^10.0.2"
},
"dependencies": {
"japa": "git+https://github.com/thetutlage/japa.git#develop",
"p-series": "^1.0.0"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}
30 changes: 30 additions & 0 deletions providers/VowProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict'

/*
* adonis-vow
*
* (c) Harminder Virk <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

const { ServiceProvider } = require('adonis-fold')

class VowProvider extends ServiceProvider {
register () {
this.app.singleton('Test/Runner', (app) => {
const Runner = require('../src/Runner')
return new Runner(app.use('Adonis/Src/Config'))
})

this.app.bind('Test/Suite', (app) => {
const Runner = app.use('Test/Runner')
return function (title) {
return Runner.suite(title)
}
})
}
}

module.exports = VowProvider
Loading

0 comments on commit 831b174

Please sign in to comment.