Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
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.riot-jest-transformer must be used in your Jest config file like this:
{
"transform": {
"^.+\\.jsx?$": "babel-jest",
"^.+\\.tag$": "riot-jest-transformer"
}
}
If you use Riot pre-processors, you can provide config options for riot-jest-transformer to register pre-processors befor compiling your tags for your tests. In this case you should use the following scheme:
{
"transform": {
"^.+\\.jsx?$": "babel-jest",
"^.+\\.tag$": ["riot-jest-transformer", {
registrations: [{
type: "css" | "template" | "javascript",
name: string,
preprocessorModulePath: string
}]
}
}
preprocessorModulePath must be defined as a relative path (based on Jest rootDir
configuration) to a module that exports your preprocessor function.
For example if you use scss, you can define a preprocessor function like this:
// riot-scss-preprocessor.js
const sass = require('node-sass');
module.exports = function riotScssPreprocessor(code, { options }) => {
const { file } = options;
console.log('Compile the sass code in', file);
const { css } = sass.renderSync({
data: code
});
return {
code: css.toString(),
map: null
};
}
In the above case the jest config should be looked something like this:
// jest.config.js
module.exports = {
transform: {
"^.+\\.riot$": ["riot-jest-transformer", {
registrations: [{
type: 'css',
name: 'scss',
preprocessorModulePath: 'riot-scss-preprocessor'
}]
}],
"^.+\\.jsx?$": "babel-jest"
},
};
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.register('hello', hello);
riot.mount(elem, 'hello');
});
it('should mount the tag', () => {
expect(document.querySelector('hello h1').textContent).toBe('world');
});
});
You 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 241 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
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.