@power-doctest/tester
v5.3.3
Published
A Test Runner for A power-doctest.
Downloads
205
Readme
@power-doctest/tester
A Test Runner for A power-doctest.
Install
Install with npm:
npm install @power-doctest/tester
Usage
import { run } from "@power-doctest/tester"
run(`
console.log(1); // => 1
console.log("string"); // => "string"
console.log([1, 2, 3]); // => [1, 2, 3]
console.log({ key: "value" }); // => { key: "value" }
console.log(NaN); // => NaN
console.log(null); // => null
// Special Case
throw new Error("message"); // => Error: "message"
// Promise
Promise.resolve(1); // => Resolve: 1
Promise.reject(new Error("message")); // => Reject: "message"
`).then(() => {
console.log("Pass");
}).catch(error => {
console.log("failed");
})
Options
export interface PowerDoctestRunnerOptions {
// pseudo file path for code
filePath?: string;
// sandbox context for code
// context defined global variables
context?: {
[index: string]: any
}
// sandbox require mock for code
requireMock?: {
[index: string]: any
}
// If it is true, console.log output to console
// If you want to mock console, please pass `console` to `context: { console: consoleMock }`
//
// Exception:
// Always suppress console and assertion, because it is converted to assert function
// ```
// console.log(1); // => 1
// ```
console?: boolean;
// Timeout millisecond
// Default: 2000
timeout?: number
// Default: all
// If runMode is all, all assertions are finished and resolve it
// If runMode is any, anyone assertion is finished and resolve it
// In Both, anyone is failed and reject it
runMode?: "any" | "all";
// Internal Option
powerDoctestCallbackFunctionName?: string;
}
Changelog
See Releases page.
Running tests
Install devDependencies and Run npm test
:
npm test
Contributing
Pull requests and stars are always welcome.
For bugs and feature requests, please create an issue.
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
Author
License
MIT © azu