Skip to content

Commit

Permalink
orchestrate with mocha hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
m5r committed Jun 27, 2024
1 parent e787b14 commit 9d89609
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ coverage
.nyc_output
.DS_Store
test/.DS_Store
test/e2e/.cht-docker-helper
2 changes: 1 addition & 1 deletion test/e2e/.mocharc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = {
spec: require('./specs').all,
timeout: 200 * 1000, //API takes a little long to start up
reporter: 'spec',
file: [ 'test/e2e/hooks.js' ],
file: ['test/e2e/hooks.js'],
captureFile: 'test/e2e/results.txt',
exit: true,
recursive: true,
Expand Down
63 changes: 60 additions & 3 deletions test/e2e/hooks.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,66 @@
before(() => {
const path = require('path');
const fs = require('fs');
const https = require('https');
const { spawn } = require('child_process');

const projectName = 'cht_conf_e2e_tests';
const dockerHelperDirectory = path.resolve(__dirname, '.cht-docker-helper');
const dockerHelperScript = path.resolve(dockerHelperDirectory, './cht-docker-compose.sh');

const downloadDockerHelperScript = () => new Promise((resolve, reject) => {
const file = fs.createWriteStream(dockerHelperScript, { mode: 0o755 });
https
.get('https://raw.githubusercontent.com/medic/cht-core/master/scripts/docker-helper-4.x/cht-docker-compose.sh', (response) => {
response.pipe(file);
file.on('finish', () => file.close(resolve));
file.on('error', () => file.close(reject));
})
.on('error', () => {
fs.unlinkSync(file.path);
file.close(() => reject('Failed to download CHT Docker Helper script "cht-docker-compose.sh"'));
});
});

const spinUpCHT = () => new Promise((resolve, reject) => {
const childProcess = spawn(dockerHelperScript, { stdio: 'pipe', cwd: dockerHelperDirectory });
childProcess.on('error', reject);
childProcess.on('close', resolve);

const configFile = path.resolve(dockerHelperDirectory, `${projectName}.env`);
if (fs.existsSync(configFile)) {
childProcess.stdin.write('n\n');
childProcess.stdin.write('1\n');
} else {
childProcess.stdin.write('y\n');
childProcess.stdin.write('y\n');
childProcess.stdin.write(`${projectName}\n`);
}
});

const takeDownCHT = () => new Promise((resolve, reject) => {
const childProcess = spawn(dockerHelperScript, [`${projectName}.env`, 'stop'], { cwd: dockerHelperDirectory });
childProcess.on('error', reject);
childProcess.on('close', resolve);
});

before(async () => {
console.log('before');

Check warning on line 47 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 14.x

Unexpected console statement

Check warning on line 47 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 18.x

Unexpected console statement

Check warning on line 47 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 20.x

Unexpected console statement

Check warning on line 47 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 20.x

Unexpected console statement

Check warning on line 47 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 10.x

Unexpected console statement

Check warning on line 47 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 8.x

Unexpected console statement

Check warning on line 47 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 16.x

Unexpected console statement

Check warning on line 47 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 8.x

Unexpected console statement

Check warning on line 47 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 14.x

Unexpected console statement

Check warning on line 47 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 12.x

Unexpected console statement

Check warning on line 47 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 10.x

Unexpected console statement

Check warning on line 47 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 12.x

Unexpected console statement

Check warning on line 47 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 18.x

Unexpected console statement

Check warning on line 47 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 16.x

Unexpected console statement

if (!fs.existsSync(dockerHelperDirectory)) {
fs.mkdirSync(dockerHelperDirectory);
}

if (!fs.existsSync(dockerHelperScript)) {
await downloadDockerHelperScript();
}

await spinUpCHT();
});

after(() => {
after(async () => {
console.log('after');

Check warning on line 61 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 14.x

Unexpected console statement

Check warning on line 61 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 18.x

Unexpected console statement

Check warning on line 61 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 20.x

Unexpected console statement

Check warning on line 61 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 20.x

Unexpected console statement

Check warning on line 61 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 10.x

Unexpected console statement

Check warning on line 61 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 8.x

Unexpected console statement

Check warning on line 61 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 16.x

Unexpected console statement

Check warning on line 61 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 8.x

Unexpected console statement

Check warning on line 61 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 14.x

Unexpected console statement

Check warning on line 61 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 12.x

Unexpected console statement

Check warning on line 61 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 10.x

Unexpected console statement

Check warning on line 61 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 12.x

Unexpected console statement

Check warning on line 61 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 18.x

Unexpected console statement

Check warning on line 61 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 16.x

Unexpected console statement

await takeDownCHT();
});

beforeEach(() => {
Expand All @@ -12,4 +69,4 @@ beforeEach(() => {

afterEach(() => {
console.log('afterEach');

Check warning on line 71 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 14.x

Unexpected console statement

Check warning on line 71 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 18.x

Unexpected console statement

Check warning on line 71 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 20.x

Unexpected console statement

Check warning on line 71 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 20.x

Unexpected console statement

Check warning on line 71 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 10.x

Unexpected console statement

Check warning on line 71 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 8.x

Unexpected console statement

Check warning on line 71 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 16.x

Unexpected console statement

Check warning on line 71 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 8.x

Unexpected console statement

Check warning on line 71 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 14.x

Unexpected console statement

Check warning on line 71 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 12.x

Unexpected console statement

Check warning on line 71 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 10.x

Unexpected console statement

Check warning on line 71 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 12.x

Unexpected console statement

Check warning on line 71 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 18.x

Unexpected console statement

Check warning on line 71 in test/e2e/hooks.js

View workflow job for this annotation

GitHub Actions / Build for Node version 16.x

Unexpected console statement
});
});

0 comments on commit 9d89609

Please sign in to comment.