Masafumi Okura
Masafumi Okura

Reputation: 724

Why do I get webpacker error only on CircieCI?

I have RSpec test suite which passes on my local machine. However, when I run specs on CircleCI, it fails.

Here are the outputs:

1) Articles GET /articles/:id when article exists when article feedbacked behaves like success response and template behaves like normal request returns 200
     Failure/Error: = javascript_pack_tag 'personal_comment/index'

     ActionView::Template::Error:
       Webpacker can't find personal_comment/index in /home/circleci/project/public/packs-test/manifest.json. Possible causes:
       1. You want to set webpacker.yml value of compile to true for your environment
          unless you are using the `webpack -w` or the webpack-dev-server.
       2. webpack has not yet re-run to reflect updates.
       3. You have misconfigured Webpacker's config/webpacker.yml file.
       4. Your webpack configuration is not creating a manifest.
       Your manifest contains:
       {
       }
     Shared Example Group: "normal request" called from ./spec/support/requests/request_macros.rb:14
     Shared Example Group: "success response and template" called from ./spec/requests/articles_spec.rb:19
     # ./app/views/articles/feedbacked/show.html.haml:37:in `_app_views_articles_feedbacked_show_html_haml___803483453260433823_47067249050920'

It says our manifest is empty, but as far as I can confirm on my local machine it is not empty.

Here's our config file for CircleCI:

version: 2.1

references:
  default_docker_ruby_executor: &default_docker_ruby_executor
    image: circleci/ruby:2.6.5-stretch-node
    environment:
      BUNDLE_JOBS: 3
      BUNDLE_RETRY: 3
      BUNDLE_PATH: vendor/bundle
      PGHOST: 127.0.0.1
      PGUSER: root
      PGPASSWORD: ""
      RAILS_ENV: test
  postgres: &postgres
    image: circleci/postgres:11.6-alpine
    environment:
      POSTGRES_USER: root
      POSTGRES_DB: app_test
      POSTGRES_PASSWORD: ""

jobs:
  build:
    docker:
      - *default_docker_ruby_executor
    steps:
      - checkout
      # bundle cache
      - restore_cache:
          keys:
            - app-bundle-v2-{{ checksum "Gemfile.lock" }}
            - app-bundle-v2-
      - run:
          name: Bundle Install
          command: bundle check || bundle install
      # Store bundle cache
      - save_cache:
          key: rewrites-bundle-v2-{{ checksum "Gemfile.lock" }}
          paths:
            - vendor/bundle
      # Only necessary if app uses webpacker or yarn in some other way
      - restore_cache:
          keys:
            - app-yarn-{{ checksum "yarn.lock" }}
            - app-yarn-
      - run:
          name: Yarn Install
          command: yarn install --cache-folder ~/.cache/yarn
      # Store yarn / webpacker cache
      - save_cache:
          key: app-yarn-{{ checksum "yarn.lock" }}
          paths:
            - ~/.cache/yarn
  test:
    parallelism: 2
    docker:
      - *default_docker_ruby_executor
      - *postgres
    steps:
      - checkout
      - restore_cache:
          keys:
            - app-bundle-v2-{{ checksum "Gemfile.lock" }}
            - app-bundle-v2-
      - run:
          name: Bundle Install
          command: bundle check || bundle install
      - restore_cache:
          keys:
            - rewrites-yarn-{{ checksum "yarn.lock" }}
            - rewrites-yarn-
      - run:
          name: Wait for DB
          command: dockerize -wait tcp://localhost:5432 -timeout 1m
      - run:
          name: Database setup
          command: bundle exec rails db:schema:load --trace
      # Run rspec in parallel
      - run:
          command: |
            mkdir /tmp/test-results
            TESTFILES=$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)
            bundle exec rspec $TESTFILES --profile 10 --format RspecJunitFormatter --out /tmp/test-results/rspec.xml --format progress
      - store_test_results:
          path: /tmp/test-results
      - store_artifacts:
          path: /tmp/test-results
          destination: test-results

workflows:
  version: 2
  build_and_test:
    jobs:
      - build
      - test:
          requires:
            - build

I think this is something related to Webpacker, but don't know what to do.

Upvotes: 1

Views: 1486

Answers (1)

avimoondra
avimoondra

Reputation: 896

It seems like assets are not being compiled in CircleCI.

You may need to set NODE_ENV=test at the top, and another step to compile assets (which happen automatically in development, by default):

- run:
    name: Build assets
    command: bundle exec rails assets:precompile

This will run webpacker:compile in addition to some other tasks to configure youur environment correctly. Note, you will need config/webpack/test.js and a test section in config/webpacker.yaml. Looks like this documentation is not recorded here: https://circleci.com/docs/2.0/language-ruby/.

Some helpful links:

Upvotes: 3

Related Questions