diff --git a/test/integration/setup.js b/test/integration/setup.js index 230d3ac..329f1ca 100644 --- a/test/integration/setup.js +++ b/test/integration/setup.js @@ -15,21 +15,23 @@ 'use strict'; const app = require('../../app'); -const config = require('../../config/test.json'); const createNavigator = require('./helper/navigate'); const loadFixtures = require('../../data/fixture/load'); const request = require('request'); -const errorCodeForNoService = 2; +const config = { + database: process.env.DATABASE || 'mongodb://127.0.0.1/pa11y-webservice-test', + host: process.env.HOST || '0.0.0.0', + port: Number(process.env.PORT) || 3000 +}; -// Run before all tests before(function(done) { - this.baseUrl = `http://localhost:${config.port}/`; + this.baseUrl = `http://${config.host}:${config.port}/`; this.app = null; this.last = {}; this.navigate = createNavigator(this.baseUrl, this.last); - assertTestAppIsRunning(this.baseUrl, () => { + assertServiceIsAvailable(this.baseUrl, () => { config.dbOnly = true; app(config, (error, initialisedApp) => { this.app = initialisedApp; @@ -38,17 +40,15 @@ before(function(done) { }); }); -// Run after each test afterEach(done => { loadFixtures('test', config, done); }); -// Check that the test application is running, and exit if not -function assertTestAppIsRunning(baseUrl, done) { +function assertServiceIsAvailable(baseUrl, done) { request(baseUrl, error => { if (error) { console.error(`Error: Test app not started. NODE_ENV was ${process.env.NODE_ENV}; run with \`NODE_ENV=test node index.js\``); - process.exit(errorCodeForNoService); + process.exit(); } done(); }); diff --git a/test/integration/startup.js b/test/integration/startup.js index 568c825..3b5e5fa 100644 --- a/test/integration/startup.js +++ b/test/integration/startup.js @@ -14,28 +14,21 @@ // along with Pa11y Webservice. If not, see . 'use strict'; +const util = require('util'); const assert = require('proclaim'); -const config = require('../../config/test.json'); const app = require('../../app'); -describe('pa11y-service startup', function() { +const config = { + database: process.env.DATABASE || 'mongodb://127.0.0.1/pa11y-webservice-test', + host: process.env.HOST || '0.0.0.0', + port: Number(process.env.PORT_FOR_SPINUP_TEST) || 3010 +}; - it('should start the service and call the callback', done => { - const modifiedConfig = { - database: config.database, - host: config.host, - port: config.port + 10 - }; +describe('pa11y-webservice lifecycle', function() { + it('should start and stop the service', async () => { + const service = await util.promisify(app)(config); + assert.isDefined(service); - app(modifiedConfig, (error, webservice) => { - assert.isNull(error); - assert.notStrictEqual(webservice, undefined); - - webservice.server.stop(); - - done(); - }); + await service.server.stop(); }); }); - -