Skip to content

Commit

Permalink
fix leaking config between tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jelhan committed Aug 6, 2019
1 parent d71386b commit da41a5c
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion node-tests/e2e/deliver-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,27 @@ const fs = require('fs-extra');

const CSP_META_TAG_REG_EXP = /<meta http-equiv="Content-Security-Policy" content="(.*)">/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);

Expand All @@ -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.
Expand Down

0 comments on commit da41a5c

Please sign in to comment.