-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathutils.js
103 lines (97 loc) · 2.74 KB
/
utils.js
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const BASE_URL = process.env.PIXEL_MW_SERVER;
/**
* @param {Object} featureFlags
* @return {string}
*/
const getFeatureQueryString = ( featureFlags ) => {
return Object.keys( featureFlags )
// @ts-ignore
.map( ( name ) => `${name}=${featureFlags[ name ]}` )
.join( '&' );
};
/**
* @param {string} path
* @return {Object}
*/
const makePaths = ( path ) => {
return {
// eslint-disable-next-line camelcase
bitmaps_reference: `report/reference-screenshots-${path}`,
// eslint-disable-next-line camelcase
bitmaps_test: `report/test-screenshots-${path}`,
// eslint-disable-next-line camelcase
engine_scripts: 'src/engine-scripts',
// eslint-disable-next-line camelcase
html_report: `report/${path}`,
// eslint-disable-next-line camelcase
ci_report: 'report/ci-report-dev',
// eslint-disable-next-line camelcase
json_report: 'report/json-report-dev'
};
};
/**
* @param {string} path
* @return {Object}
*/
const makeA11yPaths = ( path ) => {
return {
// eslint-disable-next-line camelcase
a11y_reference: `report/reference-json-${path}-a11y`,
// eslint-disable-next-line camelcase
a11y_test: `report/test-json-${path}-a11y`,
// eslint-disable-next-line camelcase
a11y_report: `report/${path}-a11y`
};
};
/**
* @param {Object} scenario
* @param {string} scenario.url
* @param {Object} featureFlags
* @return {Object}
*/
const addFeatureFlagQueryStringsToScenario = ( scenario, featureFlags ) => {
const hasQueryString = scenario.url.includes( '?' );
const url = scenario.url;
const qs = getFeatureQueryString( featureFlags );
return Object.assign( {}, scenario, {
url: hasQueryString ? `${url}&${qs}` : `${url}?${qs}`
} );
};
/**
* @typedef {Object} Test
* @property {string} path
* @property {string} [hash]
* @property {Object} [query]
* @property {string[]} [hashtags]
* @property {number} [misMatchThreshold]
* @property {string} label
* @property {string[]} selectors
*
* @param {Test[]} tests
* @param {string[]} skins to test on
* @return {Object[]} scenarios
*/
const makeScenariosForSkins = ( tests, skins ) => {
let /** @type {Object[]} */ scenarios = [];
skins.forEach( ( useskin ) => {
scenarios = scenarios.concat(
tests.map( ( test ) => {
const hashtagString = `${( test.hashtags || [] ).join( ' ' )} #${useskin}`.trim();
const query = Object.assign( {}, test.query, { useskin } );
const qs = Object.keys( query ).length ? `?${getFeatureQueryString( query )}` : '';
const hash = test.hash || '';
return Object.assign( {}, test, {
label: `${test.label} (${hashtagString})`,
url: `${BASE_URL}${test.path}${qs}${hash}`
} );
} )
);
} );
return scenarios;
};
module.exports = {
makeScenariosForSkins,
makePaths,
makeA11yPaths,
addFeatureFlagQueryStringsToScenario
};