From a79bcf3d2b0d0a79073ec8c742140f4b01a67fae Mon Sep 17 00:00:00 2001 From: Philipp Piwo Date: Fri, 25 Feb 2022 11:47:48 +0100 Subject: [PATCH] test: improved exec env, assert env and test results --- src/env/env.js | 9 +++++---- tests/happy-path.js | 10 ++++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/env/env.js b/src/env/env.js index 2c1aa134..c1f08807 100644 --- a/src/env/env.js +++ b/src/env/env.js @@ -3,8 +3,8 @@ const { spawn, exec } = require('promisify-child-process'); const { print, printError, awaitNodeAvailable } = require('../utils/utils'); const { nodeConfiguration, compilerConfiguration, proxyConfiguration } = require('../config/node-config.json'); -async function isEnvRunning() { - const info = await getInfo(); +async function isEnvRunning(cwd = './') { + const info = await getInfo(cwd); if (info) { const containers = [ @@ -76,8 +76,8 @@ async function printInfo(running) { print(await getInfo()); } -async function getInfo() { - const info = await exec('docker-compose ps'); +async function getInfo(cwd) { + const info = await exec('docker-compose ps', { cwd }); if (info && info.stdout) { return info.stdout; @@ -88,4 +88,5 @@ async function getInfo() { module.exports = { run, + isEnvRunning, }; diff --git a/tests/happy-path.js b/tests/happy-path.js index 6c8da0a1..1491dcc6 100644 --- a/tests/happy-path.js +++ b/tests/happy-path.js @@ -3,13 +3,14 @@ const { exec: execP } = require('promisify-child-process'); const fs = require('fs'); const chai = require('chai'); const chaiFiles = require('chai-files'); +const { isEnvRunning } = require('../src/env/env'); chai.use(chaiFiles); const { assert } = chai; const { file } = chaiFiles; const cwd = path.join(process.cwd(), '.testdir'); -const exec = (cmd, options) => execP(`source ~/.profile;${cmd}`, options); +const exec = (cmd, options) => execP(`. ~/.profile;${cmd}`, options); describe('Happy Path', () => { before(async () => { @@ -37,13 +38,18 @@ describe('Happy Path', () => { it('env', async () => { await exec('aeproject env', { cwd }); + assert.isTrue(await isEnvRunning(cwd)); }); it('test', async () => { - await exec('aeproject test', { cwd }); + const res = await exec('aeproject test', { cwd }); + assert.equal(res.code, 0); + assert.equal(res.stderr, ''); + assert.include(res.stdout, '2 passing'); }); it('env --stop', async () => { await exec('aeproject env --stop', { cwd }); + assert.isFalse(await isEnvRunning(cwd)); }); });