Skip to content

Commit

Permalink
➕ Describe / add manual execution option(immediate)
Browse files Browse the repository at this point in the history
  • Loading branch information
59naga committed Aug 19, 2018
1 parent 716aca6 commit 60db72b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 28 deletions.
64 changes: 36 additions & 28 deletions src/describe.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default class Describe {
this.opts = Object.assign(
{
timeout: 1000,
immediate: true,
concurrency: Infinity
},
options
Expand Down Expand Up @@ -39,40 +40,47 @@ export default class Describe {
this.block.setOptions = this.setOptions.bind(this);

this.waitForChildren = this.waitForChildren.bind(this);
this.evaluted = new Promise(resolve => {
if (this.opts.immediate) {
this.evaluateBlock = () => {};
setImmediate(resolve);
} else {
this.evaluateBlock = resolve;
}
});
this.finish = new Promise(finish => {
this.busy = new Promise(free => {
this.busy = new Promise(async free => {
await this.evaluted;
try {
await Promise.each(this.hooks.before, Promise.try);
} catch (error) {
this.opts.reporter.fail("before hooks", error);
process.emit("exit");
}

while (this.tasks.length) {
const tasks = this.tasks.slice();
this.tasks.length = 0;

if (this.opts.concurrency === 1) {
await Promise.each(tasks, ([title, task]) => task());
} else {
await Promise.map(tasks, ([title, task]) => task(), {
concurrency: this.opts.concurrency || Infinity
});
}
}
free();

setImmediate(async () => {
await this.waitForChildren();
try {
await Promise.each(this.hooks.before, Promise.try);
await Promise.each(this.hooks.after, Promise.try);
} catch (error) {
this.opts.reporter.fail("before hooks", error);
this.opts.reporter.fail("after hooks", error);
process.emit("exit");
}

while (this.tasks.length) {
const tasks = this.tasks.slice();
this.tasks.length = 0;

if (this.opts.concurrency === 1) {
await Promise.each(tasks, ([title, task]) => task());
} else {
await Promise.map(tasks, ([title, task]) => task(), {
concurrency: this.opts.concurrency || Infinity
});
}
}
free();

setImmediate(async () => {
await this.waitForChildren();
try {
await Promise.each(this.hooks.after, Promise.try);
} catch (error) {
this.opts.reporter.fail("after hooks", error);
process.emit("exit");
}
finish();
});
finish();
});
});
});
Expand Down
8 changes: 8 additions & 0 deletions test/describe/immediate false(manual)/expected.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const code = 1;
export const stdout = `
foo
0 passing (ELAPSED ms)
`;

export const stderr = ``;
12 changes: 12 additions & 0 deletions test/describe/immediate false(manual)/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { describe } from "eastern";

describe(
"foo",
it => {
it("bar");
it("bar", () => {
console.log("baz");
});
},
{ immediate: false }
);

0 comments on commit 60db72b

Please sign in to comment.