Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
riot-jest-transformer
Advanced tools
This transformer helps you to use Jest testing tool for your Riot tags. With this transformer you can import your tags into your Jest tests.
npm i --save-dev jest babel-jest
)npm i --save-dev riot-jest-transformer
.babelrc
file correctly (for more see Jest docs). Don't forget setting presets
for new javascript features. babel-jest
does not seem to be able to pick up babel.config.js
files, so please prefer .babelrc
.riot-jest-transformer must be used in your Jest config file like this:
{
"transform": {
"^.+\\.jsx?$": "babel-jest",
"^.+\\.tag$": "riot-jest-transformer"
}
}
Let's suppose that you saved the Jest config file to the project root directory as jest.config
. In this case you should run jest with --config option: jest --config jest.config
Just import your tag into the Jest test file. After that you can mount your tag to an html element. For example:
import * as riot from 'riot';
import hello from '../hello.tag'; // <hello><h1>{ opts.name }</h1></hello>
describe('hello', () => {
beforeAll( () => {
// create mounting point
const elem = document.createElement('hello');
elem.setAttribute('name', 'world');
document.body.appendChild(elem)
riot.mount(elem, 'hello');
});
it('should mount the tag', () => {
expect(document.querySelector('hello h1').textContent).toBe('world');
});
});
The transformation has two steps:
The transformer uses @babel/core module by default as transformer for the compiled tag (and uses the .babelrc for babel configuration). You can also use other transformer by configuring it in the riot-jest-transformer.json
config file in the root of your project directory. In the latter case the form of the config file must be like this:
{
"transformer": <transformer module name or path, it will be required by Jest> : String, required
"method": <the used method of transformer module> : String, required
"args": <arguments for method> : Array, optional
}
riot-jest-transformer.json
and want to use babel-core
as transformer (maybe with special options for riot tags), the first argument must be an object in args
, because transformer method of babel-core
needs an options object for transformation.transformer
attribute. If the transformer module is from an npm package, it is enough to give the name of the module, otherwise you have to provide the path of the module from project root directoryYou can play with importing and testing tags in the demo folder:
npm i
npm test
to run a simple jest test for an example Riot tag.Run tests with npm test
or npm run test:watch
.
The transformer is developed with tdd, so if you would like to contribute (you are really welcomed :), please write your tests for your new functionality, and send pull request to integrate your changes.
FAQs
Jest transformer for testing riot tags
The npm package riot-jest-transformer receives a total of 238 weekly downloads. As such, riot-jest-transformer popularity was classified as not popular.
We found that riot-jest-transformer 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
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.