From 2c5b377cd14876ed3ffe0fa3da40327c0a3f0de3 Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdxcode@users.noreply.github.com> Date: Fri, 26 Jan 2018 14:49:38 -0800 Subject: [PATCH] fix: updated fancy-test --- package.json | 7 ++++--- src/logger.ts | 2 +- test/errors.test.ts | 15 +++++--------- test/logger.test.ts | 33 ++++++++++-------------------- test/styled/object.test.ts | 4 ++-- test/styled/table.test.ts | 4 ++-- yarn.lock | 41 +++++++++++++++++++++++++++++--------- 7 files changed, 56 insertions(+), 50 deletions(-) diff --git a/package.json b/package.json index a796b85f..eb04d301 100644 --- a/package.json +++ b/package.json @@ -20,21 +20,22 @@ "devDependencies": { "@dxcli/dev-nyc-config": "^0.0.3", "@dxcli/dev-semantic-release": "^0.1.0", - "@dxcli/dev-tslint": "^0.0.16", + "@dxcli/dev-tslint": "^0.0.17", "@types/ansi-styles": "^2.0.30", "@types/chai": "^4.1.2", "@types/fs-extra": "^5.0.0", - "@types/lodash": "^4.14.96", + "@types/lodash": "^4.14.97", "@types/mocha": "^2.2.47", "@types/nock": "^9.1.2", "@types/node": "^9.4.0", + "@types/node-notifier": "^0.0.28", "@types/semver": "^5.4.0", "@types/strip-ansi": "^3.0.0", "@types/supports-color": "^3.1.0", "chai": "^4.1.2", "eslint": "^4.16.0", "eslint-config-dxcli": "^1.1.4", - "fancy-mocha": "^0.3.3", + "fancy-test": "^0.5.0", "husky": "^0.14.3", "mocha": "^5.0.0", "mocha-junit-reporter": "^1.17.0", diff --git a/src/logger.ts b/src/logger.ts index 6a1a44ab..392445b2 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -66,8 +66,8 @@ export default (e: IEventEmitter) => { async function close() { e.removeListener('output', handleOutput) - await flush() if (!stream) return + await flush() const s = await stream return new Promise((resolve, reject) => { s.end() diff --git a/test/errors.test.ts b/test/errors.test.ts index 6a903ae2..617bb0ce 100644 --- a/test/errors.test.ts +++ b/test/errors.test.ts @@ -1,22 +1,17 @@ -import chalk from 'chalk' -import {expect, fancy} from 'fancy-mocha' - import cli from '../src' -beforeEach(() => { - chalk.enabled = false -}) +import {expect, fancy} from './fancy' describe('errors', () => { - fancy() + fancy .stderr() - .end('warns', output => { + .end('warns', async output => { cli.warn('foobar') expect(output.stderr).to.equal(' ▸ foobar\n') }) - fancy() - .end('errors', () => { + fancy + .end('errors', async () => { expect(() => cli.error('foobar')).to.throw(/foobar/) }) }) diff --git a/test/logger.test.ts b/test/logger.test.ts index 4cc9b446..8d30195c 100644 --- a/test/logger.test.ts +++ b/test/logger.test.ts @@ -1,32 +1,19 @@ -import {expect, fancy} from 'fancy-mocha' - import * as fs from 'fs-extra' -import * as path from 'path' import cli from '../src' -const log = path.join(__dirname, '../tmp/error.log') -const logLevel = cli.config.logLevel - -beforeEach(() => { - cli.config.logLevel = logLevel - fs.removeSync(log) - cli.config.errlog = log -}) -afterEach(() => cli.config.errlog = undefined) +import {expect, fancy} from './fancy' describe('logger', () => { - fancy() + fancy .stdout() - .stderr() .end('does nothing if no error.log', async () => { cli.config.errlog = undefined cli.info('foobar') await cli.done() - expect(fs.pathExistsSync(log)).to.equal(false) }) - fancy() + fancy .stdout() .stderr() .end('writes stuff out', async () => { @@ -34,10 +21,10 @@ describe('logger', () => { cli.info('hideme') cli.error('showerror', {exit: false}) await cli.done() - expect(fs.readFileSync(log, 'utf8')).to.contain(' ERROR showerror') + expect(fs.readFileSync(cli.config.errlog!, 'utf8')).to.contain(' ERROR showerror') }) - fancy() + fancy .stdout() .stderr() .end('can change log level', async () => { @@ -47,10 +34,10 @@ describe('logger', () => { cli.debug('hideme') cli.error('showerror', {exit: false}) await cli.done() - expect(fs.readFileSync(log, 'utf8')).to.contain(' ERROR showerror') + expect(fs.readFileSync(cli.config.errlog!, 'utf8')).to.contain(' ERROR showerror') }) - fancy() + fancy .stdout() .stderr() .end('uses scope', async () => { @@ -59,10 +46,10 @@ describe('logger', () => { _cli.info('hideme') _cli.error('showerror', {exit: false}) await cli.done() - expect(fs.readFileSync(log, 'utf8')).to.contain(' WARN mynewscope showwarning') + expect(fs.readFileSync(cli.config.errlog!, 'utf8')).to.contain(' WARN mynewscope showwarning') }) - fancy() + fancy .stdout() .stderr() .end('does not create file if no output', async () => { @@ -70,6 +57,6 @@ describe('logger', () => { cli.debug('mycontent') cli.info('mycontent') await cli.done() - expect(fs.pathExistsSync(log)).to.equal(false) + expect(fs.pathExistsSync(cli.config.errlog!)).to.equal(false) }) }) diff --git a/test/styled/object.test.ts b/test/styled/object.test.ts index e6b61de1..f09b8560 100644 --- a/test/styled/object.test.ts +++ b/test/styled/object.test.ts @@ -1,9 +1,9 @@ -import {expect, fancy} from 'fancy-mocha' +import {expect, fancy} from 'fancy-test' import cli from '../../src' describe('styled/table', () => { - fancy() + fancy .stdout() .end('shows a table', output => { cli.styledObject([ diff --git a/test/styled/table.test.ts b/test/styled/table.test.ts index 120b5b77..6bc7471e 100644 --- a/test/styled/table.test.ts +++ b/test/styled/table.test.ts @@ -1,9 +1,9 @@ -import {expect, fancy} from 'fancy-mocha' +import {expect, fancy} from 'fancy-test' import cli from '../../src' describe('styled/table', () => { - fancy() + fancy .stdout() .end('shows a table', output => { cli.table([ diff --git a/yarn.lock b/yarn.lock index 2f108ecb..455ee8be 100644 --- a/yarn.lock +++ b/yarn.lock @@ -126,9 +126,9 @@ "@semantic-release/npm" "^2.6.4" semantic-release "^12.2.2" -"@dxcli/dev-tslint@^0.0.16": - version "0.0.16" - resolved "https://registry.yarnpkg.com/@dxcli/dev-tslint/-/dev-tslint-0.0.16.tgz#84aa077d5f0c92f770b2b7eb091588c8553b4c9f" +"@dxcli/dev-tslint@^0.0.17": + version "0.0.17" + resolved "https://registry.yarnpkg.com/@dxcli/dev-tslint/-/dev-tslint-0.0.17.tgz#f20767b72188a0695e4b34ba50976e11502d3891" dependencies: tslint "^5.9.1" tslint-xo "^0.5.0" @@ -259,9 +259,9 @@ dependencies: "@types/node" "*" -"@types/lodash@^4.14.96": - version "4.14.96" - resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.96.tgz#49a402bb6984af7dd9a48cea3781744a3774bff1" +"@types/lodash@^4.14.97": + version "4.14.97" + resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.97.tgz#7262d6d5fc5e87cdb3f68eb33accd4024f2b211e" "@types/mocha@^2.2.47": version "2.2.47" @@ -273,6 +273,12 @@ dependencies: "@types/node" "*" +"@types/node-notifier@^0.0.28": + version "0.0.28" + resolved "https://registry.yarnpkg.com/@types/node-notifier/-/node-notifier-0.0.28.tgz#86ba3d3aa8d918352cc3191d88de328b20dc93c1" + dependencies: + "@types/node" "*" + "@types/node@*": version "9.3.0" resolved "https://registry.yarnpkg.com/@types/node/-/node-9.3.0.tgz#3a129cda7c4e5df2409702626892cb4b96546dd5" @@ -1622,9 +1628,9 @@ extsprintf@^1.2.0: version "1.4.0" resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.4.0.tgz#e2689f8f356fad62cca65a3a91c5df5f9551692f" -fancy-mocha@^0.3.3: - version "0.3.3" - resolved "https://registry.yarnpkg.com/fancy-mocha/-/fancy-mocha-0.3.3.tgz#414359b859e84cb8d25a9183d02fc52c03d43403" +fancy-test@^0.5.0: + version "0.5.0" + resolved "https://registry.yarnpkg.com/fancy-test/-/fancy-test-0.5.0.tgz#ebefe0ad756eb2fbd1eaafe0383c710bada2cb6d" dependencies: lodash "^4.17.4" stdout-stderr "^0.1.4" @@ -2005,6 +2011,10 @@ growl@1.10.3: version "1.10.3" resolved "https://registry.yarnpkg.com/growl/-/growl-1.10.3.tgz#1926ba90cf3edfe2adb4927f5880bc22c66c790f" +growly@^1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/growly/-/growly-1.3.0.tgz#f10748cbe76af964b7c96c93c6bcc28af120c081" + handlebars@^4.0.2, handlebars@^4.0.3: version "4.0.11" resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.0.11.tgz#630a35dfe0294bc281edae6ffc5d329fc7982dcc" @@ -3032,6 +3042,15 @@ node-emoji@^1.4.1: dependencies: lodash.toarray "^4.4.0" +node-notifier@^5.2.1: + version "5.2.1" + resolved "https://registry.yarnpkg.com/node-notifier/-/node-notifier-5.2.1.tgz#fa313dd08f5517db0e2502e5758d664ac69f9dea" + dependencies: + growly "^1.3.0" + semver "^5.4.1" + shellwords "^0.1.1" + which "^1.3.0" + normalize-package-data@^2.3.2, normalize-package-data@^2.3.4, "normalize-package-data@~1.0.1 || ^2.0.0": version "2.4.0" resolved "https://registry.yarnpkg.com/normalize-package-data/-/normalize-package-data-2.4.0.tgz#12f95a307d58352075a04907b84ac8be98ac012f" @@ -3908,6 +3927,10 @@ shelljs@0.7.6: interpret "^1.0.0" rechoir "^0.6.2" +shellwords@^0.1.1: + version "0.1.1" + resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b" + signal-exit@^3.0.0, signal-exit@^3.0.1, signal-exit@^3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"