Giter VIP home page Giter VIP logo

react-native-less-transformer's Issues

Error with Jest

Hi!

I have an error when I try to run my Jest tests.
I've followed the instructions and everything works fine for development.

But when I run my tests, I have this error:

tests/views/Login.test.js
  ● Test suite failed to run

    /app/styles/less/common.less:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){@backgroundColor: #fff;
                                                                                             ^

    SyntaxError: Invalid or unexpected token

      1 | import {StyleSheet} from "react-native";
    > 2 | import extraStyles from "./less/common.less";
        | ^
      3 | 
      4 | export const styles = StyleSheet.create({});
      5 | 

      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
      at Object.<anonymous> (app/styles/common.js:2:1)
      at Object.<anonymous> (app/views/Login.js:5:1)

I tried to configure Jest in my package.json:

"jest": {
    "preset": "react-native",
    "moduleFileExtensions": [
      "less",
      "js"
    ],
    "transform": {
      "^.+\\.(js)$": "<rootDir>/node_modules/babel-jest",
      "\\.(less)$": "<rootDir>/node_modules/react-native-less-transformer"
    },
    "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(less|js)$",
    "testPathIgnorePatterns": [
      "\\.snap$",
      "<rootDir>/node_modules/"
    ],
    "cacheDirectory": ".jest/cache"
  },

But it raised another error:

TypeError: Jest: a transform must export a `process` function.

      1 | import {StyleSheet} from "react-native";
    > 2 | import extraStyles from "./less/common.less";
        |               ^
      3 | 
      4 | export const styles = StyleSheet.create({});
      5 | 

      at ScriptTransformer._getTransformer (node_modules/jest-runtime/build/script_transformer.js:236:15)
      at Object.<anonymous> (app/styles/common.js:2:15)

My dependencies are:

"dependencies": {
    "axios": "^0.18.0",
    "prop-types": "^15.6.2",
    "react": "16.3.1",
    "react-native": "~0.55.2",
    "react-native-config": "^0.11.5",
    "react-navigation": "^2.10.0",
    "react-redux": "^5.0.7",
    "redux": "^4.0.0"
  },
"devDependencies": {
    "babel-eslint": "^8.2.6",
    "babel-preset-react-native-stage-0": "^1.0.1",
    "eslint": "^5.2.0",
    "eslint-plugin-jest": "^21.18.0",
    "eslint-plugin-react": "^7.10.0",
    "faker": "^4.1.0",
    "jest": "^23.4.2",
    "jest-react-native": "^18.0.0",
    "jscpd": "^0.6.22",
    "less": "^3.8.1",
    "react-native-cli": "^2.0.1",
    "react-native-less-transformer": "^1.1.2",
    "react-test-renderer": "16.3.1"
  },
  • Is there a way of using this library with Jest?

do i need a StyleSheet.create wrapper?

Hi, do I need a wrapper around the StyleSheet.create?
Or does react-native-svg-transformer do it itself?

image

This code doesn't really work ((
but I would like to know whether it is necessary or not.
If necessary, how can you add it?

Not working on RN 0.59

After updating the project to 0.59, I get the error:
error: bundling failed: TypeError: Cannot destructure property src of 'undefined' or 'null'. at renderToCSS (node_modules/react-native-less-transformer/index.js:32:21)

On version 0.58 everything is ok

UPD:
You can fix it by change this line
return renderToCSS().then(css => {
to
return renderToCSS({ src, filename, options }).then(css => {

if i want to add a plugins `less-plugin-functions` to handler function in transfromer.js,how do i do ?

I try to do it like this ,but it don't work
less-plugin-functions

var lessTransformer = require("react-native-less-transformer");

module.exports.transform = function({ src, filename, options }) {
  if (filename.endsWith(".less")) {
    var opts = Object.assign(options, {
      lessOptions: {
        plugins: [require("less-plugin-functions")]
      }
    });
    return lessTransformer.transform({ src, filename, options: opts });
  } else {
    return upstreamTransformer.transform({ src, filename, options });
  }
};

semver issue

using in expo and facing error while starting server
Failed to construct transformer: TypeError: semver is not a function

console.log says that semver is object. so looks like we need change line
var reactNativeMinorVersion = semver(reactNativeVersionString).minor;
to
var reactNativeMinorVersion = semver.minor(reactNativeVersionString);

i have "react-native-less-transformer": "^1.4.0",
inside have dependency semver v7.5.1.

react-native-web support

Hi, is it possible to make this plugin work for react-native-web? Since necolas/react-native-web#1146 prevents classname from working I wanted to use babel-plugin-react-native-classname-to-style to convert className to style so I can still use css modules for React Native and React JS. But I also need react-native-less-transformer to work in React JS for that to work. Hope you can help me.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.