From da41a5c2292a676a1e2d688cfb50f62274da1b29 Mon Sep 17 00:00:00 2001 From: Jeldrik Hanschke Date: Tue, 6 Aug 2019 23:34:15 +0200 Subject: [PATCH] fix leaking config between tests --- node-tests/e2e/deliver-test.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/node-tests/e2e/deliver-test.js b/node-tests/e2e/deliver-test.js index 56ca567..804c320 100644 --- a/node-tests/e2e/deliver-test.js +++ b/node-tests/e2e/deliver-test.js @@ -6,13 +6,27 @@ const fs = require('fs-extra'); const CSP_META_TAG_REG_EXP = //i; +function getConfigPath(app) { + return app.filePath('config/content-security-policy.js'); +} + async function setConfig(app, config) { - let file = app.filePath('config/content-security-policy.js'); + let file = getConfigPath(app); let content = `module.exports = function() { return ${JSON.stringify(config)}; }`; await fs.writeFile(file, content); } +async function removeConfig(app) { + let file = getConfigPath(app); + + if (!fs.existsSync(file)) { + return; + } + + return fs.remove(file); +} + describe('e2e: delivers CSP as configured', function() { this.timeout(300000); @@ -24,6 +38,10 @@ describe('e2e: delivers CSP as configured', function() { await app.create('default', { noFixtures: true }); }); + afterEach(async function() { + await removeConfig(app); + }); + // Server isn't shutdown successfully if `app.startServer()` and `app.stopServer()` // are not wrapped inside a describe block. Therefore all tests after the first one // fail with a "Port 49741 is already in use" error.