Comments (9)
We don't have any integration for compiling for tests in webpack at the moment. If you need webpack assets available for testing, then you currently have to compile them yourself.
from webpacker.
@p0wl In case you're interested, here's a snippet that will only run bin/webpack
if at least one JS test is run, and only if there's been updates to files in app/javascript
since the last test build
https://gist.github.com/naps62/a7dcce679a45592714ea6477108f0419
from webpacker.
It doesn't seem like the before(:suite)
would work. Maybe I am doing something wrong and if that's the case, please do let me know!
I tried before(:suite) and I think what happens is that the backticks kick off a subprocess. So the specs are running while webpack is compiling. Therefore, some specs fail raising that there is no such pack, while others succeed. This success and failure happen non-deterministically.
The second time that you run the specs, the files have been compiled, so there are fewer failures, but it's not guaranteed that any changes to the files since then will have made it through the compilation.
For now, I'm running RAILS_ENV=test bin/webpack
before I run the specs. But it'd be great to have a hook in the rspec command line or some other automatic thing. I wonder, for the 5.1 release, what will the recommended course of action be?
Update
Never mind! Actually, I got it to work by putting Webpacker::Manifest.load
after the bin/webpack
command. Before bin/webpack
runs, Webpacker::Manifest.instance
thinks there is no manifest-test.json
file. You have to reload the instance and it'll appear.
from webpacker.
We played around with different approaches, e.g. trying to only execute webpack if at least one spec needs it (via :js
group or similar), but we ended up running webpack before :suite
:
# spec/rails_helper.rb
config.before :suite do
# Run webpack compilation before suite, so assets exists in public/packs
# It would be better to run the webpack compilation only if at least one :js spec
# should be executed, but `when_first_matching_example_defined`
# does not work with `config.infer_spec_type_from_file_location!`
# see https://github.com/rspec/rspec-core/issues/2366
`bin/webpack`
end
for js tests we use jest (and babel-jest for transpiling), so no webpack involved there.
from webpacker.
I know this is closed, but I am running into the same issue with running my controller specs. To be clear, should I be putting a command within my config/environments/test.rb
that runs the webpack executable from /bin
?
from webpacker.
I'm interested to hear how others got this working. For now we are just running webpack
before we run our test suite, but it would be nice for to compile automatically before we run the integration tests. Maybe add it to bin/rspec
or in a RSpec.configure { |config| config.before(:suite) ... }
block...
from webpacker.
@zhumo not sure if you ran into the same problem, but making your change threw a parse error in /config/webpack/shared.js
when running rspec
:
const { basename, dirname, join, resolve } = require("path");
// ^
It's kinda smelly, but changing those imports to:
const P = require("path")
const basename = P.basename;
// ...
seems to fix the symptom. I had to change all files where the unpacking of require
was done. I would prefer to NOT do this. If anyone has any suggestions I'm all ears. This all feels like a hack to me.
from webpacker.
@taystack I did not run in to that issue. I am befuddled as to why that is happening for you because I think require("path")
is looking at a library external to both rails and webpacker.
from webpacker.
@taystack Maybe I found your problem? #192. If you follow through to the PR, you'll see that it requires node >= 6.4.0.
from webpacker.
Related Issues (20)
- Webpacker 6 Disable Babel HOT 1
- Webpacker compilation takes more than 1.5 hours HOT 11
- How do I allow a package in node_modules to be processed by babel? HOT 1
- Remove addition of node_modules to Rails.application.config.assets.paths HOT 1
- V6 Status HOT 3
- Raise an error when javascript_pack_tag or stylesheet_pack_tag are called more than once HOT 1
- Regular Expression Denial of Service in postcss HOT 2
- Intermittent Webpacker.dev_server.running? behavior HOT 2
- Host for assets from a webpacker configuration using custom domains not being resolved HOT 2
- Cherry-pick "Nothing to do" logging update onto `5.x` HOT 1
- Rails 6 WebPacker is not calling JQuery inside views HOT 1
- Security Vulnerability in [email protected] HOT 2
- currently no loaders are configured to process this file HOT 1
- Incompatibility with Ruby 3.2.0 HOT 2
- Confusing gem description on RubyGems HOT 1
- Npm package for 5.4.4 was not released HOT 2
- class variable @@local_levels of ActiveSupport::Logger is overtaken by Logger HOT 2
- Trying to deploy but assets assets:precompile fail
- Security Vulnerability for postcss
- Postcss Security Vulnerability
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webpacker.