This repository has been archived by the owner on Feb 27, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
completed base implementation required for test runner
- Loading branch information
1 parent
12f7303
commit d14f0bc
Showing
20 changed files
with
984 additions
and
230 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'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 { Command } = require('adonis-ace') | ||
|
||
class RunTests extends Command { | ||
static get signature () { | ||
return `test | ||
{ type?: Define test types, needs to be unit or functional } | ||
{ --bail: Stop running tests on first failure } | ||
{ --timeout: Define a global timeout for all the tests } | ||
{ --files: Pick only specific files. File names are seperated by comma }` | ||
} | ||
|
||
static get description () { | ||
return 'Run application tests' | ||
} | ||
|
||
constructor (runner, cli) { | ||
super() | ||
this.runner = runner | ||
this.cli = cli | ||
} | ||
|
||
handle ({ type }, { bail, timeout, files }) { | ||
console.log(type) | ||
} | ||
} | ||
|
||
module.exports = RunTests |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'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 cli = require('japa/cli') | ||
|
||
cli.run('test/*/*.spec.js') |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
'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 superagent = require('superagent') | ||
const Response = require('./Response') | ||
|
||
const superagentMethods = [ | ||
'send', | ||
'set', | ||
'query', | ||
'type', | ||
'retry', | ||
'accept', | ||
'key', | ||
'cert', | ||
'timeout', | ||
'redirects', | ||
'attach', | ||
'withCredentials', | ||
'accept' | ||
] | ||
|
||
class Request { | ||
constructor (url, verb, assert) { | ||
this.agent = superagent[verb](url) | ||
this._assert = assert | ||
} | ||
|
||
then (userResolve, userReject) { | ||
if (!this._fullfilledPromise) { | ||
this._fullfilledPromise = new Promise((resolve) => { | ||
this.agent.end((error, response) => { | ||
if (error) { | ||
resolve(new Response(error, this._assert)) | ||
return | ||
} | ||
resolve(new Response(response, this._assert)) | ||
}) | ||
}) | ||
} | ||
return this._fullfilledPromise.then(userResolve, userReject) | ||
} | ||
|
||
catch (callback) { | ||
return this.then(undefined, callback) | ||
} | ||
|
||
loginAs (user) { | ||
} | ||
} | ||
|
||
superagentMethods.forEach((method) => { | ||
Request.prototype[method] = function (...args) { | ||
this.agent[method](...args) | ||
return this | ||
} | ||
}) | ||
|
||
module.exports = Request |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
'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 urlModule = require('url') | ||
|
||
class Response { | ||
constructor (resOrError, assert) { | ||
this._assert = assert | ||
this._isError = resOrError.name === 'Error' | ||
this._res = this._isError ? resOrError.response : resOrError | ||
} | ||
|
||
get status () { | ||
return this._res.status | ||
} | ||
|
||
get text () { | ||
return this._res.text | ||
} | ||
|
||
get body () { | ||
return this._res.body | ||
} | ||
|
||
get redirects () { | ||
return this._res.redirects | ||
} | ||
|
||
assertStatus (expected) { | ||
this._assert.equal(this.status, expected) | ||
} | ||
|
||
assertText (expected) { | ||
this._assert.equal(this.text, expected) | ||
} | ||
|
||
assertBody (expected) { | ||
try { | ||
this._assert.deepEqual(this.body, expected) | ||
} catch (error) { | ||
this._assert.equal(this.text, expected) | ||
} | ||
} | ||
|
||
assertJSON (expected) { | ||
this._assert.deepEqual(this.body, expected) | ||
} | ||
|
||
assertError (expected) { | ||
this.assertBody(expected) | ||
} | ||
|
||
assertRedirect (expectedUrl) { | ||
const routes = this.redirects.map((url) => urlModule.parse(url).pathname) | ||
this._assert.include(routes, expectedUrl, `Request was not redirected to ${expectedUrl}`) | ||
} | ||
} | ||
|
||
module.exports = Response |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
'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 Request = require('./Request') | ||
const apiMethods = ['get', 'post', 'put', 'delete', 'patch'] | ||
|
||
class ApiClient { | ||
constructor (Env, assert) { | ||
this._baseUrl = Env.get('TEST_SERVER_URL') | ||
this._assert = assert | ||
} | ||
|
||
/** | ||
* Returns complete url to the http server. | ||
* | ||
* @method _getCompleteUrl | ||
* | ||
* @param {String} url | ||
* | ||
* @return {String} | ||
* | ||
* @private | ||
*/ | ||
_getCompleteUrl (url) { | ||
return `${this._baseUrl}/${url}`.replace(/([^:]\/)\/+/g, '$1') | ||
} | ||
} | ||
|
||
apiMethods.forEach((method) => { | ||
ApiClient.prototype[method] = function (url) { | ||
return new Request(this._getCompleteUrl(url), method, this._assert) | ||
} | ||
}) | ||
|
||
module.exports = ApiClient |
Oops, something went wrong.