Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work with AVA tests in separate processes #41

Closed
jedrichards opened this issue Mar 2, 2016 · 5 comments
Closed

Doesn't work with AVA tests in separate processes #41

jedrichards opened this issue Mar 2, 2016 · 5 comments

Comments

@jedrichards
Copy link
Contributor

I think this issue has already been noted here #4 (comment) but thought it would be worth making a dedicated issue, since it looks like no solution has been found?

The ava test runner runs each file under test in a new process, so I think this has the effect of adjusting the pwd to the folder of the current file and breaking this plugins ability to find the webpack config.

So a babel config that looks like,

{
  "presets": ["es2015"],
  "env": {
    "AVA": {
      "plugins": [
        [
          "babel-plugin-webpack-loaders",
          {
            "config": "./webpack.config.ava.js",
            "verbose": false
          }
        ]
      ]
    }
  }
}

breaks with an error,

Cannot find module '/Users/jed/work/project/components/text-control/webpack.config.ava.js'

If I change the config to the below it works perfectly, but obviously the absolute filepath is no good on a shared project ...

{
  "presets": ["es2015"],
  "env": {
    "AVA": {
      "plugins": [
        [
          "babel-plugin-webpack-loaders",
          {
            "config": "/Users/jed/work/project/webpack.config.ava.js",
            "verbose": false
          }
        ]
      ]
    }
  }
}

Any body got any ideas? I would be happy to try and prepare a PR ... but not sure what approach to take ...

@istarkov
Copy link
Owner

istarkov commented Mar 2, 2016

I can't get the idea of why ava changes process.cwd for tests. I never had those problem with path.join(__dirname as in ava documentation.

But as we talk not about ava, the problem is how to convert relative path in .babelrc to abs path.
process.cwd() is not a good solution but I have no other simple enough.

As a variant use some magic env variable like WEBPACK_CONFIG_ROOT and resolve path at 182 line via WEBPACK_CONFIG_ROOT if process.env.WEBPACK_CONFIG_ROOT exists.

So you could run test as

WEBPACK_CONFIG_ROOT=`pwd` .. bla bla... ava blabla 

Or allow $vars in plugin config section, and set any var you like

"plugins": [
        [
          "babel-plugin-webpack-loaders",
          {
            "config": "${SOMEVAR}/project/webpack.config.ava.js",
            "verbose": false
          }
        ]
      ]

@jedrichards
Copy link
Contributor Author

Something like that? #42

It wasn't clear to me how to add specific tests for it, without duplicating a lot of testing structure.

I could add a section to the readme too, similar to the Caching Issues https://github.com/istarkov/babel-plugin-webpack-loaders#caching-issues section you have already?

@istarkov
Copy link
Owner

istarkov commented Mar 2, 2016

#42 (comment)

It's easy to test, just add additional test config and check that path to config is resolved with your variable,

@jedrichards
Copy link
Contributor Author

Fixed and closed via: #42
Info now in the readme here: https://github.com/istarkov/babel-plugin-webpack-loaders#dynamic-config-path

Ty help @istarkov 🎉

@sindresorhus
Copy link

This will soon be fixed in AVA core and the workaround will not be needed anymore. We decided to reverse the decision to make CWD be the test file and instead it will be the directory of your package.json. See: avajs/ava#32

We could use some help with avajs/ava-codemods#19 so we can get the change into a release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants