Skip to content

Commit c089f77

Browse files
authored
Merge pull request #1437 from nextcloud/feat/fallback-img-source
Fallback to direct image if preview load failed
2 parents d80eb34 + 38b20d7 commit c089f77

Some content is hidden

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

54 files changed

+821
-1058
lines changed

cypress.config.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ export default defineConfig({
1313
viewportHeight: 720,
1414

1515
// Tries again 2 more times on failure
16-
retries: 2,
16+
retries: {
17+
runMode: 2,
18+
// do not retry in `cypress open`
19+
openMode: 0,
20+
},
1721

18-
// Needed to trigger `before:run` events with cypress open
22+
// Needed to trigger `after:run` events with cypress open
1923
experimentalInteractiveRunEvents: true,
2024

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

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

6368
// Before the browser launches
6469
// starting Nextcloud testing container
65-
return startNextcloud()
70+
return startNextcloud(process.env.BRANCH)
6671
.then((ip) => {
6772
// Setting container's IP as base Url
6873
config.baseUrl = `http://${ip}/index.php`

cypress/dockerNode.ts

Lines changed: 64 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,50 @@ const pkg = require('../package.json');
3131
const APP_PATH = path.resolve(__dirname, '../')
3232
const APP_NAME = pkg.name
3333

34+
const SERVER_IMAGE = 'ghcr.io/nextcloud/continuous-integration-shallow-server'
35+
3436
/**
3537
* Start the testing container
3638
*/
37-
export const startNextcloud = async function (branch = 'master'): Promise<any> {
39+
export const startNextcloud = async function (branch: string = 'master'): Promise<any> {
3840
try {
39-
// Remove old container if exists
41+
// Pulling images
42+
console.log('Pulling images...')
43+
await docker.pull(SERVER_IMAGE)
44+
45+
// Getting latest image
46+
console.log('\nChecking running containers... 🔍')
47+
const localImage = await docker.listImages({ filters: `{"reference": ["${SERVER_IMAGE}"]}` })
48+
49+
// Remove old container if exists and not initialized by us
4050
try {
4151
const oldContainer = docker.getContainer(CONTAINER_NAME)
52+
const oldContainerData = await oldContainer.inspect()
53+
if (oldContainerData.State.Running) {
54+
console.log(`├─ Existing running container found`)
55+
if (localImage[0].Id !== oldContainerData.Image) {
56+
console.log(`└─ But running container is outdated, replacing...`)
57+
} else {
58+
// Get container's IP
59+
console.log(`├─ Reusing that container`)
60+
let ip = await getContainerIP(oldContainer)
61+
return ip
62+
}
63+
} else {
64+
console.log(`└─ None found!`)
65+
}
66+
// Forcing any remnants to be removed just in case
4267
await oldContainer.remove({ force: true })
43-
} catch (error) {}
44-
45-
// Pulling images
46-
console.log('Pulling images...')
47-
await docker.pull('ghcr.io/nextcloud/continuous-integration-shallow-server')
68+
} catch (error) {
69+
console.log(`└─ None found!`)
70+
}
4871

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

66-
console.log(`> Nextcloud container's IP is ${ip} 🌏`)
89+
console.log(`├─ Nextcloud container's IP is ${ip} 🌏`)
6790
return ip
6891
} catch (err) {
92+
console.log(`└─ Unable to start the container 🛑`)
6993
console.log(err)
7094
stopNextcloud()
71-
throw new Error('> Unable to start the container 🛑')
95+
throw new Error('Unable to start the container')
7296
}
7397
}
7498

7599
/**
76100
* Configure Nextcloud
77101
*/
78102
export const configureNextcloud = async function () {
79-
console.log('Configuring nextcloud...')
103+
console.log('\nConfiguring nextcloud...')
80104
const container = docker.getContainer(CONTAINER_NAME)
81-
await runExec(container, ['php', 'occ', '--version'])
105+
await runExec(container, ['php', 'occ', '--version'], true)
82106

83107
// Be consistent for screenshots
84-
await runExec(container, ['php', 'occ', 'config:system:set', 'default_language', '--value', 'en'])
85-
await runExec(container, ['php', 'occ', 'config:system:set', 'force_language', '--value', 'en'])
86-
await runExec(container, ['php', 'occ', 'config:system:set', 'default_locale', '--value', 'en_US'])
87-
await runExec(container, ['php', 'occ', 'config:system:set', 'force_locale', '--value', 'en_US'])
88-
await runExec(container, ['php', 'occ', 'config:system:set', 'enforce_theme', '--value', 'light'])
108+
await runExec(container, ['php', 'occ', 'config:system:set', 'default_language', '--value', 'en'], true)
109+
await runExec(container, ['php', 'occ', 'config:system:set', 'force_language', '--value', 'en'], true)
110+
await runExec(container, ['php', 'occ', 'config:system:set', 'default_locale', '--value', 'en_US'], true)
111+
await runExec(container, ['php', 'occ', 'config:system:set', 'force_locale', '--value', 'en_US'], true)
112+
await runExec(container, ['php', 'occ', 'config:system:set', 'enforce_theme', '--value', 'light'], true)
89113

90114
// Enable the app and give status
91-
await runExec(container, ['php', 'occ', 'app:enable', '--force', 'viewer'])
92-
await runExec(container, ['php', 'occ', 'app:list'])
115+
await runExec(container, ['php', 'occ', 'app:enable', '--force', 'viewer'], true)
116+
// await runExec(container, ['php', 'occ', 'app:list'], true)
93117

94-
console.log('> Nextcloud is now ready to use 🎉')
118+
console.log('└─ Nextcloud is now ready to use 🎉')
95119
}
96120

97121
/**
@@ -102,7 +126,7 @@ export const stopNextcloud = async function () {
102126
const container = docker.getContainer(CONTAINER_NAME)
103127
console.log('Stopping Nextcloud container...')
104128
container.remove({ force: true })
105-
console.log('> Nextcloud container removed 🥀')
129+
console.log('└─ Nextcloud container removed 🥀')
106130
} catch (err) {
107131
console.log(err)
108132
}
@@ -139,13 +163,15 @@ export const getContainerIP = async function (
139163
// We need to make sure the server is already running before cypress
140164
// https://github.com/cypress-io/cypress/issues/22676
141165
export const waitOnNextcloud = async function (ip: string) {
142-
console.log('> Waiting for Nextcloud to be ready ⏳')
166+
console.log('├─ Waiting for Nextcloud to be ready... ⏳')
143167
await waitOn({ resources: [`http://${ip}/index.php`] })
168+
console.log('└─ Done')
144169
}
145170

146171
const runExec = async function (
147172
container: Docker.Container,
148-
command: string[]
173+
command: string[],
174+
verbose: boolean = false
149175
) {
150176
const exec = await container.exec({
151177
Cmd: command,
@@ -154,11 +180,18 @@ const runExec = async function (
154180
User: 'www-data',
155181
})
156182

157-
await exec.start({}, (err, stream) => {
158-
if (stream) {
159-
stream.setEncoding('utf-8')
160-
stream.on('data', console.log)
161-
}
183+
return new Promise((resolve, reject) => {
184+
exec.start({}, (err, stream) => {
185+
if (stream) {
186+
stream.setEncoding('utf-8')
187+
stream.on('data', str => {
188+
if (verbose && str.trim() !== '') {
189+
console.log(`├─ ${str.trim().replace(/\n/gi, '\n├─ ')}`)
190+
}
191+
})
192+
stream.on('end', resolve)
193+
}
194+
})
162195
})
163196
}
164197

cypress/e2e/delete.cy.js renamed to cypress/e2e/actions/delete.cy.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,25 @@
2020
*
2121
*/
2222

23-
import { randHash } from '../utils'
23+
import { randHash } from '../../utils'
2424
const randUser = randHash()
2525

2626
describe('Delete image.png in viewer', function() {
2727
before(function() {
2828
// Init user
29-
cy.nextcloudCreateUser(randUser, 'password')
30-
cy.login(randUser, 'password')
29+
cy.nextcloudCreateUser(randUser)
3130

3231
// Upload test files
33-
cy.uploadFile('image.png', 'image/png')
34-
cy.visit('/apps/files')
35-
36-
// wait a bit for things to be settled
37-
cy.wait(1000)
32+
cy.uploadFile(randUser, 'image.png', 'image/png')
3833
})
3934
after(function() {
4035
cy.logout()
4136
})
4237

4338
it('See image.png in the list', function() {
39+
cy.login(randUser)
40+
cy.visit('/apps/files')
41+
4442
cy.get('.files-fileList tr[data-file="image.png"]', { timeout: 10000 })
4543
.should('contain', 'image.png')
4644
})

cypress/e2e/download.cy.js renamed to cypress/e2e/actions/download.cy.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*
2121
*/
2222

23-
import { randHash } from '../utils'
23+
import { randHash } from '../../utils'
2424
import * as path from 'path'
2525

2626
const randUser = randHash()
@@ -29,22 +29,20 @@ const fileName = 'image.png'
2929
describe(`Download ${fileName} in viewer`, function() {
3030
before(function() {
3131
// Init user
32-
cy.nextcloudCreateUser(randUser, 'password')
33-
cy.login(randUser, 'password')
32+
cy.nextcloudCreateUser(randUser)
3433

3534
// Upload test files
36-
cy.uploadFile(fileName, 'image/png')
37-
cy.visit('/apps/files')
38-
39-
// wait a bit for things to be settled
40-
cy.wait(1000)
35+
cy.uploadFile(randUser, fileName, 'image/png')
4136
})
4237

4338
after(function() {
4439
cy.logout()
4540
})
4641

4742
it(`See "${fileName}" in the list`, function() {
43+
cy.login(randUser)
44+
cy.visit('/apps/files')
45+
4846
cy.get(`.files-fileList tr[data-file="${fileName}"]`, { timeout: 10000 })
4947
.should('contain', fileName)
5048
})

cypress/e2e/sidebar.cy.js renamed to cypress/e2e/actions/sidebar.cy.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,28 @@
2121
*
2222
*/
2323

24-
import { randHash } from '../utils/'
24+
import { randHash } from '../../utils'
2525
const randUser = randHash()
2626

2727
describe('Open the sidebar from the viewer and open viewer with sidebar already opened', function() {
2828
before(function() {
2929
// Init user
30-
cy.nextcloudCreateUser(randUser, 'password')
31-
cy.login(randUser, 'password')
30+
cy.nextcloudCreateUser(randUser)
3231

3332
// Upload test files
34-
cy.uploadFile('image1.jpg', 'image/jpeg')
35-
cy.uploadFile('image2.jpg', 'image/jpeg')
36-
cy.uploadFile('image3.jpg', 'image/jpeg')
37-
cy.uploadFile('image4.jpg', 'image/jpeg')
38-
cy.visit('/apps/files')
39-
40-
// wait a bit for things to be settled
41-
cy.wait(1000)
33+
cy.uploadFile(randUser, 'image1.jpg', 'image/jpeg')
34+
cy.uploadFile(randUser, 'image2.jpg', 'image/jpeg')
35+
cy.uploadFile(randUser, 'image3.jpg', 'image/jpeg')
36+
cy.uploadFile(randUser, 'image4.jpg', 'image/jpeg')
4237
})
4338
after(function() {
4439
cy.logout()
4540
})
4641

4742
it('See images in the list', function() {
43+
cy.login(randUser)
44+
cy.visit('/apps/files')
45+
4846
cy.get('.files-fileList tr[data-file="image1.jpg"]', { timeout: 10000 })
4947
.should('contain', 'image1.jpg')
5048
cy.get('.files-fileList tr[data-file="image2.jpg"]', { timeout: 10000 })

cypress/e2e/audio.mpeg.cy.js

Lines changed: 0 additions & 76 deletions
This file was deleted.

0 commit comments

Comments
 (0)