I'm trying to run jest tests alongside my rails application in Travis CI. This is what pops up in the Travis CI logs.
$ yarn test
yarn run v1.9.4
$ jest
/bin/sh: jest: not found
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Here's my .travis.yml
sudo: required
services:
- docker
- redis-server
language: ruby
cache:
bundler: true
directories:
- node_modules
yarn: true
addons:
postgresql: "9.6"
chrome: stable
rvm:
- 2.5.1
before_script:
- cp config/database.yml{.sample,}
- bundle exec rake db:create db:test:prepare assets:precompile
install:
- bundle install
- nvm install node
- node -v
- npm i -g yarn
- yarn
script:
- yarn test
- bundle exec rake test
Here's my package.json > scripts and devDependencies section
"scripts": { "test": "jest" },
"devDependencies": {
"#vue/test-utils": "^1.0.0-beta.25",
"babel-jest": "^23.6.0",
"babel-preset-es2015": "^6.24.1",
"eslint": "^5.5.0",
"eslint-plugin-jest": "^21.22.0",
"eslint-plugin-vue": "^4.7.1",
"jest": "^23.6.0",
"jest-canvas-mock": "^1.1.0",
"stylelint": "^9.5.0",
"stylelint-config-standard": "^18.2.0",
"vue-jest": "^2.6.0",
"webpack-dev-server": "2.11.2"
},
"jest": {
"roots": [
It fails on yarn test. When I debug the job and re-run the steps one-by-one it succeeds and it can find and run jest successfully. I've also tried clearing caches for the repo.
Am I missing something on my setup?
I figured it out, the offending step is:
before_script:
- cp config/database.yml{.sample,}
- bundle exec rake db:create db:test:prepare assets:precompile
install:
- bundle install
- nvm install node
- node -v
- npm i -g yarn
- yarn
script:
- yarn test
- bundle exec rake test
The bundle exec rake assets:precompile compiles the webpack bundle for production and removes devDependencies. So when it gets to the script step it cannot find jest anymore. The short term fix was removing assets:precompile in the before_script. Long-term would be to make a separate job testing for asset precompilation itself.
Related
Extremly odd error, asset precompilation works fine in dev mode, but as soon as i do production mode, i get error:
root#53407ec15126:/app# RAILS_ENV=production rails assets:precompile
yarn install v1.22.18
[1/4] Resolving packages...
success Already up-to-date.
Done in 0.04s.
yarn run v1.22.18
error Command "build" not found.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
rails aborted!
jsbundling-rails: Command build failed, ensure yarn is installed and `yarn build` runs without errors
Tasks: TOP => assets:precompile => javascript:build
(See full trace by running task with --trace)
root#53407ec15126:/chinese-flashcards-app#
And the weirdest thing is, i dont even use yarn in my project(i use importmaps).
Well.. I figured out how to do a monkey patch(Sigh..).
Add this to package.json:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "echo 1",
"build:css": "echo 1"
},
This does not resolve the issue of rails prod preprocessor using yarn/npm tho(i dont need them).
I built a new rails app and when I have configured the .travis.yml file it exits with one all the time.
Here is my travis configuration:
language: ruby
node_js:
- 12
cache:
bundler: true
yarn: true
services:
- redis-server
sudo: required
before_install:
- sudo apt-get update
- sudo apt-get install google-chrome-stable
addons:
postgresql: '9.6'
before_script:
- psql -c 'create database product_hunt_clone_test;' -U postgres
script:
- bundle install
- bundle exec rake db:schema:load
- bundle exec rake db:test:prepare
- SECRET_KEY_BASE=a RAILS_ENV=production bundle exec rake assets:precompile
- bundle exec rake test
- bundle exec rake test:system
and here are the errors travis is giving me:
screenshot from travis console
You have apparently create the initial application using the --skip-sprockets parameter. As such, you have disable the use of the assets pipeline in your application and with that have disable the need (and possibility) to run rake assets:precompile.
If you do need assets pipeline (and thus the rails-sprockets gem), you can re-enable it by adding
gem "sprockets-rails"
to your Gemfile and uncommenting the line
# require "sprockets/railtie"
in your config/application.rb file. You would also need to create the asset files as necessary. Please refer to the documentation for the assets pipeline for details.
If you actually want to skip the assets pipeline, you can just remove the call to the assets:precompile task from your .travis.yml.
Are you correctly installing your gems (with bundle install) before executing your rake commands? Seems like you would need sprockets before compiling the assets.
I struggle setting up Wercker on a rails / Webpacker project.
I first had to add steps to install node, then another to pre-compile react packs, then to install yarn. First it was good but then I added dependencies to the project and know I'm stuck on 3 dependencies with the same error message :
ERROR in ./app/javascript/app/index.js
Module not found: Error: Can't resolve 'redux-thunk' in '/pipeline/source/app/javascript/app'
# ./app/javascript/app/index.js 5:0-32
# ./app/javascript/packs/app.js
That's happening only with redux-thunk, react-redux-i18n and react-spinkit
I've tried to add a step yarn install which passes through the process but doesn't solve the problem.
Here is my wercker.yml:
# wercker.yml
box: ruby:2.4.1
services:
- redis
- postgres
build:
steps:
- louischavane/install-phantomjs#0.0.5
- rails-database-yml
- script:
name: nokogiri tricks
code: bundle config build.nokogiri --use-system-libraries
- bundle-install
- bigtruedata/install-node#2.1.1
- akupila/yarn#0.2.0
- script:
name: yarn-install
code: yarn install
- script:
name: pre-compile react packs
code: NODE_ENV=test bundle exec rails webpacker:compile
- script:
name: run migration
code: rake db:migrate RAILS_ENV=test
- script:
name: load fixture
code: rake db:fixtures:load RAILS_ENV=test
- script:
name: run rubocop
code: bundle exec rubocop
- script:
name: test
code: bundle exec rake test RAILS_ENV=test
Found a way around adding a step to remove node modules before pre-compiling :
- script:
name: delete node modules
code: rm -rf node_modules
UPDATE
I now have a clean Wercker setup handling tests, system tests with chrome headless, rubocop, eslint and stylelint. You can find it here: https://gist.github.com/adesurirey/7c013bfa1a9bed9d56ffea54db5d6288
I have installed bower in the app server and I am able to run bundle exec rake bower:install in any release or in current directory. But when I'm trying the same while cap production deploy, the following error is repeated.
Command:
cd /home/deploy/apps/xxxx/releases/20150910064532 && ~/.rvm/bin/rvm default do bundle exec rake bower:install CI=true
Bower not found! You can install Bower using Node and npm:
DEBUG [68147ae5] $ npm install bower -g
DEBUG [68147ae5] For more info see http://bower.io/
config in deploy.rb
namespace :bower do
desc 'Install bower'
task :install do
on roles(:web) do
within release_path do
execute :rake, 'bower:install CI=true'
end
end
end
end
before 'deploy:compile_assets', 'bower:install'
I have a rails project and am running tests for my JavaScript test (Jasmine) through Karma
.travis.yml file
language: ruby
rvm:
- 2.0.0
script:
- RAILS_ENV=test bundle exec rake --trace db:migrate test
- karma start --single-run --browsers PhantomJS test/karma/config/unit.js
Travis fails saying it does not find karma. is there a way to define node_js as another language and install karma on the build VM?
It is not possible yet to have several languages on travis configuration file.
On the other hand, all environments run node.js. The following script does the trick:
language: ruby
rvm:
- 2.0.0
before_script:
- npm install karma
script:
- RAILS_ENV=test bundle exec rake --trace db:migrate test
- karma start --single-run --browsers PhantomJS test/karma/config/unit.js
Help found on an old thread in a google group
K-Yo's answer got me moving in the right direction, but far short of success. Here is what I needed:
First in my .travis.yml:
language: ruby
rvm:
- 2.1.1
before_script:
- psql -c 'create database spokenvote_test;' -U postgres
- cp config/database.travis.yml config/database.yml
- rake db:test_prep
- npm install karma
- npm install karma-jasmine
- npm install karma-coverage
- npm install karma-phantomjs-launcher
- npm install karma-coffee-preprocessor
script:
- bundle exec rspec spec # basic for ruby
- node_modules/karma/bin/karma start config/karma.conf.js --single-run --browsers PhantomJS
Then I also placed this code in my package.json, though I'm not sure if it was needed:
"devDependencies": {
"karma": "~0.12",
"karma-jasmine": "~0.2",
"karma-coverage": "~0.2.6",
"karma-phantomjs-launcher": "~0.1.4",
"karma-coffee-preprocessor": "~0.2.1"
},
Finally, I learned that Travis is case sensitive, so:
'bower_components/jquery/dist/jquery.min.js',
in my karma.conf.js needed to be:
'bower_components/jQuery/dist/jquery.min.js',
When the language key in .travis.yml is set to node, Travis will run nvm install 0.12 at the beginning of the build. Similarly, for a Ruby project, Travis will run rvm use 2.2.2 --install --binary --fuzzy at the beginning of the build.
I've had success running both commands in a Bash build