riot-jest-transformer
Advanced tools
Comparing version 4.0.1 to 4.1.0
{ | ||
"name": "riot-jest-transformer", | ||
"version": "4.0.1", | ||
"version": "4.1.0", | ||
"description": "Jest transformer for testing riot tags", | ||
@@ -38,4 +38,5 @@ "main": "src/main.js", | ||
"@babel/core": "^7.2.2", | ||
"lodash": "^4.17.15", | ||
"riot": "^4.3.8" | ||
} | ||
} |
@@ -29,4 +29,57 @@ ![Build Status](https://travis-ci.org/tompascall/riot-jest-transformer.svg?branch=master) [![Coverage Status](https://coveralls.io/repos/github/tompascall/riot-jest-transformer/badge.svg?branch=master)](https://coveralls.io/github/tompascall/riot-jest-transformer?branch=master) | ||
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` | ||
If you use [Riot pre-processors](https://riot.js.org/compiler/#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 module format for jest configuration (i.e. exporting your configuration object as a module from jest.config.js) using the following scheme: | ||
```js | ||
{ | ||
"transform": { | ||
"^.+\\.jsx?$": "babel-jest", | ||
"^.+\\.tag$": ["riot-jest-transformer", { | ||
registrations: [{ | ||
type: 'css' | 'template' | 'javascript', | ||
name: string, | ||
registrationCb: (code: string, { options }) => { | ||
/** | ||
* pre-process code using your | ||
* favorite preprocessor, and finally | ||
* return the pre-processed code and | ||
* sourcemap | ||
**/ | ||
}: { code: string, map: null | sourcemap } | ||
}] | ||
} | ||
} | ||
``` | ||
For example using `node-sass` for pre-processing `.scss` files, you can define the following config: | ||
```js | ||
// jest.config.js | ||
const sass = require('node-sass'); | ||
module.exports = { | ||
transform: { | ||
"^.+\\.riot$": ["riot-jest-transformer", { | ||
registrations: [{ | ||
type: 'css', | ||
name: 'scss', | ||
registrationCb: function(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 | ||
} | ||
} | ||
}] | ||
}], | ||
"^.+\\.jsx?$": "babel-jest" | ||
}, | ||
}; | ||
``` | ||
#### Usage | ||
@@ -33,0 +86,0 @@ |
@@ -0,7 +1,11 @@ | ||
const { registerPreprocessor } = require('@riotjs/compiler'); | ||
const { compile } = require('@riotjs/compiler'); | ||
const babelJest = require('babel-jest'); | ||
const { registerPreProcessors } = require('./pre-processors'); | ||
exports.process = function (source, filename, config, options) { | ||
registerPreProcessors(config); | ||
let compiled = compile(source); | ||
return babelJest.process(compiled.code, filename, config, options); | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15538
18
285
124
3
1
+ Addedlodash@^4.17.15
+ Addedlodash@4.17.21(transitive)