diff --git a/package.json b/package.json index cb9dee1..67d05dc 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "type": "module", "scripts": { "start": "node index.js", - "test": "npm run test:all", + "test": "npm run test:unit", "test:all": "export SVC_ENV=test && c8 --reporter=text mocha --exit --timeout 15000 --recursive test/unit test/e2e/automated/", "test:unit": "export SVC_ENV=test && c8 --reporter=text mocha --exit --timeout 15000 --recursive test/unit/", "test:e2e:auto": "export SVC_ENV=test && mocha --exit --timeout 15000 test/e2e/automated/", diff --git a/test/e2e/automated/a00-liveness.rest-e2e.js b/test/e2e/automated/a00-liveness.rest-e2e.js new file mode 100644 index 0000000..b4981fb --- /dev/null +++ b/test/e2e/automated/a00-liveness.rest-e2e.js @@ -0,0 +1,32 @@ +/* + Liveness test runs before all other tests to ensure the server is running. +*/ + +// Public npm libraries +import { assert } from 'chai' + +import axios from 'axios' + +// const sinon = require('sinon') + +// Local support libraries +import config from '../../../config/index.js' +// import Server from '../../../bin/server.js' +// import testUtils from '../../utils/test-utils.js' +// const adminLib = new AdminLib() + +const LOCALHOST = `http://localhost:${config.port}` + +describe('#Check Server Liveness', () => { + // before(async () => { + it('should confirm the server is running', async () => { + try { + const response = await axios.get(`${LOCALHOST}/`) + assert(response.status === 200, 'Server is running, continuing with E2E tests.') + } catch (err) { + console.log('\nServer is not running, exiting tests.') + console.log('Start the server with `npm start` before running E2E tests.\n') + process.exit(1) + } + }) +}) diff --git a/test/e2e/automated/a01-auth.rest-e2e.js b/test/e2e/automated/a01-auth.rest-e2e.js index d6d21d0..1965c5c 100644 --- a/test/e2e/automated/a01-auth.rest-e2e.js +++ b/test/e2e/automated/a01-auth.rest-e2e.js @@ -13,7 +13,7 @@ import axios from 'axios' // Local support libraries import config from '../../../config/index.js' -import Server from '../../../bin/server.js' +// import Server from '../../../bin/server.js' import testUtils from '../../utils/test-utils.js' import AdminLib from '../../../src/adapters/admin.js' const adminLib = new AdminLib() @@ -26,10 +26,12 @@ const LOCALHOST = `http://localhost:${config.port}` if (!config.noMongo) { describe('Auth', () => { before(async () => { - const app = new Server() + // const app = new Server() // This should be the first instruction. It starts the REST API server. - await app.startServer() + // await app.startServer() + + // TODO: // Stop the IPFS node for the rest of the e2e tests. // await app.controllers.adapters.ipfs.stop() diff --git a/test/utils/test-utils.js b/test/utils/test-utils.js index 5758dbc..0afbbd5 100644 --- a/test/utils/test-utils.js +++ b/test/utils/test-utils.js @@ -47,7 +47,7 @@ async function deleteAllUsers () { await thisUser.remove() } } catch (err) { - console.error('Error in test-utils.js/deleteAllUsers()') + console.error('Error in test-utils.js/deleteAllUsers(): ', err) } }