
Security News
PEP 810 Proposes Explicit Lazy Imports for Python 3.15
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
Doctests are executable usage examples sometimes found in "docstrings". JavaScript doesn't have docstrings, but inline documentation can be included in code comments. doctest finds and evaluates usage examples in code comments and reports any inaccuracies. doctest works with JavaScript and CoffeeScript modules.
// toFahrenheit :: Number -> Number
//
// Convert degrees Celsius to degrees Fahrenheit.
//
// > toFahrenheit(0)
// 32
// > toFahrenheit(100)
// 212
function toFahrenheit(degreesCelsius) {
return degreesCelsius * 9 / 5 + 32;
}
Doctest will execute toFahrenheit(0)
and verify that its output is 32
.
$ npm install doctest
Test a module via JavaScript API:
> doctest ({}) ('lib/temperature.js')
Test a module via command-line interface:
$ doctest lib/temperature.js
The exit code is 0 if all tests pass, 1 otherwise.
Module system | Option | Node.js | Dependencies |
---|---|---|---|
CommonJS | commonjs | ✔︎ | ✔︎ |
ECMAScript modules | esm | ✔︎ | ✔︎ |
Specify module system via JavaScript API:
> doctest ({module: 'esm'}) ('path/to/esm/module.js')
Specify module system via command-line interface:
$ doctest --module commonjs path/to/commonjs/module.js
Input lines may be wrapped by beginning each continuation with FULL STOP (.
):
// > reverse([
// . 'foo',
// . 'bar',
// . 'baz',
// . ])
// ['baz', 'bar', 'foo']
Output lines may be wrapped in the same way:
// > reverse([
// . 'foo',
// . 'bar',
// . 'baz',
// . ])
// [ 'baz',
// . 'bar',
// . 'foo' ]
An output line beginning with EXCLAMATION MARK (!
) indicates that the
preceding expression is expected to throw. The exclamation mark must be
followed by SPACE (
) and the name of an Error constructor.
For example:
// > null.length
// ! TypeError
The constructor name may be followed by COLON (:
), SPACE (
),
and the expected error message. For example:
// > null.length
// ! TypeError: Cannot read property 'length' of null
Each doctest has access to variables in its scope chain.
$ npm install
$ npm test
FAQs
Doctests for JavaScript and CoffeeScript
The npm package doctest receives a total of 2,064 weekly downloads. As such, doctest popularity was classified as popular.
We found that doctest demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
Security News
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.