Skip to content

Commit

Permalink
fix(tests): Log errors when running approval tests (#485)
Browse files Browse the repository at this point in the history
* fix(tests): Log errors when running approval tests

* reduce risk of server staying alive

* add (slower) "test-approval-debug" script to stop on first test failure
  • Loading branch information
adrienjoly committed Oct 9, 2021
1 parent 6707b3d commit da43c20
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/lib/my-http-wrapper/http/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const formidable = require('formidable');
const qset = require('q-set'); // instead of body-parser, for form fields with brackets
const sessionTracker = require('../../../controllers/admin/session.js');

const LOG_THRESHOLD = 500;
const LOG_THRESHOLD = process.env.LOG_REQ_THRESHOLD_MS || 500;

// From Response.js

Expand Down
1 change: 1 addition & 0 deletions env-vars-testing.conf
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ LAST_FM_API_SECRET=""
ALGOLIA_APP_ID=""
ALGOLIA_API_KEY=""
DISABLE_DATADOG="true"
LOG_REQ_THRESHOLD_MS="5000"
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"test-reset": "node test/reset-test-db.js",
"test-api": "npx mocha test/api/*.js --serial --exit",
"test-unit": "npx mocha test/unit/*.js --exit",
"test-approval": "START_WITH_ENV_FILE='./env-vars-testing.conf' ava test/approval.tests.js",
"test-approval": "START_WITH_ENV_FILE='./env-vars-testing.conf' ava test/approval.tests.js $@",
"test-approval-debug": "npm run test-approval -- --fail-fast --serial",
"test:cypress:dev": "node_modules/.bin/cypress open",
"test:cypress": "node_modules/.bin/cypress run",
"test": ". ./env-vars-testing.sh && npm run test-unit && npm run test-api && npm run test:cypress",
Expand Down
2 changes: 1 addition & 1 deletion test/approval.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ test.before(async (t) => {

test.after((t) => {
if (t.context.serverProcess) {
t.context.serverProcess.kill();
t.context.serverProcess.kill('SIGINT');
}
});

Expand Down
15 changes: 15 additions & 0 deletions test/db-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,27 @@ async function insertTestData(url, docsPerCollection) {
await mongoClient.close();
}

const errPrinter = ((blocklist) => {
return (chunk) => {
const message = chunk.toString();
if (!blocklist.some((term) => message.includes(term)))
console.error(message);
};
})([
'closing server',
'deprecated',
'gm: command not found',
'convert: command not found',
'please install graphicsmagick',
]);

async function startOpenwhydServer(env) {
const serverProcess = childProcess.fork(
'./app.js',
['--fakeEmail', '--digestInterval', '-1'],
{ env, silent: true }
);
serverProcess.stderr.on('data', errPrinter);
await waitOn({ resources: [`http://localhost:${env.WHYD_PORT}`] });
return serverProcess;
}
Expand Down

0 comments on commit da43c20

Please sign in to comment.