Skip to content

Commit fddf2ca

Browse files
skjnldsvbackportbot[bot]
authored andcommitted
fix(cypress): wait for ressource load
Signed-off-by: skjnldsv <[email protected]> [skip ci]
1 parent 0d82335 commit fddf2ca

8 files changed

Lines changed: 36 additions & 22 deletions

File tree

.eslintrc.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"globals": {
33
"appName": true,
44
"appVersion": true,
5-
"INJECT_CYPRESS_FONT": true,
65
"PLYR_ICONS": true,
76
"oc_defaults": true,
87
"__dirname": true

.github/workflows/cypress.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jobs:
6666
- name: Install node dependencies & build app
6767
run: |
6868
npm ci
69-
TESTING=true npm run build --if-present
69+
npm run build --if-present
7070
7171
- name: Save context
7272
uses: buildjet/cache/save@e376f15c6ec6dc595375c78633174c7e5f92dc0e # v3
@@ -119,7 +119,6 @@ jobs:
119119
# https://github.com/cypress-io/github-action/issues/124
120120
COMMIT_INFO_MESSAGE: ${{ github.event.pull_request.title }}
121121
# Needed for some specific code workarounds
122-
TESTING: true
123122
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
124123
SPLIT: ${{ matrix.total-containers }}
125124
SPLIT_INDEX: ${{ matrix.containers == 'component' && 0 || matrix.containers }}

cypress/e2e/visual-regression.cy.ts

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

23-
describe('Visual regression tests ', function() {
23+
describe('Visual regression tests', function() {
2424
let randUser
2525

2626
before(function() {
@@ -36,18 +36,28 @@ describe('Visual regression tests ', function() {
3636
cy.login(user)
3737
cy.visit('/apps/files')
3838
})
39+
40+
cy.window().then((win) => {
41+
// Load roboto font for visual regression consistency
42+
win.loadRoboto = true
43+
win.document.body.style.fontFamily = 'Roboto'
44+
})
3945
})
4046

4147
it('See files in the list', function() {
42-
// TODO: Do we care about the file name being split by a ' ' in the text property?
4348
cy.getFile('test-card.mp4', { timeout: 10000 })
4449
.should('contain', 'test-card .mp4')
4550
cy.getFile('test-card.png', { timeout: 10000 })
4651
.should('contain', 'test-card .png')
4752
})
4853

4954
it('Open the viewer on file click', function() {
55+
cy.intercept('GET', '**/core/preview*').as('image1')
56+
cy.intercept('GET', '/remote.php/dav/files/*/test-card.mp4').as('video')
5057
cy.openFile('test-card.mp4')
58+
cy.wait('@video')
59+
// We preload images, so we can check its loading here and not when clicking next
60+
cy.wait('@image1')
5161
cy.get('body > .viewer').should('be.visible')
5262
})
5363

@@ -73,7 +83,7 @@ describe('Visual regression tests ', function() {
7383
.and('not.have.class', 'icon-loading')
7484
})
7585

76-
it('Take test-card.mp4 screenshot', function() {
86+
it('Take test-card.mp4 screenshot', { retries: 0 }, function() {
7787
cy.get('body > .viewer .modal-container .viewer__file.viewer__file--active video').then(video => {
7888
video.get(0).pause()
7989
video.get(0).currentTime = 1
@@ -99,14 +109,17 @@ describe('Visual regression tests ', function() {
99109
.and('not.have.class', 'icon-loading')
100110
})
101111

102-
it('Take test-card.png screenshot', function() {
112+
it('Take test-card.png screenshot', { retries: 0 }, function() {
103113
cy.compareSnapshot('image')
104114
})
105115

106116
it('Close and open image again', function() {
107117
cy.get('body > .viewer button.header-close').click()
108118
cy.get('body > .viewer').should('not.exist')
119+
120+
// No need to intercept the request again, it's cached
109121
cy.openFile('test-card.png')
122+
110123
cy.get('body > .viewer').should('be.visible')
111124
cy.get('body > .viewer .modal-header__name').should('contain', 'test-card.png')
112125
cy.get('body > .viewer .modal-container img').should('have.length', 1)
@@ -122,7 +135,7 @@ describe('Visual regression tests ', function() {
122135
.and('not.have.class', 'icon-loading')
123136
})
124137

125-
it('Take test-card.png screenshot 2', function() {
138+
it('Take test-card.png screenshot 2', { retries: 0 }, function() {
126139
cy.compareSnapshot('image2')
127140
})
128141

@@ -136,13 +149,14 @@ describe('Visual regression tests ', function() {
136149
hasPreview: false,
137150
fileid: 123,
138151
}
139-
152+
cy.intercept('GET', '/core/img/favicon.png').as('favicon')
140153
cy.window().then((win) => {
141154
win.OCA.Viewer.open({
142155
fileInfo,
143156
list: [fileInfo],
144157
})
145158
})
159+
cy.wait('@favicon')
146160

147161
cy.get('body > .viewer .modal-container img').should('have.length', 1)
148162
cy.get('body > .viewer .modal-container img').should('have.attr', 'src')
@@ -157,7 +171,7 @@ describe('Visual regression tests ', function() {
157171
.and('not.have.class', 'icon-loading')
158172
})
159173

160-
it('Take non-dav logo.png screenshot', function() {
174+
it('Take non-dav logo.png screenshot', { retries: 0 }, function() {
161175
cy.compareSnapshot('non-dav')
162176
})
163177
})

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@
3636
"cypress": "npm run cypress:e2e",
3737
"cypress:e2e": "cypress run --e2e",
3838
"cypress:gui": "cypress open --e2e",
39-
"cypress:pre-snapshots": "TESTING=true npm run dev",
40-
"cypress:visual-regression": "npm run cypress:pre-snapshots && cypress run --spec cypress/e2e/visual-regression.cy.ts",
41-
"cypress:update-snapshots": "npm run cypress:pre-snapshots && cypress run --env visualRegressionType=base --spec cypress/e2e/visual-regression.cy.ts --config screenshotsFolder=cypress/snapshots/base"
39+
"cypress:visual-regression": "cypress run --spec cypress/e2e/visual-regression.cy.ts",
40+
"cypress:update-snapshots": "cypress run --env visualRegressionType=base --spec cypress/e2e/visual-regression.cy.ts --config screenshotsFolder=cypress/snapshots/base"
4241
},
4342
"dependencies": {
4443
"@fontsource/roboto": "^5.0.14",

src/components/Videos.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export default {
136136
beforeDestroy() {
137137
// Force stop any ongoing request
138138
logger.debug('Closing video stream', { filename: this.filename })
139-
this.$refs.video.pause()
139+
this.$refs.video?.pause?.()
140140
this.player.stop()
141141
this.player.destroy()
142142
},

src/main.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,18 @@
1919
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
*
2121
*/
22+
import { translate as t } from '@nextcloud/l10n'
2223
import Vue from 'vue'
24+
2325
import ViewerComponent from './views/Viewer.vue'
2426
import ViewerService from './services/Viewer.js'
25-
import { translate as t } from '@nextcloud/l10n'
2627

2728
Vue.mixin({
2829
methods: {
2930
t,
3031
},
3132
})
3233

33-
// Inject proper font for cypress visual regression testing
34-
// eslint-disable-next-line no-unused-expressions
35-
INJECT_CYPRESS_FONT
36-
3734
Vue.prototype.OC = window.OC
3835
Vue.prototype.OCA = window.OCA
3936

src/views/Viewer.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,13 @@ export default {
588588
OCA.Files.Sidebar.setFullScreenMode(true)
589589
}
590590
this.sortingConfig = await getSortingConfig()
591+
592+
// Load Roboto font for visual regression tests
593+
if (window.loadRoboto) {
594+
logger.debug('⚠️ Loading roboto font for visual regression tests')
595+
import('@fontsource/roboto/index.css')
596+
delete window.loadRoboto
597+
}
591598
},
592599
593600
/**

vite.config.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ import { createAppConfig } from '@nextcloud/vite-config'
22
import { readFileSync } from 'node:fs'
33
import { join } from 'node:path'
44

5-
const isTesting = !!process.env.TESTING
5+
const isProduction = process.env.NODE_ENV === 'production'
66
const plyrIcons = readFileSync(join(__dirname, 'node_modules', 'plyr', 'dist', 'plyr.svg'), { encoding: 'utf8' })
77

88
export default createAppConfig({
99
main: 'src/main.js',
1010
}, {
1111
replace: {
1212
PLYR_ICONS: JSON.stringify(plyrIcons),
13-
INJECT_CYPRESS_FONT: isTesting ? '; import("@fontsource/roboto");' : '',
1413
},
15-
minify: false,
14+
minify: isProduction,
1615
})

0 commit comments

Comments
 (0)