Skip to content
This repository has been archived by the owner on Jan 3, 2019. It is now read-only.

Commit

Permalink
Merge branch 'master' into greenkeeper/typescript-2.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
clebert committed Mar 27, 2017
2 parents d0626da + 92d90a3 commit b70dd9a
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 28 deletions.
17 changes: 9 additions & 8 deletions README.md
Expand Up @@ -117,22 +117,23 @@ module.exports = {
### Test

```ts
test(name: string, implementation: (t: Test) => Promise<void>, stepTimeout?: number): void
test(name: string, implementation?: (t: Test) => Promise<void>, stepTimeout?: number): void

skip(name: string, implementation?: (t: Test) => Promise<void>, stepTimeout?: number): void

todo(name: string, implementation?: (t: Test) => Promise<void>, stepTimeout?: number): void
skip(name: string, implementation: (t: Test) => Promise<void>, stepTimeout?: number): void
```

```ts
import {skip, test, todo} from 'cybernaut';
import {skip, test} from 'cybernaut';

test('foo'); // This test will be marked as TODO

test('foo', async t => {
test('bar', async t => { // This test will be executed
// ...
});

skip('bar');
todo('baz');
skip('baz', async t => { // This test won't be executed (and marked as SKIP)
// ...
});
```

#### Methods
Expand Down
3 changes: 3 additions & 0 deletions fixtures/test-config.js
@@ -0,0 +1,3 @@
module.exports = {
dependencies: []
};
7 changes: 7 additions & 0 deletions fixtures/test.e2e.js
@@ -0,0 +1,7 @@
const {skip, test} = require('../dist/index');

test('foo');

skip('bar', t => {
// ...
});
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -43,6 +43,7 @@
"dist/config.js",
"dist/index.js",
"example/**",
"fixtures/**",
"wallaby.js"
],
"reporter": [
Expand Down
48 changes: 48 additions & 0 deletions src/__tests__/index.test.ts
@@ -0,0 +1,48 @@
import test from 'ava';
import {execFile} from 'child_process';
import {join} from 'path';

interface Result {
readonly error: Error | null;
readonly stdout: string;
readonly stderr: string;
}

let result: Result;

test.cb.before(t => {
execFile(process.execPath, [
join(__dirname, '../index.js'), 'test-config.js'
], {cwd: join(__dirname, '../../fixtures')}, (error, stdout, stderr) => {
result = {error, stdout, stderr};

t.end();
});
});

test('`error` should be null', t => {
t.plan(1);

t.is(result.error, null);
});

test('`stdout` should contain a test marked as TODO', t => {
t.plan(1);

t.regex(result.stdout, /ok 1 - foo # TODO/);
});

test('`stdout` should contain a test marked as SKIP', t => {
t.plan(1);

t.regex(result.stdout, /ok 2 - bar # SKIP/);
});

test('`stderr` should contain a copy of the configuration', t => {
t.regex(result.stderr, /capabilities: \{ browserName: 'chrome' \}/);
t.regex(result.stderr, /concurrency: 1/);
t.regex(result.stderr, /dependencies: \[\]/);
t.regex(result.stderr, /exclude: \[ '\*\*\/node_modules\/\*\*\/\*' \]/);
t.regex(result.stderr, /include: '\*\*\/\*\.e2e\.js'/);
t.regex(result.stderr, /stepTimeout: 10000/);
});
34 changes: 15 additions & 19 deletions src/index.ts
Expand Up @@ -57,20 +57,24 @@ const tasks: (() => void)[] = [];

export function test(
name: string,
implementation: Implementation,
implementation?: Implementation,
stepTimeout: number = config.stepTimeout
): void {
tasks.push(() => {
// tslint:disable-next-line no-floating-promises
tap.test(name, {timeout: 0, diagnostic: false}, async t => {
const driver = await new Builder().withCapabilities(
config.capabilities
).build();

try {
await implementation(new TapTest(driver, stepTimeout, t));
} finally {
await driver.quit();
tap.test(name, {
diagnostic: false, timeout: 0, todo: !implementation
}, async t => {
if (implementation) {
const driver = await new Builder().withCapabilities(
config.capabilities
).build();

try {
await implementation(new TapTest(driver, stepTimeout, t));
} finally {
await driver.quit();
}
}
}).catch((error: Error) => {
tap.fail(error.message);
Expand All @@ -79,21 +83,13 @@ export function test(
}

export function skip(
name: string, implementation?: Implementation, stepTimeout?: number
name: string, implementation: Implementation, stepTimeout?: number
): void {
tasks.push(() => {
tap.test(name, {skip: true}); // tslint:disable-line no-floating-promises
});
}

export function todo(
name: string, implementation?: Implementation, stepTimeout?: number
): void {
tasks.push(() => {
tap.test(name, {todo: true}); // tslint:disable-line no-floating-promises
});
}

if (require.main !== module) {
const packageName = require('../package.json').name;

Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Expand Up @@ -10,6 +10,7 @@
"coverage",
"dist",
"example",
"fixtures",
"node_modules"
]
}
2 changes: 1 addition & 1 deletion wallaby.js
Expand Up @@ -3,7 +3,7 @@ module.exports = function (wallaby) {

return {
files: ['src/**/*.ts', '!src/**/*.test.ts'],
tests: ['src/**/*.test.ts'],
tests: ['src/**/*.test.ts', '!src/__tests__/index.test.ts'],
env: {type: 'node', runner: 'node'},
testFramework: 'ava'
};
Expand Down

0 comments on commit b70dd9a

Please sign in to comment.