Giter VIP home page Giter VIP logo

ignore-styles's Introduction

ignore-styles

Version Build Status License Downloads

A babel/register style hook to ignore style imports when running in Node. This is for projects that use something like Webpack to enable CSS imports in JavaScript. When you try to run the project in Node (to test in Mocha, for example) you'll see errors like this:

SyntaxError: /Users/brandon/code/my-project/src/components/my-component/style.sass: Unexpected token (1:0)
> 1 | .title
| ^
2 |   font-family: serif
3 |   font-size: 10em
4 |

To resolve this, require ignore-styles with your mocha tests:

mocha --require ignore-styles

See DEFAULT_EXTENSIONS for the full list of extensions ignored, and send a pull request if you need more.

More Examples

To use this with multiple Mocha requires:

mocha --require babel-register --require ignore-styles

You can also use it just like babel/register:

  import 'ignore-styles'

In ES5:

require('ignore-styles')

To customize the extensions used:

import register from 'ignore-styles'
register(['.sass', '.scss'])

To customize the extensions in ES5:

require('ignore-styles')(['.sass', '.scss'])

Custom handler

By default, a no-op handler is used that doesn't actually do anything. If you'd like to substitute your own custom handler to do fancy things, pass it as a second argument:

import register from 'ignore-styles'
register(undefined, () => {styleName: 'fake_class_name'})

Why is this useful? One example is when using something like react-css-modules. You need the style imports to actually return something so that you can test the components, or the wrapper component will throw an error. Use this to provide test class names.

License

The MIT License (MIT)

Copyright (c) 2015 Brainspace Corporation

ignore-styles's People

Contributors

bkonkle avatar

Watchers

James Cloos avatar  avatar

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.