Skip to content

Commit

Permalink
added e2e tests to ci
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed May 15, 2021
1 parent 04755aa commit f62fa88
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 13 deletions.
6 changes: 6 additions & 0 deletions .github/ci-gemfiles/ruby-3.0 → .github/gemfiles/ruby-3.0
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ gem 'rubocop-rake', require: false

gem 'simplecov', require: false
gem 'codecov', require: false

group :apps do
gem 'puma'
gem 'sinatra'
gem 'sinatra-contrib'
end
79 changes: 70 additions & 9 deletions .github/workflows/pagy-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,37 @@ on:
branches: ['**']

jobs:
test:
name: Ruby ${{ matrix.ruby-version }}

should_run:
name: Run or skip?
continue-on-error: true
runs-on: ubuntu-latest
outputs:
should_skip: ${{ steps.skip_check.outputs.should_skip }}
steps:
- id: skip_check
uses: fkirc/skip-duplicate-actions@master
with:
# All of these options are optional, so you can remove them if you are happy with the defaults
concurrent_skipping: 'never'
skip_after_successful_duplicate: 'true'
paths_ignore: '["**/README.md", "**/docs/**"]'
do_not_skip: '["pull_request", "workflow_dispatch", "schedule"]'


ruby_test:
needs: should_run
if: ${{ needs.should_run.outputs.should_skip != 'true' }}
name: Ruby ${{ matrix.ruby-version }} Test
runs-on: ubuntu-latest
strategy:
matrix:
include:
- ruby-version: 3.0
env:
BUNDLE_GEMFILE: .github/ci-gemfiles/ruby-3.0
BUNDLE_GEMFILE: .github/gemfiles/ruby-3.0
CODECOV: true
RAKE_MANIFEST: true
CHECK_MANIFEST: true
fail-fast: false
env: ${{ matrix.env }}

Expand All @@ -30,18 +50,59 @@ jobs:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically

- name: Run tests
- name: Run Ruby Tests
run: bundle exec rake test

- name: Run rubocop for github
- name: Run Rubocop
run: bundle exec rubocop --format github

- name: Codecov
- name: Run Codecov
if: ${{ env.CODECOV == 'true' }}
uses: codecov/[email protected]
with:
fail_ci_if_error: true

- name: Check whether pagy.manifest is up-to-date in master|dev
if: ${{ env.RAKE_MANIFEST == 'true' && (endsWith(github.ref, '/master') || endsWith(github.ref, '/dev')) }}
- name: Check gem manifest
if: ${{ env.CHECK_MANIFEST == 'true' }}
run: bundle exec rake manifest:check


e2e_test:
needs: should_run
if: ${{ needs.should_run.outputs.should_skip != 'true' }}
name: E2E Test
runs-on: ubuntu-latest
env:
# absolute path to run sinatra for cypress in test/e2e working dir
BUNDLE_GEMFILE: /home/runner/work/pagy/pagy/.github/gemfiles/ruby-3.0

steps:
- uses: actions/checkout@v2

- name: Set up ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0
bundler-cache: true

- name: Cache NPM and Cypress
id: e2e-cache
uses: actions/cache@v2
with:
path: |
~/.cache/Cypress
node_modules
key: e2e-cache-${{ runner.os }}-${{ hashFiles('test/e2e/ci-cache.lock') }}

- name: Install Cypress and Test Dependencies
# if: steps.e2e-cache.outputs.cache-hit != 'true'
run: npm i cypress @cypress/snapshot html-validate cypress-html-validate

- name: Run Cypress Tests
uses: cypress-io/[email protected]
with:
install: false
config: baseUrl=http://0.0.0.0:4567,video=false
start: bundle exec rackup -D -o 0.0.0.0 -p 4567 pagy_app.ru
wait-on: http://0.0.0.0:4567
working-directory: test/e2e
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ _The [IPS/Kb ratio](http://ddnexus.github.io/pagination-comparison/gems.html#eff
- Pagy has a very slim core code of just above 100 lines of simple ruby, organized in 3 flat modules, very easy to understand and use _(see [more...](https://ddnexus.github.io/pagy/api))_
- It has a quite fat set of optional extras that you can explicitly require for very efficient and modular customization _(see [extras](https://ddnexus.github.io/pagy/extras))_
- It has no dependencies: it produces its own HTML, URLs, i18n with its own specialized and fast code _(see [why...](https://ddnexus.github.io/pagy/index#specialized-code-instead-of-generic-helpers))_
- 100% of its methods are public API, accessible and overridable **right where you use them** (no pesky monkey-patching needed)
- 100% test coverage for core code and extras
- 100% of its methods are accessible and overridable **right where you use them** (no pesky monkey-patching needed)
- 100% test coverage and HTML validated
- Ruby, HTML and Jvascript E2E tested with Cypress (see [Pagy Workflows CI](https://github.com/ddnexus/pagy/actions))

### Totally Agnostic

Expand Down
4 changes: 2 additions & 2 deletions pagy-on-docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ _**Notice**: This is the easiest way to run/edit the E2E tests but it requires `
- [Install Cypress](https://docs.cypress.io/guides/getting-started/installing-cypress)
- `bundle install`
- `ruby test/e2e/app.rb`
- `rackup test/e2e/pagy_app.rb`
- Open and run your Cypress tests `./node_modules/.bin/cypress open`
### 3. Build Pagy Cypress
Expand Down Expand Up @@ -150,7 +150,7 @@ If you just want to run the tests, run the container from the `pagy-on-docker` d
docker-compose up pagy-cypress
```
That will run all the tests with the built in `electron` browser in headless mode and print a report right on the screen. It will also create a video for each test file run in the `test_js/cypress/videos`. That will be useful in case of failure, showing you exactly what was on the page of the browser during the whole process.
That will run all the tests with the built in `electron` browser in headless mode and print a report right on the screen. It will also create a video for each test file run in the `test/e2e/cypress/videos`. In case of test failures you will also have screenshots images in `test/e2e/cypress/screenshots` showing you exactly what was on the page of the browser at the moment of the failure.
#### Open Cypress
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/ci-cache.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cypress:7.3.0
@cypress/snapshot:2.1.7
cypress-html-validate:1.5.1

6 changes: 6 additions & 0 deletions test/e2e/ci-cache.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# run this in order to ensure the ci cache will get updated with the latest verions

rm -rf ci-cache.lock
for pkg in cypress @cypress/snapshot cypress-html-validate ; do
echo $pkg:$(npm view $pkg version) >> ci-cache.lock
done

0 comments on commit f62fa88

Please sign in to comment.