Skip to content

Commit

Permalink
Cypress-based test suite (#157)
Browse files Browse the repository at this point in the history
* Add initial Cypress test suite

* ci: Run Cypress tests

* Rename CI workflow to match reality

* Add missing Cypress install step

* Add Cache action to avoid downloading too many things
  • Loading branch information
wetneb authored Jan 8, 2025
1 parent 73afaa0 commit 8e63818
Show file tree
Hide file tree
Showing 13 changed files with 3,280 additions and 5 deletions.
28 changes: 23 additions & 5 deletions .github/workflows/maven.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: Java CI with Maven
name: CI

on:
push:
Expand All @@ -25,20 +25,38 @@ jobs:
distribution: 'temurin'
cache: maven

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Restore dependency cache
uses: actions/cache@v4
with:
path: |
cypress/openrefine-*.tar.gz
**/node_modules
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}

- name: Build with Maven
run: mvn -B package

- name: Install Cypress
run: |
cd ./cypress
npm i -g yarn
yarn install
- name: Run Cypress tests
run: ./cypress/run_headless.sh

- name: Get release upload URL
id: get_release_upload_url
if: github.event_name == 'release'
uses: bruceadams/[email protected]
env:
GITHUB_TOKEN: ${{ github.token }}

- name: Extract version string
id: version_string_variable
run: echo "VERSION_STRING=$(mvn org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV

- name: Upload release asset
id: upload-release-asset
if: github.event_name == 'release'
Expand Down
4 changes: 4 additions & 0 deletions cypress/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
.yarn/
.yarnrc.yml
openrefine*
9 changes: 9 additions & 0 deletions cypress/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Commons extension E2E tests

Inspired from [OpenRefine's own Cypress test suite](https://openrefine.org/docs/technical-reference/functional-tests)

Install the dependencies with `yarn install`.

Run the test suite with `yarn run cypress open`.

This requires a running instance of OpenRefine with the CommonsExtension installed at `http://localhost:3333/`.
24 changes: 24 additions & 0 deletions cypress/cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const { defineConfig } = require('cypress')

module.exports = defineConfig({
keystrokeDelay: 0,
viewportWidth: 1280,
viewportHeight: 768,
retries: {
runMode: 3,
openMode: 0,
},
env: {
OPENREFINE_URL: 'http://localhost:3333',
DISABLE_PROJECT_CLEANUP: 0,
},
e2e: {
experimentalRunAllSpecs: true,
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
setupNodeEvents(on, config) {
return require('./cypress/plugins/index.js')(on, config)
},
specPattern: './cypress/e2e/**/*.cy.{js,jsx,ts,tsx}',
},
})
37 changes: 37 additions & 0 deletions cypress/cypress/e2e/import_category/create_project.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
describe(__filename, function () {
afterEach(() => {
cy.addProjectForDeletion();
});

it('Test the create project from a Commons category', function () {
cy.visitOpenRefine();
cy.navigateTo('Create project');
cy.get('#create-project-ui-source-selection-tabs > a')
.contains('Wikimedia Commons')
.click();
// enter a category name
cy.get(
'input.category-input-box'
).type('Official OpenRefine logos');
cy.get(
'.fbs-item-name'
)
.contains('Official OpenRefine logos')
.click();

cy.get(
'.create-project-ui-source-selection-tab-body.selected button.button-primary'
)
.contains('Next »')
.click();

// then ensure we are on the preview page
cy.get('.create-project-ui-panel').contains('Configure Parsing Options');

// preview and click next
cy.get('button[bind="createProjectButton"]')
.contains('Create Project »')
.click();
cy.waitForProjectTable();
});
});
5 changes: 5 additions & 0 deletions cypress/cypress/fixtures/fixtures.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

const fixtures = {
};

export default fixtures;
22 changes: 22 additions & 0 deletions cypress/cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// / <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)
/**
* @type {Cypress.PluginConfig}
*/

module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
return config;
};
Loading

0 comments on commit 8e63818

Please sign in to comment.