cap32 / kapok-js Goto Github PK
View Code? Open in Web Editor NEWJavascript Testing utilities for CLI
License: MIT License
Javascript Testing utilities for CLI
License: MIT License
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 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.
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).
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
})
})
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?
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.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.