Socket
Socket
Sign inDemoInstall

riot-jest-transformer

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

riot-jest-transformer - npm Package Compare versions

Comparing version 1.0.10 to 2.0.0

demo/foo.js

8

demo/jest.config.js

@@ -1,8 +0,8 @@

{
module.exports = {
"verbose": true,
"automock": false,
"transform": {
"^.+\\.jsx?$": "babel-jest",
"^.+\\.tag$": "../src/main.js"
"^.+\\.jsx?$": "babel-jest",
"^.+\\.tag$": "../src/main.js"
}
}
};
{
"name": "demo",
"version": "1.0.0",
"version": "2.0.0",
"description": "demo for riot-jest-transformer",

@@ -14,6 +14,9 @@ "scripts": {

"dependencies": {
"babel-jest": "^19.0.0",
"jest": "^19.0.2",
"babel-jest": "^24.1.0",
"jest": "^24.1.0",
"riot-jest-transformer": "^1.0.2"
},
"devDependencies": {
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2"
}
}

@@ -1,2 +0,2 @@

{
module.exports = {
"verbose": true,

@@ -8,2 +8,2 @@ "automock": false,

"testPathIgnorePatterns": ["/node_modules/", "/demo/"]
}
};
{
"name": "riot-jest-transformer",
"version": "1.0.10",
"version": "2.0.0",
"description": "Jest transformer for testing riot tags",

@@ -31,11 +31,11 @@ "main": "src/main.js",

"devDependencies": {
"babel-jest": "^19.0.0",
"babel-preset-es2015-riot": "^1.1.0",
"babel-jest": "^24.1.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
"coveralls": "^2.11.16",
"jest": "^19.0.0"
"jest": "^24.1.0"
},
"dependencies": {
"babel-core": "^6.23.1",
"@babel/core": "^7.2.2",
"riot": "^3.3.1"
}
}

@@ -14,3 +14,3 @@ ![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)

- Installed riot-jest-transformer npm package into your project: `npm i --save-dev riot-jest-transformer`
- If you use Babel, set up `.babelrc` file correctly (for more see [Jest docs](https://facebook.github.io/jest/docs/getting-started.html#additional-configuration)). Don't forget setting `presets` for new javascript features. In your Riot project you may want to set [`es2015-riot` preset](https://github.com/riot/babel-preset-es2015-riot).
- If you use Babel, set up `.babelrc` file correctly (for more see [Jest docs](https://facebook.github.io/jest/docs/getting-started.html#additional-configuration)). 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`.

@@ -44,9 +44,9 @@ #### Setting up Jest config file

const elem = document.createElement('hello');
elem.setAttribute('name', 'world');
document.body.appendChild(elem)
riot.mount(elem, 'hello');
});
it('should mount the tag', () => {

@@ -64,3 +64,3 @@ expect(document.querySelector('hello h1').textContent).toBe('world');

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:
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:

@@ -78,3 +78,3 @@ ```js

- If you'd like to use babel-core for transformation, and options provided in .babelrc is enough for you, you do not need to create riot-jest-transformer.json file, the transformer just works out of the box
- if you provide a configuration in `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.
- if you provide a configuration in `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.
- If you want to use other transformer module than babel-core, you have to give the proper path in `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 directory

@@ -93,4 +93,4 @@

Run tests with `npm test` or `npm run test:watch`.
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.
import { process, transformer } from '../main';
import * as riot from 'riot';
import { transform } from 'babel-core';
import { transform } from '@babel/core';
import path from 'path';

@@ -41,3 +41,3 @@ import fs from 'fs';

const config = transformer.getDefaultConfig({ filename: 'fakeFile'});
expect(config.transformer).toEqual('babel-core');
expect(config.transformer).toEqual('@babel/core');
expect(config.method).toEqual('transform');

@@ -49,3 +49,3 @@ expect(config.args).toEqual([{ filename: 'fakeFile' }]);

describe('getConfig', () => {
it('should use babel-core as default transformer if no config file', () => {
it('should use @babel/core as default transformer if no config file', () => {
const callGetConfig = function () {

@@ -65,3 +65,3 @@ transformer.getConfig()

let config = {
transformer: "babel-core",
transformer: "@babel/core",
method: 'transform',

@@ -79,3 +79,3 @@ args: [{}, 'fakeArg']

let config = `{
transformer: "babel-core",
transformer: "@babel/core",
method: 'transform',

@@ -100,5 +100,5 @@ args: [{}]

let config;
it('should check type of config object', () => {
config = [];
config = [];
expect(callValidateConfig).toThrow('riot-jest-transformer config must provide an object');

@@ -108,3 +108,3 @@ });

it('should check existence of compulsory config options', () => {
config = {};
config = {};
expect(callValidateConfig).toThrow('riot-jest-transformer config must define the name or path of the "transformer" module, the "method" of the transformer to be called, and optionally "args" ie. arguments of the method');

@@ -133,3 +133,3 @@ });

// {
// transformer: "babel-core",
// transformer: "@babel/core",
// method: 'transform',

@@ -139,5 +139,5 @@ // args: ["trallala"]

it('should throw informative error message if transformer is babel-core and args[0] in conf is not an object', () => {
it('should throw informative error message if transformer is @babel/core and args[0] in conf is not an object', () => {
let config = {
transformer: "babel-core",
transformer: "@babel/core",
method: 'transform',

@@ -151,6 +151,6 @@ args: ["trallala"]

expect(callValidateConfig).toThrow('If you want to use babel-core for transformation, you have to provide an object as first element of your args array');
expect(callValidateConfig).toThrow('If you want to use @babel/core for transformation, you have to provide an object as first element of your args array');
});
it('should not throw error if transformer is not babel-core and args[0] is not an object', () => {
it('should not throw error if transformer is not @babel/core and args[0] is not an object', () => {
let config = {

@@ -172,3 +172,3 @@ transformer: "abel-babel",

it('uses babel-core transform if config does not exist', () => {
it('uses @babel/core transform if config does not exist', () => {
if (fs.existsSync(configPath)) {

@@ -289,2 +289,1 @@ fs.unlinkSync(configPath);

});
const riot = require('riot');
const { transform } = require('babel-core');
const { transform } = require('@babel/core');
const path = require('path');

@@ -17,3 +17,3 @@ const fs = require('fs');

if (header.search(/from\s*['|"]riot['|"]/) == -1 &&
header.search(/require\s*\(['|"]riot['|"]\)/)
header.search(/require\s*\(['|"]riot['|"]\)/) == -1
) {

@@ -27,3 +27,3 @@ completed = 'const riot = require("riot");\n' + compiled;

return {
transformer: 'babel-core',
transformer: '@babel/core',
method: 'transform',

@@ -41,3 +41,3 @@ args: [{

config = JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf8'));
}
}
catch (e) {

@@ -74,4 +74,4 @@ throw Error("The content of the config file must be in JSON format");

if (config.transformer === 'babel-core' && {}.toString.call(config.args[0]) !== '[object Object]') {
throw Error("If you want to use babel-core for transformation, you have to provide an object as first element of your args array");
if (config.transformer === '@babel/core' && {}.toString.call(config.args[0]) !== '[object Object]') {
throw Error("If you want to use @babel/core for transformation, you have to provide an object as first element of your args array");
}

@@ -78,0 +78,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc