Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ export default defineConfig({
viewportHeight: 720,

// Tries again 2 more times on failure
retries: 2,
retries: {
runMode: 2,
// do not retry in `cypress open`
openMode: 0,
},

// Needed to trigger `before:run` events with cypress open
// Needed to trigger `after:run` events with cypress open
experimentalInteractiveRunEvents: true,

// faster video processing
Expand All @@ -35,6 +39,7 @@ export default defineConfig({
async setupNodeEvents(on, config) {
// Fix browserslist extend https://github.com/cypress-io/cypress/issues/2983#issuecomment-570616682
on('file:preprocessor', browserify())
// on('file:preprocessor', webpackPreprocessor({ webpackOptions }))
getCompareSnapshotsPlugin(on, config)

// Disable spell checking to prevent rendering differences
Expand Down Expand Up @@ -62,7 +67,7 @@ export default defineConfig({

// Before the browser launches
// starting Nextcloud testing container
return startNextcloud()
return startNextcloud(process.env.BRANCH)
.then((ip) => {
// Setting container's IP as base Url
config.baseUrl = `http://${ip}/index.php`
Expand Down
95 changes: 64 additions & 31 deletions cypress/dockerNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,50 @@ const pkg = require('../package.json');
const APP_PATH = path.resolve(__dirname, '../')
const APP_NAME = pkg.name

const SERVER_IMAGE = 'ghcr.io/nextcloud/continuous-integration-shallow-server'

/**
* Start the testing container
*/
export const startNextcloud = async function (branch = 'master'): Promise<any> {
export const startNextcloud = async function (branch: string = 'master'): Promise<any> {
try {
// Remove old container if exists
// Pulling images
console.log('Pulling images...')
await docker.pull(SERVER_IMAGE)

// Getting latest image
console.log('\nChecking running containers... 🔍')
const localImage = await docker.listImages({ filters: `{"reference": ["${SERVER_IMAGE}"]}` })

// Remove old container if exists and not initialized by us
try {
const oldContainer = docker.getContainer(CONTAINER_NAME)
const oldContainerData = await oldContainer.inspect()
if (oldContainerData.State.Running) {
console.log(`├─ Existing running container found`)
if (localImage[0].Id !== oldContainerData.Image) {
console.log(`└─ But running container is outdated, replacing...`)
} else {
// Get container's IP
console.log(`├─ Reusing that container`)
let ip = await getContainerIP(oldContainer)
return ip
}
} else {
console.log(`└─ None found!`)
}
// Forcing any remnants to be removed just in case
await oldContainer.remove({ force: true })
} catch (error) {}

// Pulling images
console.log('Pulling images...')
await docker.pull('ghcr.io/nextcloud/continuous-integration-shallow-server')
} catch (error) {
console.log(`└─ None found!`)
}

// Starting container
console.log('Starting Nextcloud container...')
console.log(`> Using branch '${branch}'`)
console.log(`> Mounting app '${APP_NAME}' from '${APP_PATH}'`)
console.log('\nStarting Nextcloud container... 🚀')
console.log(`├─ Using branch '${branch}'`)
console.log(`├─ And binding app '${APP_NAME}' from '${APP_PATH}'`)
const container = await docker.createContainer({
Image: 'ghcr.io/nextcloud/continuous-integration-shallow-server',
Image: SERVER_IMAGE,
name: CONTAINER_NAME,
Env: [`BRANCH=${branch}`],
HostConfig: {
Expand All @@ -63,35 +86,36 @@ export const startNextcloud = async function (branch = 'master'): Promise<any> {
// Get container's IP
let ip = await getContainerIP(container)

console.log(`> Nextcloud container's IP is ${ip} 🌏`)
console.log(`├─ Nextcloud container's IP is ${ip} 🌏`)
return ip
} catch (err) {
console.log(`└─ Unable to start the container 🛑`)
console.log(err)
stopNextcloud()
throw new Error('> Unable to start the container 🛑')
throw new Error('Unable to start the container')
}
}

/**
* Configure Nextcloud
*/
export const configureNextcloud = async function () {
console.log('Configuring nextcloud...')
console.log('\nConfiguring nextcloud...')
const container = docker.getContainer(CONTAINER_NAME)
await runExec(container, ['php', 'occ', '--version'])
await runExec(container, ['php', 'occ', '--version'], true)

// Be consistent for screenshots
await runExec(container, ['php', 'occ', 'config:system:set', 'default_language', '--value', 'en'])
await runExec(container, ['php', 'occ', 'config:system:set', 'force_language', '--value', 'en'])
await runExec(container, ['php', 'occ', 'config:system:set', 'default_locale', '--value', 'en_US'])
await runExec(container, ['php', 'occ', 'config:system:set', 'force_locale', '--value', 'en_US'])
await runExec(container, ['php', 'occ', 'config:system:set', 'enforce_theme', '--value', 'light'])
await runExec(container, ['php', 'occ', 'config:system:set', 'default_language', '--value', 'en'], true)
await runExec(container, ['php', 'occ', 'config:system:set', 'force_language', '--value', 'en'], true)
await runExec(container, ['php', 'occ', 'config:system:set', 'default_locale', '--value', 'en_US'], true)
await runExec(container, ['php', 'occ', 'config:system:set', 'force_locale', '--value', 'en_US'], true)
await runExec(container, ['php', 'occ', 'config:system:set', 'enforce_theme', '--value', 'light'], true)

// Enable the app and give status
await runExec(container, ['php', 'occ', 'app:enable', '--force', 'viewer'])
await runExec(container, ['php', 'occ', 'app:list'])
await runExec(container, ['php', 'occ', 'app:enable', '--force', 'viewer'], true)
// await runExec(container, ['php', 'occ', 'app:list'], true)

console.log('> Nextcloud is now ready to use 🎉')
console.log('└─ Nextcloud is now ready to use 🎉')
}

/**
Expand All @@ -102,7 +126,7 @@ export const stopNextcloud = async function () {
const container = docker.getContainer(CONTAINER_NAME)
console.log('Stopping Nextcloud container...')
container.remove({ force: true })
console.log('> Nextcloud container removed 🥀')
console.log('└─ Nextcloud container removed 🥀')
} catch (err) {
console.log(err)
}
Expand Down Expand Up @@ -139,13 +163,15 @@ export const getContainerIP = async function (
// We need to make sure the server is already running before cypress
// https://github.com/cypress-io/cypress/issues/22676
export const waitOnNextcloud = async function (ip: string) {
console.log('> Waiting for Nextcloud to be ready ⏳')
console.log('├─ Waiting for Nextcloud to be ready... ⏳')
await waitOn({ resources: [`http://${ip}/index.php`] })
console.log('└─ Done')
}

const runExec = async function (
container: Docker.Container,
command: string[]
command: string[],
verbose: boolean = false
) {
const exec = await container.exec({
Cmd: command,
Expand All @@ -154,11 +180,18 @@ const runExec = async function (
User: 'www-data',
})

await exec.start({}, (err, stream) => {
if (stream) {
stream.setEncoding('utf-8')
stream.on('data', console.log)
}
return new Promise((resolve, reject) => {
exec.start({}, (err, stream) => {
if (stream) {
stream.setEncoding('utf-8')
stream.on('data', str => {
if (verbose && str.trim() !== '') {
console.log(`├─ ${str.trim().replace(/\n/gi, '\n├─ ')}`)
}
})
stream.on('end', resolve)
}
})
})
}

Expand Down
14 changes: 6 additions & 8 deletions cypress/e2e/delete.cy.js → cypress/e2e/actions/delete.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,25 @@
*
*/

import { randHash } from '../utils'
import { randHash } from '../../utils'
const randUser = randHash()

describe('Delete image.png in viewer', function() {
before(function() {
// Init user
cy.nextcloudCreateUser(randUser, 'password')
cy.login(randUser, 'password')
cy.nextcloudCreateUser(randUser)

// Upload test files
cy.uploadFile('image.png', 'image/png')
cy.visit('/apps/files')

// wait a bit for things to be settled
cy.wait(1000)
cy.uploadFile(randUser, 'image.png', 'image/png')
})
after(function() {
cy.logout()
})

it('See image.png in the list', function() {
cy.login(randUser)
cy.visit('/apps/files')

cy.get('.files-fileList tr[data-file="image.png"]', { timeout: 10000 })
.should('contain', 'image.png')
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
*/

import { randHash } from '../utils'
import { randHash } from '../../utils'
import * as path from 'path'

const randUser = randHash()
Expand All @@ -29,22 +29,20 @@ const fileName = 'image.png'
describe(`Download ${fileName} in viewer`, function() {
before(function() {
// Init user
cy.nextcloudCreateUser(randUser, 'password')
cy.login(randUser, 'password')
cy.nextcloudCreateUser(randUser)

// Upload test files
cy.uploadFile(fileName, 'image/png')
cy.visit('/apps/files')

// wait a bit for things to be settled
cy.wait(1000)
cy.uploadFile(randUser, fileName, 'image/png')
})

after(function() {
cy.logout()
})

it(`See "${fileName}" in the list`, function() {
cy.login(randUser)
cy.visit('/apps/files')

cy.get(`.files-fileList tr[data-file="${fileName}"]`, { timeout: 10000 })
.should('contain', fileName)
})
Expand Down
20 changes: 9 additions & 11 deletions cypress/e2e/sidebar.cy.js → cypress/e2e/actions/sidebar.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,28 @@
*
*/

import { randHash } from '../utils/'
import { randHash } from '../../utils'
const randUser = randHash()

describe('Open the sidebar from the viewer and open viewer with sidebar already opened', function() {
before(function() {
// Init user
cy.nextcloudCreateUser(randUser, 'password')
cy.login(randUser, 'password')
cy.nextcloudCreateUser(randUser)

// Upload test files
cy.uploadFile('image1.jpg', 'image/jpeg')
cy.uploadFile('image2.jpg', 'image/jpeg')
cy.uploadFile('image3.jpg', 'image/jpeg')
cy.uploadFile('image4.jpg', 'image/jpeg')
cy.visit('/apps/files')

// wait a bit for things to be settled
cy.wait(1000)
cy.uploadFile(randUser, 'image1.jpg', 'image/jpeg')
cy.uploadFile(randUser, 'image2.jpg', 'image/jpeg')
cy.uploadFile(randUser, 'image3.jpg', 'image/jpeg')
cy.uploadFile(randUser, 'image4.jpg', 'image/jpeg')
})
after(function() {
cy.logout()
})

it('See images in the list', function() {
cy.login(randUser)
cy.visit('/apps/files')

cy.get('.files-fileList tr[data-file="image1.jpg"]', { timeout: 10000 })
.should('contain', 'image1.jpg')
cy.get('.files-fileList tr[data-file="image2.jpg"]', { timeout: 10000 })
Expand Down
76 changes: 0 additions & 76 deletions cypress/e2e/audio.mpeg.cy.js

This file was deleted.

Loading