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

Commit

Permalink
feat(command): start http server when running test
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Jul 29, 2017
1 parent a89ed8f commit 2c1b68d
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion commands/RunTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ const _ = require('lodash')
const { Command } = require('@adonisjs/ace')

class RunTests extends Command {
constructor (runner, cli) {
constructor (runner, cli, server) {
super()
this.runner = runner
this.cli = cli
this.server = server
}

/**
Expand Down Expand Up @@ -132,13 +133,41 @@ class RunTests extends Command {
}

try {
/**
* Starting HTTP server
*/
this.server.listen()

/**
* Setting test url when its not defined
*/
if (!process.env.TEST_SERVER_URL) {
process.env.TEST_SERVER_URL = `http://${process.env.HOST}:${process.env.PORT}`
}

/**
* Requiring all test files.
*/
_.each(testFiles, (file) => require(file))

/**
* Running the test runner
*/
await this.runner.run()
} catch (error) {
/**
* If log the error when test suite was not executed.
* Otherwise test reporter will report the error
*/
if (!this.runner.executedStack) {
console.error(error)
}
}

/**
* Closing HTTP server
*/
this.server.getInstance().close()
}
}

Expand Down

0 comments on commit 2c1b68d

Please sign in to comment.