diff --git a/README.md b/README.md index e06485d..7d6abdd 100644 --- a/README.md +++ b/README.md @@ -117,22 +117,23 @@ module.exports = { ### Test ```ts -test(name: string, implementation: (t: Test) => Promise, stepTimeout?: number): void +test(name: string, implementation?: (t: Test) => Promise, stepTimeout?: number): void -skip(name: string, implementation?: (t: Test) => Promise, stepTimeout?: number): void - -todo(name: string, implementation?: (t: Test) => Promise, stepTimeout?: number): void +skip(name: string, implementation: (t: Test) => Promise, 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 diff --git a/fixtures/test-config.js b/fixtures/test-config.js new file mode 100644 index 0000000..c9e1abc --- /dev/null +++ b/fixtures/test-config.js @@ -0,0 +1,3 @@ +module.exports = { + dependencies: [] +}; diff --git a/fixtures/test.e2e.js b/fixtures/test.e2e.js new file mode 100644 index 0000000..99c9e98 --- /dev/null +++ b/fixtures/test.e2e.js @@ -0,0 +1,7 @@ +const {skip, test} = require('../dist/index'); + +test('foo'); + +skip('bar', t => { + // ... +}); diff --git a/package.json b/package.json index dac5c60..f68b949 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "dist/config.js", "dist/index.js", "example/**", + "fixtures/**", "wallaby.js" ], "reporter": [ diff --git a/src/__tests__/index.test.ts b/src/__tests__/index.test.ts new file mode 100644 index 0000000..dcdaf32 --- /dev/null +++ b/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/); +}); diff --git a/src/index.ts b/src/index.ts index ff31297..0bc4721 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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); @@ -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; diff --git a/tsconfig.json b/tsconfig.json index e743def..7380f8d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,6 +10,7 @@ "coverage", "dist", "example", + "fixtures", "node_modules" ] } diff --git a/wallaby.js b/wallaby.js index 8dfe7e0..b58b60b 100644 --- a/wallaby.js +++ b/wallaby.js @@ -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' };