Skip to content

Commit

Permalink
feat: add acceptance tests (#175)
Browse files Browse the repository at this point in the history
* feat: add acceptance tests with cypress/mocha
  • Loading branch information
olevski authored Jul 16, 2021
1 parent 11bfccd commit add75b1
Show file tree
Hide file tree
Showing 12 changed files with 2,118 additions and 1 deletion.
64 changes: 64 additions & 0 deletions .github/workflows/acceptance_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Acceptance tests

on:
pull_request:
types:
- synchronize

jobs:
build-base-python-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build Image
run: |
docker build -t py docker/py/
docker save py > /tmp/py.tar
- name: Upload Image Artifact
uses: actions/upload-artifact@v2
with:
name: py
path: /tmp/py.tar

acceptance-tests:
needs: build-base-python-image
strategy:
matrix:
include:
- image_name: py
test_user: jovyan
- image_name: cuda-tf
build_arg: BASE_IMAGE=py
test_user: jovyan
- image_name: generic
build_arg: RENKU_BASE=py
test_user: jovyan
- image_name: julia
build_arg: BASE_IMAGE=py
test_user: jovyan
- image_name: r
build_arg: RENKU_BASE=py
test_user: rstudio
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Download Base Image
uses: actions/download-artifact@v2
with:
name: py
path: /tmp
- name: Load Base Image in Docker
run: |
docker load --input /tmp/py.tar
- name: Build images
if: ${{ matrix.image_name != 'py' }}
run: |
docker build -t ${{ matrix.image_name }} --build-arg ${{ matrix.build_arg }} docker/${{ matrix.image_name }}/
- name: Py Image Acceptance Tests
uses: cypress-io/github-action@v2
env:
TEST_IMAGE_NAME: ${{ matrix.image_name }}
TEST_USER_NAME: ${{ matrix.test_user }}
with:
working-directory: tests
command: npx mocha test.js
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@
# Ignore all local history of files
.history

## Node modules
**/node_modules/*
## Cypress
tests/cypress/videos/*
tests/cypress/screenshots/*

# End of https://www.gitignore.io/api/visualstudiocode
2 changes: 2 additions & 0 deletions docker/generic/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ RUN apt-get update --fix-missing && \
libsm6 \
libxext6 \
libxrender1 \
tini \
wget \
vim && \
apt-get purge && \
Expand All @@ -51,6 +52,7 @@ ENV PATH ${CONDA_PATH}/bin:$PATH

# inject the renku-jupyter stack
COPY --from=renku_base /opt/conda /opt/conda
COPY --from=renku_base /entrypoint.sh /entrypoint.sh
COPY --from=renku_base --chown=1000:1000 \
/home/jovyan/ /home/${NB_USER}/

Expand Down
2 changes: 1 addition & 1 deletion docker/r/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ RUN /rocker_scripts/install_rstudio.sh
# Add Tini
ENV TINI_VERSION v0.18.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini
RUN chmod +x /tini && ln -s /tini /usr/bin/

# install dependencies
RUN apt-get update --fix-missing && \
Expand Down
28 changes: 28 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Acceptance Tests for Renkulab Images

## Requirements
- node
- docker

## Run Tests
The following instructions assume that the user has navigated to the `test` folder already.

1. Install node packages: `npm install`
2. Build the docker images:

```
docker build -t py ../docker/py
docker build -t cuda-tf --build-arg BASE_IMAGE=py ../docker/cuda-tf/
docker build -t generic --build-arg RENKU_BASE=py ../docker/generic/
docker build -t julia --build-arg BASE_IMAGE=py ../docker/julia/
docker build -t r --build-arg RENKU_BASE=py ../docker/r/
```

3. Test an image: `TEST_IMAGE_NAME="py" TEST_USER_NAME="jovyan" npx mocha test.js`

Mocha is used to launch a test session with Cypress for each image. Mocha
captures and displays the logs from Cypress for each test. The reason for having Mocha
launch the Cypress tests is because the Cypress tests cannot run terminal commands
to launch a Jupyterlab container beacuse they operate only in the browser. However,
running Mocha tests does not have this limitation and the Mocha tests can launch
containers with Jupyterlab as well as all Cypress tests.
3 changes: 3 additions & 0 deletions tests/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"defaultCommandTimeout": 10000
}
22 changes: 22 additions & 0 deletions tests/cypress/integration/test.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
describe('Basic functionality', function() {
before(function() {
cy.visit(Cypress.env("URL"))
})
it('Can find launcher icons', function() {
cy.get('div.jp-LauncherCard')
})
it('Can find main menu at the top', function() {
cy.get('div#jp-menu-panel')
})
it('Can launch terminal', function() {
cy.get('div.jp-LauncherCard[title="Start a new terminal session"]').click()
})
it('Runs a command in the terminal to make new file', function () {
cy.get('canvas.xterm-link-layer')
cy.get('div.xterm-screen').click().type("touch new-file.txt{enter}")
})
it('Can see the new file in the file browser', function () {
cy.get('button[title="Refresh File List"]').click().wait(2000)
cy.get('li.jp-DirListing-item[title^="Name: new-file.txt"]')
})
})
22 changes: 22 additions & 0 deletions tests/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}
*/
// eslint-disable-next-line no-unused-vars
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}
24 changes: 24 additions & 0 deletions tests/cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
// import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')

Cypress.on('uncaught:exception', (err) => {
return false
})
Loading

0 comments on commit add75b1

Please sign in to comment.