GithubHelp home page GithubHelp logo

Support test rails enviroment about webpacker HOT 9 CLOSED

rails avatar rails commented on May 5, 2024 3
Support test rails enviroment

from webpacker.

Comments (9)

dhh avatar dhh commented on May 5, 2024 28

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.

naps62 avatar naps62 commented on May 5, 2024 25

@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.

zhumo avatar zhumo commented on May 5, 2024 20

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.

p0wl avatar p0wl commented on May 5, 2024 16

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.

taystack avatar taystack commented on May 5, 2024

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.

stereoscott avatar stereoscott commented on May 5, 2024

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.

taystack avatar taystack commented on May 5, 2024

@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.

zhumo avatar zhumo commented on May 5, 2024

@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.

zhumo avatar zhumo commented on May 5, 2024

@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)

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.