Skip to content

Commit 4964377

Browse files
committed
Copy how cypress is run on the server
Signed-off-by: Louis Chemineau <[email protected]>
1 parent efa2bf5 commit 4964377

24 files changed

+2182
-1199
lines changed

.github/workflows/cypress.yml

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ on:
1010
env:
1111
APP_NAME: photos
1212
BRANCH: ${{ github.base_ref }}
13-
CYPRESS_baseUrl: http://127.0.0.1:8082/index.php
1413
TESTING: true
1514

1615
jobs:
@@ -25,12 +24,13 @@ jobs:
2524
uses: skjnldsv/[email protected]
2625
id: versions
2726
with:
28-
fallbackNode: '^12'
29-
fallbackNpm: '^6'
27+
fallbackNode: "^12"
28+
fallbackNpm: "^6"
3029

3130
- name: Set up node ${{ steps.versions.outputs.nodeVersion }}
3231
uses: actions/setup-node@v3
3332
with:
33+
cache: "npm"
3434
node-version: ${{ steps.versions.outputs.nodeVersion }}
3535

3636
- name: Set up npm ${{ steps.versions.outputs.npmVersion }}
@@ -55,7 +55,7 @@ jobs:
5555
fail-fast: false
5656
matrix:
5757
# run multiple copies of the current job in parallel
58-
containers: [1, 2, 3, 4, 5, 6, 7, 8]
58+
containers: ["component", 1, 2]
5959

6060
name: runner ${{ matrix.containers }}
6161

@@ -66,13 +66,7 @@ jobs:
6666
key: cypress-context-${{ github.run_id }}
6767
path: /home/runner/work/photos
6868

69-
- name: Setup server
70-
run: |
71-
cd cypress
72-
docker-compose up -d
73-
74-
- name: Wait for server
75-
run: npm run wait-on $CYPRESS_baseUrl
69+
- name: Run ${{ matrix.containers == 'component' && 'component' || 'E2E' }} cypress tests
7670

7771
- name: Enable app & configure server
7872
run: |

cypress.config.js

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

cypress.config.ts

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/* eslint-disable node/no-unpublished-import */
2+
3+
import {
4+
configureNextcloud,
5+
startNextcloud,
6+
stopNextcloud,
7+
waitOnNextcloud,
8+
} from './cypress/dockerNode'
9+
import { defineConfig } from 'cypress'
10+
11+
import browserify from '@cypress/browserify-preprocessor'
12+
13+
export default defineConfig({
14+
projectId: 'okzqgr',
15+
16+
// 16/9 screen ratio
17+
viewportWidth: 1280,
18+
viewportHeight: 720,
19+
20+
// Tries again 2 more times on failure
21+
retries: {
22+
runMode: 2,
23+
// do not retry in `cypress open`
24+
openMode: 0,
25+
},
26+
27+
// Needed to trigger `after:run` events with cypress open
28+
experimentalInteractiveRunEvents: true,
29+
30+
// faster video processing
31+
videoCompression: false,
32+
33+
// Visual regression testing
34+
env: {
35+
failSilently: false,
36+
type: 'actual',
37+
},
38+
39+
screenshotsFolder: 'cypress/snapshots/actual',
40+
trashAssetsBeforeRuns: true,
41+
42+
e2e: {
43+
testIsolation: false,
44+
45+
// We've imported your old cypress plugins here.
46+
// You may want to clean this up later by importing these.
47+
async setupNodeEvents(on, config) {
48+
// Fix browserslist extend https://github.com/cypress-io/cypress/issues/2983#issuecomment-570616682
49+
on('file:preprocessor', browserify({ typescript: require.resolve('typescript') }))
50+
51+
// Disable spell checking to prevent rendering differences
52+
on('before:browser:launch', (browser, launchOptions) => {
53+
if (browser.family === 'chromium' && browser.name !== 'electron') {
54+
launchOptions.preferences.default['browser.enable_spellchecking'] = false
55+
return launchOptions
56+
}
57+
58+
if (browser.family === 'firefox') {
59+
launchOptions.preferences['layout.spellcheckDefault'] = 0
60+
return launchOptions
61+
}
62+
63+
if (browser.name === 'electron') {
64+
launchOptions.preferences.spellcheck = false
65+
return launchOptions
66+
}
67+
})
68+
69+
// Remove container after run
70+
on('after:run', () => {
71+
stopNextcloud()
72+
})
73+
74+
// Before the browser launches
75+
// starting Nextcloud testing container
76+
return startNextcloud(process.env.BRANCH)
77+
.then((ip) => {
78+
// Setting container's IP as base Url
79+
config.baseUrl = `http://${ip}/index.php`
80+
return ip
81+
})
82+
.then(waitOnNextcloud)
83+
.then(configureNextcloud)
84+
.then(() => {
85+
return config
86+
})
87+
},
88+
},
89+
90+
component: {
91+
devServer: {
92+
framework: 'vue',
93+
bundler: 'webpack',
94+
webpackConfig: async () => {
95+
process.env.npm_package_name = 'NcCypress'
96+
process.env.npm_package_version = '1.0.0'
97+
process.env.NODE_ENV = 'development'
98+
99+
/**
100+
* Needed for cypress stubbing
101+
*
102+
* @see https://github.com/sinonjs/sinon/issues/1121
103+
* @see https://github.com/cypress-io/cypress/issues/18662
104+
*/
105+
const babel = require('./babel.config.js')
106+
babel.plugins.push([
107+
'@babel/plugin-transform-modules-commonjs',
108+
{
109+
loose: true,
110+
},
111+
])
112+
113+
const config = require('@nextcloud/webpack-vue-config')
114+
config.module.rules.push({
115+
test: /\.svg$/,
116+
type: 'asset/source',
117+
})
118+
119+
return config
120+
},
121+
},
122+
},
123+
})

0 commit comments

Comments
 (0)