-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcypress.config.ts
65 lines (61 loc) · 2.51 KB
/
cypress.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { defineConfig } from 'cypress';
// eslint-disable-next-line n/no-missing-import
import { mwApiCommands } from './cypress/support/MwApiPlugin';
// eslint-disable-next-line n/no-missing-import
import LocalSettingsSetup from './cypress/support/LocalSettingsSetup';
import * as installCypressLogsPrinter from 'cypress-terminal-report/src/installLogsPrinter';
import * as childProcess from 'child_process';
const envLogDir = process.env.LOG_DIR ? process.env.LOG_DIR + '/GrowthExperiments' : null;
if ( process.env.MW_SERVER === undefined || process.env.MW_SCRIPT_PATH === undefined ||
process.env.MEDIAWIKI_USER === undefined || process.env.MEDIAWIKI_PASSWORD === undefined ) {
throw new Error( 'Please define MW_SERVER, MW_SCRIPT_PATH, ' +
'MEDIAWIKI_USER and MEDIAWIKI_PASSWORD environment variables' );
}
process.env.REST_BASE_URL = process.env.MW_SERVER + process.env.MW_SCRIPT_PATH + '/';
export default defineConfig( {
e2e: {
supportFile: 'cypress/support/e2e.ts',
baseUrl: process.env.MW_SERVER + process.env.MW_SCRIPT_PATH,
env: {
mediawikiAdminUsername: process.env.MEDIAWIKI_USER,
mediawikiAdminPassword: process.env.MEDIAWIKI_PASSWORD,
},
setupNodeEvents( on, config ) {
installCypressLogsPrinter( on );
on( 'task', {
...mwApiCommands( config ),
} );
on( 'before:run', async () => {
LocalSettingsSetup.overrideLocalSettings();
await LocalSettingsSetup.restartPhpFpmService();
const ip = process.env.MW_INSTALL_PATH || '../..';
const command = process.env.MW_MAINTENANCE_COMMAND || 'php';
const maintScriptRunnerArgs = process.env.MW_MAINTENANCE_ARGS ? process.env.MW_MAINTENANCE_ARGS.split( ' ' ) : [ 'maintenance/run.php' ];
const maintScriptResult = childProcess.spawnSync(
command,
[
...maintScriptRunnerArgs,
'GrowthExperiments:PrepareBrowserTests',
],
{ cwd: ip },
);
console.log( 'stdout:' );
console.log( String( maintScriptResult.stdout ) );
console.log( 'stderr:' );
console.log( String( maintScriptResult.stderr ) );
if ( maintScriptResult.status !== 0 ) {
throw new Error( 'unable to run the maintenance script setting up the browser tests' );
}
} );
on( 'after:run', async () => {
LocalSettingsSetup.restoreLocalSettings();
await LocalSettingsSetup.restartPhpFpmService();
} );
},
defaultCommandTimeout: 20000,
},
screenshotsFolder: envLogDir || 'cypress/screenshots',
videosFolder: envLogDir || 'cypress/videos',
video: true,
downloadsFolder: envLogDir || 'cypress/downloads',
} );