From 3b4bfdeebf3fd01bb06c384dadae94ea05cea93e Mon Sep 17 00:00:00 2001 From: Adrien Joly <531781+adrienjoly@users.noreply.github.com> Date: Fri, 16 Jun 2023 09:50:45 +0200 Subject: [PATCH] `npm run test:integration:post` controls execution of openwhyd server --- package.json | 1 + test/integration/post.api.tests.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/package.json b/package.json index 0d4e4b0..903f3db 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "start:coverage": "npx nyc --silent node app.js $@", "test-reset": "node test/reset-test-db.js", "test:integration": "npx mocha test/integration/*.js --serial --exit", + "test:integration:post": "START_WITH_ENV_FILE='./env-vars-testing.conf' mocha test/integration/*post.api.tests.js $@", "test:unit": "npx mocha test/unit/*.js --exit", "test-approval": "npx kill-port --port 8080 >/dev/null; DONT_KILL=1 START_WITH_ENV_FILE='./env-vars-testing.conf' ava test/approval.tests.js $@", "test-approval-debug": "npm run test-approval -- --fail-fast --serial", diff --git a/test/integration/post.api.tests.js b/test/integration/post.api.tests.js index b82737e..44699de 100644 --- a/test/integration/post.api.tests.js +++ b/test/integration/post.api.tests.js @@ -5,8 +5,24 @@ const request = require('request'); var { DUMMY_USER, cleanup, URL_PREFIX } = require('../fixtures.js'); var api = require('../api-client.js'); +var { START_WITH_ENV_FILE } = process.env; +const { startOpenwhydServer } = require('../approval-tests-helpers'); + describe(`post api`, function () { before(cleanup); // to prevent side effects between tests + let context = {}; + before(async () => { + if (START_WITH_ENV_FILE) { + context.serverProcess = await startOpenwhydServer({ + startWithEnv: START_WITH_ENV_FILE, + }); + } + }); + after(() => { + if (context.serverProcess?.kill) { + context.serverProcess.kill('SIGINT'); + } + }); var pId, uId; const post = {