forked from wikimedia/mediawiki-extensions-Wikibase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcypress.config.ts
More file actions
85 lines (80 loc) · 3.13 KB
/
Copy pathcypress.config.ts
File metadata and controls
85 lines (80 loc) · 3.13 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { defineConfig } from 'cypress';
import { unlinkSync } from 'fs';
const envLogDir = process.env.LOG_DIR ? process.env.LOG_DIR + '/Wikibase' : 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 + '/';
import { mwApiCommands } from 'cypress-wikibase-api';
import { clientFactory } from 'api-testing';
const compressedVideoPath = function ( uncompressedPath: string ): string {
const lastDot = uncompressedPath.lastIndexOf( '.' );
const base = uncompressedPath.slice( 0, lastDot );
const ext = uncompressedPath.slice( lastDot );
return base + '-compressed' + ext;
};
export default defineConfig( {
e2e: {
supportFile: 'cypress/support/e2e.ts',
baseUrl: process.env.MW_SERVER + process.env.MW_SCRIPT_PATH,
mediawikiAdminUsername: process.env.MEDIAWIKI_USER,
mediawikiAdminPassword: process.env.MEDIAWIKI_PASSWORD,
wikibasePropertyIds: {
string: process.env.WIKIBASE_PROPERTY_STRING,
},
setupNodeEvents( on, config ) {
on( 'task', {
/* eslint-disable no-console */
log( message ) {
console.log( message );
return null;
},
table( message ) {
console.table( message );
return null;
},
/* eslint-enable */
// TODO: T427277 (follow-up) we might want to add this cypress task implementation to 'cypress-wikibase-api` library and call it from the test directly.
async 'MwApi:DeletePage'( { title }: { title: string } ) {
const client = clientFactory.getActionClient( null );
await client.login( process.env.MEDIAWIKI_USER, process.env.MEDIAWIKI_PASSWORD );
await client.loadTokens( [ 'csrf' ] );
await client.action( 'delete', {
title,
reason: 'Cypress test cleanup',
token: await client.token( 'csrf' ),
}, 'POST' );
return null;
},
// eslint-disable-next-line es-x/no-rest-spread-properties
...mwApiCommands( config ),
} );
on( 'after:spec', ( spec, results ) => {
if ( results && results.video ) {
// Do we have failures for any retry attempts?
const failures = results.tests.some(
( test ) => test.attempts
.some( ( attempt ) => attempt.state === 'failed' ),
);
if ( !failures ) {
// delete the video if the spec passed and no tests retried
// eslint-disable-next-line security/detect-non-literal-fs-filename
unlinkSync( results.video );
// Cypress creates a zero-byte "compressed" video file even if you disable compression.
// Delete that file
// eslint-disable-next-line security/detect-non-literal-fs-filename
unlinkSync( compressedVideoPath( results.video ) );
}
}
} );
},
defaultCommandTimeout: 20000,
},
screenshotsFolder: envLogDir || 'cypress/screenshots',
video: true,
videoCompression: false,
videosFolder: envLogDir || 'cypress/videos',
downloadsFolder: envLogDir || 'cypress/downloads',
} );