Coder Social home page Coder Social logo

jest-webpack-alias's People

Contributors

dependabot[bot] avatar dmnd avatar gyran avatar kendru avatar nhz-io avatar rhfung avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jest-webpack-alias's Issues

Not compatible with `jest.unmock()`

It looks like Jest does not use jest-webpack-alias when resolving jest.unmock() module paths. e.g.

// webpack.config.js
const path = require('path');

module.exports = {
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'build'),
    filename: 'bundle.js',
  },
  resolve: {
    root: path.resolve(__dirname, 'src'),
  },
  module: {
    loaders: [
      {
        test: /\.js$/,
        include: path.resolve(__dirname, 'src'),
        loader: 'babel-loader',
      },
    ],
  },
};
// src/actions/index.js
export function foo() {
  return { type: 'FOO' };
}

Notice jest.unmock('..') vs jest.unmock('actions'):

// src/actions/__tests__/index-test.js

// This succeeds:
// jest.unmock('..');

// But this fails:
jest.unmock('actions');

import { foo } from 'actions';

describe('foo', () => {
  it('creates a FOO action', () => {
    expect(foo()).toEqual({ type: 'FOO' });
  });
});

Would this be an issue with jest-webpack-alias or with jest itself?

Error when webpack.config.js exports a function

When webpack.config.js exports a function, jest-webpack-alias throws the following error:

  ● Test suite failed to run

    Missing setting "resolve.modules" (webpack v2) or "resolve.root" (webpack v1) in /Users/davidcalhoun/Sites/web/gn-web/webpack.config.js
      
      at Object.read (node_modules/jest-webpack-alias/lib/webpackInfo.js:38:11)
      at ensureWebpackInfo (node_modules/jest-webpack-alias/lib/preprocessor.js:26:33)
      at Object.process (node_modules/jest-webpack-alias/lib/preprocessor.js:165:3)
      at Object.process (test/preprocessor.js:9:45)

The reason I am attempting to export a function is to setup environment-specific configs utilizing webpack-merge. Is it possible to support exporting a function?

My issues appear to be similar to #15.

No support for ES6 in webpack config

It is common to write webpack config on ES6 (webpack makes it possible if config name simply has *.babel.js in the tail).
jest-webpack-alias doesn't support ES6 syntax within given webpack config.

Here is my configuration:

// package.json
...
jest-webpack-alias": {
  "configFile": "webpack.config.babel.js"
}
...
// webpack.config.babel.js
import webpack from 'webpack';
...

Resolver should handle aliases with absolute paths

The resolver should be able to handle aliases that reference absolute paths. For instance, given the following resolver config:

resolve: {
  root: '/srv/app',
  alias: {
    helpers: '/srv/helpers'
  }
}

and given the file, /srv/helpers/logger.js exists,

The statement, require('helpers/logger');, in a file at /srv/app/index.js should be transformed to require('../helpers/logger.js');.

Error: Unknown config option "jest-webpack-alias" with value "[object Object]".

Hey

I use a webpack alias to load my custom config for my reactjs app.

    alias: {
      config: path.join(__dirname, 'config', `${process.env.NODE_ENV || 'development'}`)
    }

When running my tests with jest-webpack-alias enabled, I get this error :

> npm run test
> jest
Error: Unknown config option "jest-webpack-alias" with value "[object Object]". This is either a typing error or another user mistake and fixing it will remove this message.
Using Jest CLI v12.1.1, jasmine2

I tried to rename my alias because I thought this might be a reserved name. But even after renaming or deleting the alias the error still gets thrown.

Hope you can help

Support including / in webpack alias

The alias config below works ok with webpack but jest-webpack-alias doesn't work properly.

resolve: {
    modules: [path.resolve(__dirname, '..'), 'node_modules'],
    alias: {
        '@app/core': '../apps/core',
        '@app/views': '../apps/components/views'
    }
}

jest-webpack-alias works after I change it to @app-core instead of @app/core, It looks a little tricky.

Could you please help to support slash symbol / in the alias.

Thanks

- SyntaxError: Unexpected token export

Not totally sure if this is a problem with this lib, but maybe someone can point me in the right direction.

I have the preprocessor/config setup like the readme and a .babelrc that works, but I still get this error when trying to run tests:
- SyntaxError: Unexpected token export

I am pretty sure it fails because of this statement in a file that I am importing:
export const VERSION = __VERSION__;

I had to get https://www.npmjs.com/package/babel-plugin-add-module-exports to get my imports/exports working properly with babel 6 and am wondering if I have to add anything to the preprocessor to get it working too?

SyntaxError: Unexpected reserved word

Hi. when I try run test with 'jest-webpack-alias', he has error

● Runtime Error
SyntaxError: Unexpected reserved word

This error in file webpackInfo.js on line 17 var webpackSettings = require(webpackFile);

I don't understand why this happening. Help please.

[question] CSS Modules + Webpack + Jest

Hi, I am not sure if this is a proper place for this question, but I have a component which imports Stylus file. I use Css Modules approach. When I try to test this component with Jest I get an error: SyntaxError: Unexpected character '@ (3:0)' or if I remove 'imports' I get: Unexpected token (6:0) etc so it looks like Jest will not support style imports at all.

So I ended with something like:

var babelJest = require('babel-jest');
var webpackAlias = require('jest-webpack-alias');

module.exports = {
    process: function(src, filename) {
        // ignore styles and images imports
        if ((/\.(gif|jpg|jpeg|tiff|png|css|styl|less|scss)$/i).test(path.basename(filename))) {
            return '';
        }
        if (filename.indexOf('node_modules') === -1) {
            src = babelJest.process(src, filename);
            src = webpackAlias.process(src, filename);
        }
        return src;
    }
};

Isn't it a little bit hacky? :/ Can we make it work in some other way?

Coffee support?

I have webpack set up to use coffeescript in my project. Should coffeescript then work for jest testing?

I created an example repo to show what happens. https://github.com/tylercollier/jest-with-webpack

$ npm test __tests__/MyCoffeeComponent.coffee 

> [email protected] test /home/tylercollier/repos/jest-with-webpack
> jest "__tests__/MyCoffeeComponent.coffee"

Using Jest CLI v0.8.2, jasmine1
 FAIL  __tests__/MyCoffeeComponent.coffee 
● Runtime Error
SyntaxError: Unexpected token (1:22)
npm ERR! Test failed.  See above for more details.

Maybe I've misunderstood what jest-webpack-alias is for? I read #5 and figured that "coffeescript is javascript", so it should work, right?

I also wrote this issue up at http://stackoverflow.com/questions/35327165/how-do-i-use-jest-with-coffeescript-and-es6-es2015-e-g-via-babel. If someone writes an answer there, I'll give them credit on that site, otherwise, I'll transfer stuff from here to there.

Add travis and coveralls

Proposal

Add .travis.yml, coveralls npm task, travis and coveralls badges to README.md

I can provide you with the necessary PR for that but you gotta take few setup steps.

What the heck is webpackProfile?

Sorry if I'm ignorant, but I can't work out how to use this.

Is webpackProfile an actual webpack thing or is it something you guys use internally? It looks like your webpack.config.js exports an object with profile names as keys. Is that something you made up?

Runtime Error when webpack.config.js exports an ES6 module

When jest-webpack-alias imports the webpack config:

var webpackSettings = require(webpackFile);

_.get(webpackSettings, 'resolve.root') fails because webpackSettings looks like this:

> webpackSettings
{ __esModule: true,
  default:
   { name: 'main',
     entry: './src/app/main.jsx',
     output:
      { pathinfo: true,
        filename: 'main.bundle.js',
        path: '/Users/spencerelliott/some/project/build/public',
        publicPath: '/assets/' },
     devtool: 'eval',
     module: { preLoaders: [Object], loaders: [Object], noParse: [Object] },
     resolve:
      { extensions: [Object],
        root: '/Users/spencerelliott/some/project/src' },
     plugins: [ [Object], [Object], [Object], [Object] ] } }

Causing this error:

● Runtime Error
Error: Missing setting "resolve.root" in /Users/spencerelliott/some/project/webpack.config.js
    at Object.read (/Users/spencerelliott/some/project/node_modules/jest-webpack-alias/lib/webpackInfo.js:34:11)
    at ensureWebpackInfo (/Users/spencerelliott/some/project/node_modules/jest-webpack-alias/lib/preprocessor.js:25:33)
    at Object.process (/Users/spencerelliott/some/project/node_modules/jest-webpack-alias/lib/preprocessor.js:138:3)
    at Object.module.exports.process (/Users/spencerelliott/some/project/jestPreprocessor.js:20:31)

My current workaround is:

// webpack.config.js

export default module.exports = { /* the config */ };

Use Jest config to resolve configFile

    Cannot find module '******/webpack.config.js'

I found a line where you parse package.json ...

{
    "jest-webpack-alias":{
        "configFile": "tasks/webpack/production.js"
    }
}

Ok. But, it's strange to see that when you probably can place configFile into jest config. Why not?

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.