Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Commit

Permalink
fix: updated fancy-test
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Jan 26, 2018
1 parent d35b163 commit 2c5b377
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 50 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>((resolve, reject) => {
s.end()
Expand Down
15 changes: 5 additions & 10 deletions test/errors.test.ts
Original file line number Diff line number Diff line change
@@ -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/)
})
})
33 changes: 10 additions & 23 deletions test/logger.test.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,30 @@
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 () => {
cli.warn('showwarning')
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 () => {
Expand All @@ -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 () => {
Expand All @@ -59,17 +46,17 @@ 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 () => {
cli.trace('mycontent')
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)
})
})
4 changes: 2 additions & 2 deletions test/styled/object.test.ts
Original file line number Diff line number Diff line change
@@ -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([
Expand Down
4 changes: 2 additions & 2 deletions test/styled/table.test.ts
Original file line number Diff line number Diff line change
@@ -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([
Expand Down
41 changes: 32 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -2005,6 +2011,10 @@ [email protected]:
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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -3908,6 +3927,10 @@ [email protected]:
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"
Expand Down

0 comments on commit 2c5b377

Please sign in to comment.