为什么我只在 CircieCI 上收到 webpacker 错误?
Why do I get webpacker error only on CircieCI?
我有 RSpec 测试套件在我的本地机器上通过。
但是,当我 运行 在 CircleCI 上规范时,它失败了。
输出如下:
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'
它说我们的清单是空的,但据我在本地机器上确认它不是空的。
这是我们的 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
我觉得这个跟Webpacker有关,但是不知道怎么办。
CircleCI 中似乎没有编译资产。
您可能需要在顶部设置 NODE_ENV=test
,以及另一个编译资产的步骤(默认情况下在开发中自动发生):
- run:
name: Build assets
command: bundle exec rails assets:precompile
这将 运行 webpacker:compile
除了一些其他任务来正确配置您的环境。请注意,您将需要 config/webpack/test.js
和 config/webpacker.yaml
中的 test
部分。此处似乎未记录此文档:https://circleci.com/docs/2.0/language-ruby/.
一些有用的链接:
我有 RSpec 测试套件在我的本地机器上通过。 但是,当我 运行 在 CircleCI 上规范时,它失败了。
输出如下:
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'
它说我们的清单是空的,但据我在本地机器上确认它不是空的。
这是我们的 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
我觉得这个跟Webpacker有关,但是不知道怎么办。
CircleCI 中似乎没有编译资产。
您可能需要在顶部设置 NODE_ENV=test
,以及另一个编译资产的步骤(默认情况下在开发中自动发生):
- run:
name: Build assets
command: bundle exec rails assets:precompile
这将 运行 webpacker:compile
除了一些其他任务来正确配置您的环境。请注意,您将需要 config/webpack/test.js
和 config/webpacker.yaml
中的 test
部分。此处似乎未记录此文档:https://circleci.com/docs/2.0/language-ruby/.
一些有用的链接: