Skip to content

Commit

Permalink
Merge pull request #392 from thefrontside/cli-suite-improvements
Browse files Browse the repository at this point in the history
CLI suite improvements
  • Loading branch information
jnicklas authored Jul 9, 2020
2 parents fbb2ce1 + 95d4f9c commit da93513
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 29 deletions.
2 changes: 2 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
},
"devDependencies": {
"@bigtest/todomvc": "^0.5.2",
"@effection/channel": "^0.6.4",
"@effection/events": "^0.7.4",
"@effection/subscription": "^0.9.0",
"@frontside/tsconfig": "*",
"@types/capture-console": "1.0.0",
"@types/json5": "^0.0.30",
Expand Down
67 changes: 40 additions & 27 deletions packages/cli/test/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,57 +14,70 @@ function run(...args: string[]) {
describe('@bigtest/cli', function() {
this.timeout(process.env.CI ? 120000 : 30000);

describe('starting the server', () => {
let child: Process;
describe('start', () => {
describe('starting the server', () => {
let child: Process;

beforeEach(async () => {
child = await World.spawn(run('server', '--launch', 'chrome.headless'));
});
beforeEach(async () => {
child = await World.spawn(run('server', '--launch', 'chrome.headless'));
});

afterEach(async () => {
await World.spawn(child.close());
});
afterEach(async () => {
await World.spawn(child.close());
});

it('outputs that the server was started successfully', async () => {
await World.spawn(child.stdout?.waitFor("[orchestrator] running!"));
it('outputs that the server was started successfully', async () => {
await World.spawn(child.stdout?.waitFor("[orchestrator] running!"));
});
});
});

describe('running the suite', () => {
describe('test', () => {
describe('running the suite successfully', () => {
let startChild: Process;
let runChild: Process;

beforeEach(async () => {
await World.spawn(child.stdout?.waitFor("[orchestrator] running!"));
startChild = await World.spawn(run('server', '--launch', 'chrome.headless'));

await World.spawn(startChild.stdout?.waitFor("[orchestrator] running!"));

runChild = await World.spawn(run('test'));

await World.spawn(runChild.join());
});

afterEach(async () => {
await World.spawn(startChild.close());
});

it('exits successfully', async () => {
expect(runChild.code).toEqual(0);
expect(runChild.stdout?.output).toContain("SUCCESS")
});
});
});

describe('running the suite in CI mode', () => {
let child: Process;
describe('ci', () => {
describe('running the suite successfully', () => {
let child: Process;

beforeEach(async () => {
child = await World.spawn(run('ci', '--launch', 'chrome.headless', '--log-level', 'debug'));
await World.spawn(child.stdout?.waitFor("[orchestrator] running!"));
await World.spawn(child.join());
});
beforeEach(async () => {
child = await World.spawn(run('ci', '--launch', 'chrome.headless', '--log-level', 'debug'));
await World.spawn(child.stdout?.waitFor("[orchestrator] running!"));
await World.spawn(child.join());
});

afterEach(async () => {
await World.spawn(child.close());
});
afterEach(async () => {
await World.spawn(child.close());
});

it('exits successfully', async () => {
expect(child.code).toEqual(0);
expect(child.stdout?.output).toContain("✓ [step] Passing Test -> first step")
expect(child.stdout?.output).toContain("✓ [assertion] Passing Test -> check the thing")
expect(child.stdout?.output).toContain("✓ SUCCESS")
it('exits successfully', async () => {
expect(child.code).toEqual(0);
expect(child.stdout?.output).toContain("✓ [step] Passing Test -> first step")
expect(child.stdout?.output).toContain("✓ [assertion] Passing Test -> check the thing")
expect(child.stdout?.output).toContain("✓ SUCCESS")
});
});
});
});
Expand Down
9 changes: 7 additions & 2 deletions packages/cli/test/helpers/stream.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { resource } from 'effection';
import { on, once } from '@effection/events';
import { on } from '@effection/events';
import { subscribe } from '@effection/subscription';
import { Channel } from '@effection/channel';
import { Readable } from 'stream';

export class Stream {
public output = "";
private semaphore = new Channel<true>();

static *of(value: Readable, verbose = false) {
let testStream = new Stream(value, verbose);
Expand All @@ -17,15 +20,17 @@ export class Stream {
while(true) {
let { value: chunk } = yield events.next();
this.output += chunk;
this.semaphore.send(true);
if(this.verbose) {
console.debug(chunk.toString());
}
}
}

*waitFor(text: string) {
let subscription = yield subscribe(this.semaphore);
while(!this.output.includes(text)) {
yield once(this.stream, "data");
yield subscription.next();
}
}
}
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2208,6 +2208,13 @@
"@effection/events" "^0.7.4"
effection "^0.7.0"

"@effection/subscription@^0.8.0":
version "0.8.1"
resolved "https://registry.yarnpkg.com/@effection/subscription/-/subscription-0.8.1.tgz#aa0286549b2bb833f211010db33c0324f6b59d81"
integrity sha512-0e9U1dAfc4vbr/aRy53VG9Qdh4gwFMcnNJYcYzjHfMu0GznaX4UjwuOdq7W29UfNUV/gTqA4ij95kPUfEwtONQ==
dependencies:
effection "^0.7.0"

"@effection/subscription@^0.9.0":
version "0.9.0"
resolved "https://registry.yarnpkg.com/@effection/subscription/-/subscription-0.9.0.tgz#5a7ec6ab6381b9d0698e64dc1f7f15368593b145"
Expand Down

0 comments on commit da93513

Please sign in to comment.