Skip to content

Commit dc41941

Browse files
authored
chore: enhance cypress test configuration with conditional execution of tools (SAP#11195)
Previously, the Cypress code coverage plugin was used even when a coverage report was not required. Additionally, Cypress accessibility testing (introduced in SAP#11128) is intended to run only when a report is needed and requires an environment variable. This PR introduces new internal flags in the `package-script.cjs` file of each component package, simplifying the process of setting the required environment variables when these features need to be enabled.
1 parent 965df33 commit dc41941

File tree

5 files changed

+38
-7
lines changed

5 files changed

+38
-7
lines changed

packages/ai/package-scripts.cjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ const options = {
66
aiPackage: true,
77
noWatchTS: true,
88
dev: true,
9+
internal: {
10+
cypress_code_coverage: false,
11+
cypress_acc_tests: false,
12+
},
913
};
1014

1115
const scripts = getScripts(options);

packages/cypress-internal/src/commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import "cypress-real-events";
2-
import '@cypress/code-coverage/support'
2+
import '@cypress/code-coverage/support';
33
import "./acc_report/support.js";
44
import "./helpers.js"
55

packages/fiori/package-scripts.cjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ const options = {
1818
dev: true,
1919
fioriPackage: true,
2020
noWatchTS: true,
21+
internal: {
22+
cypress_code_coverage: false,
23+
cypress_acc_tests: false,
24+
},
2125
illustrationsData: [
2226
{
2327
path: "src/illustrations",

packages/main/package-scripts.cjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ const options = {
55
portStep: 2,
66
noWatchTS: true,
77
dev: true,
8+
internal: {
9+
cypress_code_coverage: false,
10+
cypress_acc_tests: false,
11+
},
812
};
913

1014
const scripts = getScripts(options);

packages/tools/components-package/nps.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,25 @@ if (process.env.DEPLOY) {
99
websiteBaseUrl = "/ui5-webcomponents/nightly/";
1010
}
1111

12+
const cypressEnvVariables = (options, predefinedVars) => {
13+
let variables = [];
14+
const { cypress_code_coverage, cypress_acc_tests } = options.internal ?? {};
15+
16+
// Handle environment variables like TEST_SUITE
17+
if (predefinedVars) {
18+
variables = [...predefinedVars];
19+
}
20+
21+
// The coverage task is always registered and requires an explicit variable whether to generate a report or not
22+
variables.push(`CYPRESS_COVERAGE=${!!cypress_code_coverage}`);
23+
24+
if (cypress_acc_tests) {
25+
variables.push("CYPRESS_UI5_ACC=true");
26+
}
27+
28+
return variables.length ? `cross-env ${variables.join(" ")}` : "";
29+
}
30+
1231
const getScripts = (options) => {
1332

1433
// The script creates all JS modules (dist/illustrations/{illustrationName}.js) out of the existing SVGs
@@ -17,7 +36,7 @@ const getScripts = (options) => {
1736
const createIllustrationsJSImportsScript = illustrations.join(" && ");
1837

1938
// The script creates the "src/generated/js-imports/Illustration.js" file that registers loaders (dynamic JS imports) for each illustration
20-
const createIllustrationsLoadersScript = illustrationsData.map(illustrations => `node ${LIB}/generate-js-imports/illustrations.js ${illustrations.destinationPath} ${illustrations.dynamicImports.outputFile} ${illustrations.set} ${illustrations.collection} ${illustrations.dynamicImports.location} ${illustrations.dynamicImports.filterOut.join(" ")}`).join(" && ");
39+
const createIllustrationsLoadersScript = illustrationsData.map(illustrations => `node ${LIB}/generate-js-imports/illustrations.js ${illustrations.destinationPath} ${illustrations.dynamicImports.outputFile} ${illustrations.set} ${illustrations.collection} ${illustrations.dynamicImports.location} ${illustrations.dynamicImports.filterOut.join(" ")}`).join(" && ");
2140

2241
const tsOption = !options.legacy || options.jsx;
2342
const tsCommandOld = tsOption ? "tsc" : "";
@@ -31,7 +50,7 @@ const getScripts = (options) => {
3150
if (tsOption) {
3251
try {
3352
require("typescript");
34-
} catch(e) {
53+
} catch (e) {
3554
console.error(`TypeScript is not found. Try to install it by running \`npm install --save-dev typescript\` if you are using npm or by running \`yarn add --dev typescript\` if you are using yarn.`);
3655
process.exit(e.code);
3756
}
@@ -122,10 +141,10 @@ const getScripts = (options) => {
122141
},
123142
start: "nps prepare watch.devServer",
124143
test: `node "${LIB}/test-runner/test-runner.js"`,
125-
"test-cy-ci": `cross-env CYPRESS_COVERAGE=true yarn cypress run --component --browser chrome`,
126-
"test-cy-ci-suite-1": `cross-env CYPRESS_COVERAGE=true TEST_SUITE=SUITE1 yarn cypress run --component --browser chrome`,
127-
"test-cy-ci-suite-2": `cross-env CYPRESS_COVERAGE=true TEST_SUITE=SUITE2 yarn cypress run --component --browser chrome`,
128-
"test-cy-open": `cross-env CYPRESS_COVERAGE=true yarn cypress open --component --browser chrome`,
144+
"test-cy-ci": `${cypressEnvVariables(options)} yarn cypress run --component --browser chrome`,
145+
"test-cy-ci-suite-1": `${cypressEnvVariables(options, ["TEST_SUITE=SUITE1"])} yarn cypress run --component --browser chrome`,
146+
"test-cy-ci-suite-2": `${cypressEnvVariables(options, ["TEST_SUITE=SUITE2"])} yarn cypress run --component --browser chrome`,
147+
"test-cy-open": `${cypressEnvVariables(options)} yarn cypress open --component --browser chrome`,
129148
"test-suite-1": `node "${LIB}/test-runner/test-runner.js" --suite suite1`,
130149
"test-suite-2": `node "${LIB}/test-runner/test-runner.js" --suite suite2`,
131150
startWithScope: "nps scope.prepare scope.watchWithBundle",

0 commit comments

Comments
 (0)