update ci config

pull/1667/head
gabrielburnworth 2020-01-24 09:10:46 -08:00
parent e05b4a3d1c
commit 3b2422607f
7 changed files with 192 additions and 72 deletions

View File

@ -1,9 +1,25 @@
version: 2
jobs:
build:
version: 2.1
executors:
build-executor:
machine: true
working_directory: /home/circleci/project
commands:
build-commands:
steps:
- checkout
- restore_cache:
keys:
- cache-v1-{{ .Revision }}-{{ .Environment.CIRCLE_WORKFLOW_ID }}
- run:
name: After cache restore
command: |
git clean -xdn
mkdir -p docker_cache
ls docker_cache
#sudo docker images
#if [ -f docker_cache/images.tar.gz ]; then gunzip -c docker_cache/images.tar.gz | sudo docker load; fi
- run:
name: Build and Install Deps
command: |
@ -16,26 +32,107 @@ jobs:
sudo docker-compose run web bundle exec rails db:create
sudo docker-compose run web bundle exec rails db:migrate
sudo docker-compose run web rake keys:generate
- run:
name: After cache update
command: |
git clean -xdn
ls docker_cache
#sudo docker images
#if [ ! -f docker_cache/images.tar.gz ]; then sudo docker save $(sudo docker images ruby -q) | gzip > docker_cache/images.tar.gz; fi
- save_cache:
key: cache-v1-{{ .Revision }}-{{ .Environment.CIRCLE_WORKFLOW_ID }}
paths:
- docker_volumes
- node_modules
- docker_cache
rspec-commands:
steps:
- run:
name: Run Ruby Tests
command: |
sudo docker-compose run web rspec spec
sudo docker-compose run web rspec spec --format progress --format RspecJunitFormatter --out test-results/rspec/rspec.xml
jest-commands:
steps:
- run:
name: Run JS tests
command: |
sudo docker-compose run web npm run test-very-slow -- -c .circleci/jest-ci.config.js
lint-commands:
steps:
- run:
name: Run JS Linters
command: |
sudo docker-compose run web npm run linters
when: always
coverage-commands:
steps:
- run:
name: Run JS Tests
name: Check coverage status
command: |
sudo docker-compose run web npm run test-very-slow
echo 'export COVERAGE_AVAILABLE=true' >> $BASH_ENV
sudo docker-compose run -e CIRCLE_SHA1="$CIRCLE_SHA1" -e CIRCLE_BRANCH="$CIRCLE_BRANCH" -e CIRCLE_PULL_REQUEST="$CIRCLE_PULL_REQUEST" web rake coverage:run
no_output_timeout: 15m
when: always
- run:
name: Report coverage to Coveralls
command: |
if [ "$COVERAGE_AVAILABLE" ]
if [ -f /home/circleci/project/coverage_fe/lcov.info ]
then
sudo docker-compose run -e COVERALLS_REPO_TOKEN=lEX6nkql7y2YFCcIXVq5ORvdvMtYzfZdG web npm run coverage
fi
when: always # change to `on_success` for a stricter comparison
workflows:
version: 2
build_and_test:
jobs:
#- build
- all
#- test-api:
# requires:
# - build
#- run-linters:
# requires:
# - build
#- test-fe:
# requires:
# - build
jobs:
build:
executor: build-executor
steps:
- build-commands
all:
executor: build-executor
steps:
- build-commands
- rspec-commands
- lint-commands
- jest-commands
- store_test_results:
path: test-results
- coverage-commands
test-api:
executor: build-executor
steps:
- build-commands
- rspec-commands
- store_test_results:
path: test-results
run-linters:
executor: build-executor
steps:
- build-commands
- lint-commands
test-fe:
executor: build-executor
parallelism: 4
steps:
- build-commands
- run:
name: Run JS Tests
command: |
circleci tests glob **/__tests__/**/*.ts* | circleci tests split > /tmp/tests-to-run
sudo docker-compose run web npm run test-very-slow -- -c .circleci/jest-ci.config.js $(cat /tmp/tests-to-run)
- store_test_results:
path: test-results

View File

@ -0,0 +1,11 @@
const baseConfig = require("../jest.config");
baseConfig.rootDir = "..";
baseConfig.reporters.push([
"jest-junit",
{
outputDirectory: "test-results/jest"
}
]);
module.exports = baseConfig;

View File

@ -37,6 +37,7 @@ group :development, :test do
gem "pry"
gem "rspec-rails", "4.0.0.beta3"
gem "rspec"
gem 'rspec_junit_formatter'
gem "simplecov"
gem "smarf_doc", git: "https://github.com/RickCarlino/smarf_doc.git"
end

View File

@ -262,6 +262,8 @@ GEM
rspec-mocks (~> 3.8)
rspec-support (~> 3.8)
rspec-support (3.9.2)
rspec_junit_formatter (0.4.1)
rspec-core (>= 2, < 4, != 2.12.0)
scenic (1.5.1)
activerecord (>= 4.0.0)
railties (>= 4.0.0)
@ -333,6 +335,7 @@ DEPENDENCIES
rollbar
rspec
rspec-rails (= 4.0.0.beta3)
rspec_junit_formatter
scenic
secure_headers
simplecov
@ -344,4 +347,4 @@ RUBY VERSION
ruby 2.6.5p114
BUNDLED WITH
2.1.3
2.1.4

53
jest.config.js 100644
View File

@ -0,0 +1,53 @@
module.exports = {
"clearMocks": true,
"logHeapUsage": true,
"globals": {
"ts-jest": {
"diagnostics": {
"ignoreCodes": [
151001
]
}
},
"globalConfig": {
"NODE_ENV": "development",
"TOS_URL": "https://farm.bot/tos/",
"PRIV_URL": "https://farm.bot/privacy/",
"LONG_REVISION": "------------",
"SHORT_REVISION": "--------"
}
},
"setupFiles": [
"./frontend/__test_support__/setup_enzyme.js",
"./frontend/__test_support__/localstorage.js",
"./frontend/__test_support__/mock_fbtoaster.ts",
"./frontend/__test_support__/unmock_i18next.ts",
"./frontend/__test_support__/additional_mocks.ts"
],
"transform": {
".(ts|tsx)": "ts-jest"
},
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"collectCoverage": true,
"collectCoverageFrom": [
"frontend/**/*.{ts,tsx}"
],
"reporters": [
"default",
"jest-skipped-reporter"
],
"coverageReporters": [
"html",
"json",
"lcov"
],
"coverageDirectory": "<rootDir>/coverage_fe",
"setupFilesAfterEnv": [
"<rootDir>/frontend/__test_support__/customMatchers.js"
]
}

View File

@ -127,7 +127,11 @@ end
# Calculate coverage results from JSON coverage report.
def get_json_coverage_results()
results = {lines: {covered: 0, total: 0}, branches: {covered: 0, total: 0}}
data = open_json(JSON_COVERAGE_FILE_PATH)
begin
data = open_json(JSON_COVERAGE_FILE_PATH)
rescue Errno::ENOENT
return results
end
data.each do |filename, file_coverage|
lineMap = {}
file_coverage["s"].each do |statement, count|
@ -181,13 +185,16 @@ namespace :coverage do
"The Coveralls stats reporter used to perform this check, but didn't" \
"compare against a PR's base branch and would always return 0% change."
task run: :environment do
# Fetch current build coverage data from the HTML summary.
statements, branches, functions, lines =
Nokogiri::HTML(URI.open(COVERAGE_FILE_PATH))
.css(CSS_SELECTOR)
.map(&:text)
.map { |x| x.split(FRACTION_DELIM).map(&:to_f) }
.map { |x| Pair.new(*x) }
begin
# Fetch current build coverage data from the HTML summary.
statements, branches, functions, lines =
Nokogiri::HTML(URI.open(COVERAGE_FILE_PATH))
.css(CSS_SELECTOR)
.map(&:text)
.map { |x| x.split(FRACTION_DELIM).map(&:to_f) }
.map { |x| Pair.new(*x) }
rescue Errno::ENOENT
end
puts "\nUnable to determine coverage from HTML report." if lines.nil?
puts "Checking JSON report..." if lines.nil?

View File

@ -8,7 +8,7 @@
},
"scripts": {
"coverage": "cat **/*lcov.info | ./node_modules/coveralls/bin/coveralls.js",
"test-very-slow": "node --expose-gc ./node_modules/.bin/jest -i --colors --coverage # low CPU/RAM usage",
"test-very-slow": "node --expose-gc ./node_modules/.bin/jest -i --colors --coverage",
"test-slow": "./node_modules/.bin/jest -w 6 --colors",
"test": "./node_modules/.bin/jest -w 5 --no-coverage",
"typecheck": "./node_modules/typescript/bin/tsc --noEmit",
@ -82,60 +82,8 @@
"jest": "24.9.0",
"jest-cli": "24.9.0",
"jest-skipped-reporter": "0.0.5",
"jest-junit": "10.0.0",
"jshint": "2.11.0-rc1",
"madge": "3.6.0"
},
"jest": {
"clearMocks": true,
"logHeapUsage": true,
"globals": {
"ts-jest": {
"diagnostics": {
"ignoreCodes": [
151001
]
}
},
"globalConfig": {
"NODE_ENV": "development",
"TOS_URL": "https://farm.bot/tos/",
"PRIV_URL": "https://farm.bot/privacy/",
"LONG_REVISION": "------------",
"SHORT_REVISION": "--------"
}
},
"setupFiles": [
"./frontend/__test_support__/setup_enzyme.js",
"./frontend/__test_support__/localstorage.js",
"./frontend/__test_support__/mock_fbtoaster.ts",
"./frontend/__test_support__/unmock_i18next.ts",
"./frontend/__test_support__/additional_mocks.ts"
],
"transform": {
".(ts|tsx)": "ts-jest"
},
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"collectCoverage": true,
"collectCoverageFrom": [
"frontend/**/*.{ts,tsx}"
],
"reporters": [
"default",
"jest-skipped-reporter"
],
"coverageReporters": [
"html",
"json",
"lcov"
],
"coverageDirectory": "<rootDir>/coverage_fe",
"setupFilesAfterEnv": [
"<rootDir>/frontend/__test_support__/customMatchers.js"
]
}
}