Coder Social home page Coder Social logo

kapok-js's People

Contributors

cap32 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

mojavelinux

kapok-js's Issues

Assert should be able to distinguish between stdout and stderr

When declaring an assertion, it should be possible to distinguish between stdout and stderr as the source of the message. These can indicate very different results.

Here's a key example:

Kapok
  .start('ls', ['*lock*'])
  .assert(/lock/)
  .done()

The error message includes the word "lock", but we are actually looking for "lock" in the list of files.

Allow arguments to command to be passed as a String

Allow the arguments to the command to be passed as a String. The value should be split on whitespace characters to coerce it to an array.

Example:

Kapok.start('ls', '-1 -S')
  .assert(/./)
  .done()

This is merely a convenience, but could also make Kapok more newbie friendly.

Assertion errors do not play well with mocha/chai

The assertion errors do not play well when using Kapok with mocha/chai. The main issue is with the ansi escape codes, which get shown raw in the assertion message. The other problem has to do with timing.

Here's a simple example:

const expect = require('chai').expect
const { default: Kapok } = require('kapok-js')

Kapok.config.shouldShowLog = false
Kapok.config.shouldThrowError = true

describe('mocha/chai integration', () => {
  it('should show reasonable assertion error', () => {
    return Kapok.start('ls', ['-1'])
      .assert('n/a')
      .done()
  })
})

Here's what you see on the expected failure:

  1) mocha/chai integration
       should show reasonable assertion error:
     Error: the array [
  "Error: \u001b[31mโœ– \u001b[39mExpected value to be \"\u001b[32mn/a\u001b[39m\", but received \"\u001b[31mint.js\u001b[39m\"."
] was thrown, throw an Error :)
      at <anonymous>

I'm not sure if we need a dedicated mocha integration piece, or whether Kapok can be changed to raise a more portable assertion error (perhaps using the assertion-error module).

How do I assert on a command with no output?

The command I'm testing doesn't output anything when it competes successfully. When I run the command with Kapok under this circumstance, Kapok hangs indefinitely waiting for output.

it('should run successfully', () => {
  return Kapok
    .start(CLI, ['generate'])
    .done()
})

What method to I use to assert no output?

I'm currently using a Promise as a workaround, but I'm not sure this is correct:

it('should run successfully', () => {
  return new Promise((resolve) => {
    Kapok
      .start(CLI, ['generate'])
      .on('exit', () => resolve())
  }).then(() => {
    // assert files were created
  })
})

Report when command is not found

If spawn fails to find the command, it throws an uncaught, low-level ENOENT error. This can cause a new user of this library to get stuck. In my case, I was including the arguments in the command slot, so spawn was looking for a command with spaces in it. I think Kapok should detect a missing command and report it gracefully, perhaps even offering a "did you mean?" message if spaces are detected in the command name?

Allow config options to be set per instance

Currently, the shouldShowLog and shouldThrowError options can either be set globally or per method (e.g., assert). It seems like the scope that's missing is per Kapok instance. This is really where I would think it would make the most sense to set these options.

I'm imagining something like:

new Kapok('ls', [], { shouldShowLog: true })
  .assert(/./)
  .done()

This would be especially useful for debugging purposes.

These options should be removed from the options that are passed to spawn.

How do I assert the exit code?

Is there a way to assert on the exit code? I want to assert that a command exited with either 0 or 1 depending on whether it succeeded or failed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.