Skip to content

Commit baa9f0f

Browse files
authored
refact: simplify test framework integrations (#141)
* feat: simplify test framework integrations * docs * cleanup tests * cleanup
1 parent 74c832a commit baa9f0f

152 files changed

Lines changed: 1950 additions & 611 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.dockerignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.github/
2+
.ruby-lsp/
3+
coverage/
4+
tmp/
5+
6+
# Ignore report files
7+
*.attempt_*.png
8+
*.diff.png
9+
*.base.png
10+
*.attempt_*.webp
11+
*.diff.webp
12+
*.base.webp

.github/actions/setup-ruby-and-dependencies/action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ runs:
3535
# fallback if cache version is outdated
3636
- run: sudo apt-get -qq install libvips
3737
shell: bash
38+
39+
- run: sudo sed -i 's/true/false/g' /etc/fonts/conf.d/10-yes-antialias.conf
40+
shell: bash

.github/workflows/test.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ env:
2121
JAVA_OPTS: -Xmn2g -Xms6g -Xmx6g -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m -Xss1m
2222
-XX:+UseG1GC -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -XX:ReservedCodeCacheSize=256m
2323
-XX:+UseCodeCacheFlushing
24-
JRUBY_OPTS: --dev
24+
JRUBY_OPTS: --dev -J-Djruby.thread.pool.enabled=true
2525
MALLOC_ARENA_MAX: 2
2626
RUBY_GC_HEAP_FREE_SLOTS: 600000
2727
RUBY_GC_HEAP_GROWTH_FACTOR: 1.1
@@ -45,6 +45,8 @@ jobs:
4545
ruby-version: 3.4
4646

4747
- run: bin/rake test
48+
env:
49+
SCREENSHOT_DRIVER: vips
4850

4951
functional-test:
5052
name: Functional Test
@@ -87,11 +89,11 @@ jobs:
8789
github.event.pull_request.requested_reviewers.length > 0
8890
needs: [ functional-test ]
8991
runs-on: ubuntu-latest
90-
timeout-minutes: ${{ contains(matrix.ruby-version, 'jruby') && 12 || 8 }}
92+
timeout-minutes: ${{ contains(matrix.ruby-version, 'jruby') && 20 || 8 }}
9193
continue-on-error: ${{ matrix.experimental }}
9294
strategy:
9395
matrix:
94-
ruby-version: [ 3.4, 3.3, 3.2, jruby ]
96+
ruby-version: [ 3.4, 3.3, 3.2, jruby-9.4, jruby-10.0 ]
9597
gemfile:
9698
- rails70_gems.rb
9799
- rails71_gems.rb
@@ -104,7 +106,7 @@ jobs:
104106
gemfile: rails80_gems.rb
105107
experimental: false
106108
# JRuby 9.x is Ruby 3.1 compatible, and Rails 8 requires Ruby 3.2.
107-
- ruby-version: jruby
109+
- ruby-version: jruby-9.4
108110
gemfile: rails80_gems.rb
109111
experimental: false
110112
include:
@@ -130,7 +132,7 @@ jobs:
130132
- name: Run tests (with 2 retries)
131133
uses: nick-fields/retry@v3
132134
with:
133-
timeout_minutes: ${{ contains(matrix.ruby-version, 'jruby') && 3 || 3 }}
135+
timeout_minutes: ${{ contains(matrix.ruby-version, 'jruby') && 7 || 3 }}
134136
max_attempts: 3
135137
command: bin/rake test
136138

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*~
22
/.bundle/
33
/.idea
4+
/.windsurf
45
/.yardoc
56
/_yardoc/
67
/coverage/

.standard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
fix: true # default: false
33
parallel: true # default: false
44
format: progress # default: Standard::Formatter
5-
ruby_version: 3.2 # default: RUBY_VERSION
5+
ruby_version: 3.1 # to support JRuby 9.4
66
default_ignores: false # default: true
77

88
ignore: # default: []

Dockerfile

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
# $ docker build . -t csd
44
# $ docker run -v $(pwd):/app -ti csd rake test
55

6-
FROM --platform=linux/amd64 jetthoughts/cimg-ruby:3.4-chrome
6+
FROM jetthoughts/cimg-ruby:3.4-chrome
77

8-
# Install dependencies and clean up in one layer to reduce image size
9-
RUN sudo apt-get update -qq && \
10-
DEBIAN_FRONTEND=noninteractive sudo apt-get install -qq \
8+
ENV DEBIAN_FRONTEND=noninteractive \
9+
BUNDLE_PATH=/bundle
10+
11+
RUN --mount=type=cache,target=/var/cache/apt \
12+
sudo sed -i 's|http://security.ubuntu.com/ubuntu|http://archive.ubuntu.com/ubuntu|g' /etc/apt/sources.list && \
13+
sudo apt-get update -qq && \
14+
sudo apt-get install -qq --fix-missing \
1115
automake \
1216
build-essential \
1317
curl \
@@ -34,20 +38,12 @@ RUN sudo apt-get update -qq && \
3438
libwebp-dev \
3539
libxml2-dev \
3640
swig && \
37-
sudo apt-get autoremove -y && \
38-
sudo apt-get autoclean && \
39-
sudo apt-get clean && \
40-
sudo rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
41+
sudo apt-get autoclean
4142

42-
WORKDIR /app
43-
COPY gems.rb gemfiles capybara-screenshot-diff.gemspec /app/
44-
COPY lib/capybara/screenshot/diff/version.rb /app/lib/capybara/screenshot/diff/
43+
RUN sudo sed -i 's/true/false/g' /etc/fonts/conf.d/10-antialias.conf
4544

46-
# Set the location for Bundler to store gems
47-
ENV BUNDLE_PATH=/bundle
4845

49-
RUN sudo mkdir /bundle && \
50-
sudo chmod a+w+r /bundle \
51-
sudo mkdir -p /tmp/.X11-unix && \
52-
sudo chmod 1777 /tmp/.X11-unix
46+
RUN sudo mkdir -p /bundle /tmp/.X11-unix && \
47+
sudo chmod 1777 /bundle /tmp/.X11-unix
5348

49+
WORKDIR /app

bin/dtest

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,37 @@
11
#!/bin/bash
22

3-
set -eo pipefail
3+
set -o pipefail
44

55
export DOCKER_DEFAULT_PLATFORM=linux/amd64
66

7+
# Define allowed environment variables to pass to Docker
8+
ALLOWED_ENV_VARS=(
9+
"CI" "DEBUG" "TEST_ENV" "RAILS_ENV" "RACK_ENV" "COVERAGE" "DISABLE_ROLLBACK_COMPARISON_RUNTIME_FILES"
10+
"RECORD_SCREENSHOTS" "TEST" "TESTOPTS" "SCREENSHOT_DRIVER"
11+
)
12+
13+
# Build the Docker env args string
14+
DOCKER_ENV_ARGS=""
15+
for var in "${ALLOWED_ENV_VARS[@]}"; do
16+
if [[ -n "${!var}" ]]; then
17+
DOCKER_ENV_ARGS="$DOCKER_ENV_ARGS -e $var=${!var}"
18+
fi
19+
done
20+
21+
# Build the Docker image
722
docker build . -t csd:test
823

9-
docker run -v ${PWD}:/app -v csd-bundle-cache:/bundle --rm -it csd:test bin/setup
24+
# Run setup
25+
(docker run $DOCKER_ENV_ARGS -v ${PWD}:/app -v csd-bundle-cache:/bundle --rm -it csd:test bin/setup) || exit 1
1026

27+
# Run tests with different drivers
1128
echo "Running tests..."
12-
docker run -e CAPYBARA_DRIVER=cuprite -v ${PWD}:/app -v csd-bundle-cache:/bundle --rm -it csd:test bin/rake test
13-
docker run -e CAPYBARA_DRIVER=selenium_chrome_headless -v ${PWD}:/app -v csd-bundle-cache:/bundle --rm -it csd:test bin/rake test
14-
docker run -e CAPYBARA_DRIVER=selenium_headless -v ${PWD}:/app -v csd-bundle-cache:/bundle --rm -it csd:test bin/rake test
29+
DRIVERS=("cuprite" "selenium_chrome_headless" "selenium_headless")
30+
for driver in "${DRIVERS[@]}"; do
31+
echo "Running tests with $driver driver..."
32+
docker run $DOCKER_ENV_ARGS -e CAPYBARA_DRIVER="$driver" \
33+
-v ${PWD}:/app -v csd-bundle-cache:/bundle --rm -it csd:test \
34+
bin/rake test "$@"
35+
36+
CAPYBARA_DRIVER="$driver" bin/rake test "$@"
37+
done

capybara-screenshot-diff.gemspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
2323
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
2424
spec.require_paths = ["lib"]
2525

26-
spec.add_runtime_dependency "actionpack", ">= 7.0", "< 9"
26+
spec.add_development_dependency "actionpack", ">= 7.0", "< 9"
27+
spec.add_development_dependency "activesupport", ">= 7.0", "< 9"
2728
spec.add_runtime_dependency "capybara", ">= 2", "< 4"
2829
end

gemfiles/edge_gems.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
eval File.read(gems), binding, gems
55

66
git "https://github.com/rails/rails.git" do
7+
gem "activesupport"
78
gem "actionpack"
89
end

gemfiles/rails70_gems.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
eval File.read(gems), binding, gems
55

66
gem "actionpack", "~> 7.0.0"
7+
gem "activesupport", "~> 7.0.0", require: %w[active_support/deprecator active_support/test_case]
78
gem "mutex_m"
89
gem "drb"
910
gem "bigdecimal"

0 commit comments

Comments
 (0)