Skip to content

Commit

Permalink
test: improved exec env, assert env and test results
Browse files Browse the repository at this point in the history
  • Loading branch information
thepiwo committed Feb 28, 2022
1 parent a9a96e1 commit a79bcf3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/env/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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;
Expand All @@ -88,4 +88,5 @@ async function getInfo() {

module.exports = {
run,
isEnvRunning,
};
10 changes: 8 additions & 2 deletions tests/happy-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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));
});
});

0 comments on commit a79bcf3

Please sign in to comment.