
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
babel-plugin-arrow-test
Advanced tools
Babel 6 plugin, allows you to test anonymous javascript arrow functions easily.
I love to write declarative javascript code like
blabla
.map(({ x, y }) => ({z: x + y}))
.reduce((memo, { z }) => ... )
.filter(({ ... }) => ... )
.groupBy( ... )
Writing full test of this flow can be not an easy task for real flows with many map
, reduce
and other functions we like. But almost every function inside flow is easily testable.
But even if any of arrow function in this flow is easily testable, to test each I need to write something like this.
// now I can import mappingFunction and test
export const mapFn = ({ x, y }) => ({z: x + y});
export const reduceFn = (memo, { z }) => ... ;
...
blabla
.map(mappingFunction)
.reduce(reduceFunction)
...
This can easily be tested, but source is unreadable. Function definition is far outside from place I use it.
So this plugin allows you to solve this problem.
Just add comment to each anonymous function you want to test
// file.js
blabla
.map( /* @t(mapFn) */ ({ x, y }) => ({z: x + y}))
.reduce(
// @t(reduceFn)
(memo, { z }) => ...
)
...
Add next lines to .babelrc
"env": {
"ARROW": {
"plugins": [
["arrow-test", {"regexp": "@t\\(([^\\)]+)\\)"}]
]
}
}
Write test
// test anonymous mapFn reduceFn
describe('must import anonymouse functions', () => {
it('must import anonymouse functions', () => {
const { mapFn, reduceFn } = require('./file.js');
expect(mapFn({ x: 1, y: 2 })).toEqual({ z: 3});
});
}
And run with
NODE_ENV=ARROW mocha
All anonymous functions with comment you describe as plugin regexp
parameter will be
exported with regexp
capture so you can test them
Simple map reduce module and test
Functional react component with recompose and test
npm install --save-dev babel-plugin-arrow-test
Add to .babelrc
"env": {
"ARROW": {
"plugins": [
["arrow-test", {"regexp": "@t\\(([^\\)]+)\\)"}]
]
}
}
FAQs
.
The npm package babel-plugin-arrow-test receives a total of 0 weekly downloads. As such, babel-plugin-arrow-test popularity was classified as not popular.
We found that babel-plugin-arrow-test 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
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.