avajs / awesome-ava

Awesome AVA resources
https://avajs.dev
Creative Commons Zero v1.0 Universal
346 stars 36 forks source link

Add babel-plugin-webpack-loaders #3

Closed istarkov closed 7 years ago

istarkov commented 8 years ago

babel-plugin-webpack-loaders allows you to run code with non js imports, without webpack preprocessing step or require mocks. Compatible with AVA https://github.com/istarkov/babel-plugin-webpack-loaders#dynamic-config-path

sindresorhus commented 8 years ago

Can you add a short description on how it's relevant to AVA?

istarkov commented 8 years ago

A lot of developers use webpack as a bundler. A lot of them use webpack loaders feature, this feature allows you to preprocess different types of files like css, sass, txt etc.

The problem with test tools like mocha, ava, etc... that you can't test js files with code like

import myCssModuleClasses from 'myStyle.css';
...
<Blabla className={myCssModuleClasses.blabla} />

js can't imports css, and will fail if you try to test code above.

To run test on such file, you need to preprocess it with webpack or to use require mocks. Both variant is not good.

babel-plugin-webpack-loaders allows you to use webpack loaders without webpack preprocessing step.

With this plugin, example above can be tested as usual.

So this plugin is not directly relevant to ava, but allows to test without pain a big part of modern js components with ava, mocha and others.

One of the issue when I released this plugin, that it doesn't work with ava https://github.com/istarkov/babel-plugin-webpack-loaders/issues/41

Now it supports ava.

istarkov commented 8 years ago

Also small article about http://browniefed.com/blog/2016/01/31/css-modules-webpack-and-testing/

danielkcz commented 8 years ago

What about including that plugin internally same way as power-assert and similar? This would most probably require to be enabled in configuration as not everyone would want it. However in my opinion it's good way to go at least until full webpack support is finished.

sindresorhus commented 8 years ago

Sorry, totally forgot about this PR.

sindresorhus commented 7 years ago

ping @istarkov