'use strict'
/* globals describe it beforeEach */

const expect = require('unexpected')
const cli = require('..')
const hookStd = require('hook-std')

describe('action', function () {
  beforeEach(() => cli.mockConsole())

  it('shows message', function () {
    let out = ''
    const unhook = hookStd.stderr({silent: true}, output => { out += output })

    return cli.action('working', Promise.resolve())
    .then(() => {
      unhook()
      expect(cli.color.stripColor(out), 'to equal', 'working... done\n')
    })
  })

  it('warns', function () {
    let out = ''
    const unhook = hookStd.stderr({silent: true}, output => { out += output })

    let p = cli.action('working', new Promise((resolve) => process.nextTick(() => resolve())))
      .then(() => {
        unhook()
        expect(cli.color.stripColor(out), 'to equal', 'working... !\n ▸    warning!\nworking... done\n')
      })
    cli.action.warn('warning!')
    return p
  })

  it('errors', function () {
    let out = ''
    const unhook = hookStd.stderr({silent: true}, output => { out += output })

    return expect(cli.action('working', Promise.reject(new Error('oh noes'))),
      'to be rejected with', {message: 'oh noes'})
      .then(() => {
        unhook()
        expect(cli.color.stripColor(out), 'to equal', 'working... !!!\n')
      })
  })
})

@@ -110,44 +110,8 @@
 ..')
-%0Aconst hookStd = require('hook-std')
 %0A%0Ade
@@ -220,105 +220,8 @@
 ) %7B%0A
-    let out = ''%0A    const unhook = hookStd.stderr(%7Bsilent: true%7D, output =%3E %7B out += output %7D)%0A%0A
     
@@ -288,63 +288,25 @@
  =%3E 
-%7B%0A      unhook()%0A      expect(cli.color.stripColor(out)
+expect(cli.stderr
 , 't
@@ -339,14 +339,8 @@
 %5Cn')
-%0A    %7D
 )%0A  
@@ -375,105 +375,8 @@
 ) %7B%0A
-    let out = ''%0A    const unhook = hookStd.stderr(%7Bsilent: true%7D, output =%3E %7B out += output %7D)%0A%0A
     
@@ -488,67 +488,25 @@
  =%3E 
-%7B%0A        unhook()%0A        expect(cli.color.stripColor(out)
+expect(cli.stderr
 , 't
@@ -561,32 +561,24 @@
 ... done%5Cn')
-%0A      %7D
 )%0A    cli.ac
@@ -651,105 +651,8 @@
 ) %7B%0A
-    let out = ''%0A    const unhook = hookStd.stderr(%7Bsilent: true%7D, output =%3E %7B out += output %7D)%0A%0A
     
@@ -799,67 +799,25 @@
  =%3E 
-%7B%0A        unhook()%0A        expect(cli.color.stripColor(out)
+expect(cli.stderr
 , 't
@@ -849,16 +849,8 @@
 %5Cn')
-%0A      %7D
 )%0A  

build fix