Skip to content

Commit

Permalink
Add jest to circleci
Browse files Browse the repository at this point in the history
  • Loading branch information
carolinesalib committed May 17, 2020
1 parent 427bd6f commit 144a885
Show file tree
Hide file tree
Showing 4 changed files with 3,200 additions and 25 deletions.
19 changes: 18 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ jobs:
- v1-dependencies-{{ checksum "Gemfile.lock" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- restore_cache:
name: Restore Yarn Package Cache
keys:
- yarn-packages-{{ checksum "yarn.lock" }}

- run:
name: install dependencies
Expand All @@ -43,11 +47,17 @@ jobs:
sudo rm /usr/local/bin/bundler
sudo gem install bundler
bundle install --jobs=4 --retry=3 --path vendor/bundle
yarn install --frozen-lockfile
- save_cache:
paths:
- ./vendor/bundle
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
- save_cache:
name: Save Yarn Package Cache
key: yarn-packages-{{ checksum "yarn.lock" }}
paths:
- ~/.cache/yarn

# Database setup
- run: bundle exec rake db:create
Expand All @@ -63,12 +73,19 @@ jobs:
# run tests!
- run:
name: run tests
name: run rails tests
command: |
mkdir /tmp/test-results
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
bundle exec rspec spec --format progress --format RspecJunitFormatter --out /tmp/test-results/rspec.xml
- run:
name: run js` tests
command: |
npm test
environment:
JEST_JUNIT_OUTPUT: "/tmp/test-results/jest.xml"

# collect reports
- store_test_results:
path: /tmp/test-results
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"webpack-dev-server": "^3.7.2"
},
"scripts": {
"test": "jest"
"test": "node scripts/test.js --env=jsdom"
},
"jest": {
"setupFilesAfterEnv": [
Expand All @@ -57,8 +57,7 @@
"app/javascript/packs"
],
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
"<rootDir>/spec/javascript/__mocks__/fileMock.js",
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/spec/javascript/__mocks__/fileMock.js",
"\\.(css|sass)$": "<rootDir>/spec/javascript/__mocks__/styleMock.js"
}
}
Expand Down
22 changes: 22 additions & 0 deletions scripts/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

// Do this as the first thing so that any code reading it knows the right env.
process.env.BABEL_ENV = 'test';
process.env.NODE_ENV = 'test';

// Makes the script crash on unhandled rejections instead of silently
// ignoring them. In the future, promise rejections that are not handled will
// terminate the Node.js process with a non-zero exit code.
process.on('unhandledRejection', err => {
throw err;
});

const jest = require('jest');
const argv = process.argv.slice(2);

// Watch unless on CI or in coverage mode
if (!process.env.CI && argv.indexOf('--coverage') < 0) {
argv.push('--watch');
}

jest.run(argv);
Loading

0 comments on commit 144a885

Please sign in to comment.