Skip to content

Commit 7dd11fb

Browse files
authored
fix(tools): fix wc-dev test command (#12662)
The command was migrated to use "ui5nps-script" in #12352 but the test-runner script is missing the pattern to export a `_ui5mainFn`.
1 parent 984f829 commit 7dd11fb

File tree

1 file changed

+56
-48
lines changed

1 file changed

+56
-48
lines changed

packages/tools/lib/test-runner/test-runner.js

Lines changed: 56 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,69 +3,77 @@ const { readFileSync } = require("fs");
33
const path = require("path");
44
const fs = require("fs");
55

6-
// search for dev-server port
6+
function testFn() {
7+
// search for dev-server port
78
// start in current folder
89
// traversing upwards in case of mono repo tests and dev-server running in root folder of repository
9-
let devServerFolder = process.cwd();
10-
let devServerPort;
11-
while (true) {
12-
try {
13-
devServerPort = readFileSync(path.join(devServerFolder, ".dev-server-port")).toString();
14-
break; // found
15-
} catch (e) {
16-
// file not found
17-
if (devServerFolder === path.dirname(devServerFolder)) {
18-
break; // reached root folder "/"
19-
}
20-
devServerFolder = path.dirname(devServerFolder);
21-
}
22-
}
10+
let devServerFolder = process.cwd();
11+
let devServerPort;
12+
while (true) {
13+
try {
14+
devServerPort = readFileSync(path.join(devServerFolder, ".dev-server-port")).toString();
15+
break; // found
16+
} catch (e) {
17+
// file not found
18+
if (devServerFolder === path.dirname(devServerFolder)) {
19+
break; // reached root folder "/"
20+
}
21+
devServerFolder = path.dirname(devServerFolder);
22+
}
23+
}
2324

2425
// check if we are in a monorepo and extract path from package.json
25-
let packageRepositoryPath = "";
26-
const pkg = require(path.join(process.cwd(), "package.json"));
27-
packageRepositoryPath = pkg.repository ? pkg.repository.directory : "";
26+
let packageRepositoryPath = "";
27+
const pkg = require(path.join(process.cwd(), "package.json"));
28+
packageRepositoryPath = pkg.repository ? pkg.repository.directory : "";
2829

2930
// construct base url
3031
// use devServerPort if a dev server is running, otherwise let the baseUrl in the wdio config be used
3132
// if a dev server is running in the root of a mono repo, append tha package path like this
3233
// http://localhost:${devServerPort}/packages/main/
33-
let baseUrl = "";
34-
if (devServerPort) {
35-
console.log(`Found port ${devServerPort} from '${path.join(devServerFolder, ".dev-server-port")}'`);
36-
const devServerInRoot = !devServerFolder.includes(packageRepositoryPath);
37-
if (devServerInRoot) {
38-
baseUrl = `--base-url http://localhost:${devServerPort}/${packageRepositoryPath}/`;
39-
} else {
40-
baseUrl = `--base-url http://localhost:${devServerPort}/`;
41-
}
42-
}
34+
let baseUrl = "";
35+
if (devServerPort) {
36+
console.log(`Found port ${devServerPort} from '${path.join(devServerFolder, ".dev-server-port")}'`);
37+
const devServerInRoot = !devServerFolder.includes(packageRepositoryPath);
38+
if (devServerInRoot) {
39+
baseUrl = `--base-url http://localhost:${devServerPort}/${packageRepositoryPath}/`;
40+
} else {
41+
baseUrl = `--base-url http://localhost:${devServerPort}/`;
42+
}
43+
}
4344

44-
if (!baseUrl) {
45-
console.log("No dev server running, running tests served from `dist`, make sure it is up to date");
46-
}
45+
if (!baseUrl) {
46+
console.log("No dev server running, running tests served from `dist`, make sure it is up to date");
47+
}
4748

4849
// add single spec parameter if passed
49-
let spec = "";
50-
if (process.argv.length === 3) {
51-
const specFile = process.argv[2];
52-
spec = `--spec ${specFile}`;
53-
}
50+
let spec = "";
51+
if (process.argv.length === 3) {
52+
const specFile = process.argv[2];
53+
spec = `--spec ${specFile}`;
54+
}
5455

5556
// more parameters - pass them to wdio
56-
let restParams = "";
57-
if (process.argv.length > 3) {
58-
restParams = process.argv.slice(2).join(" ");
57+
let restParams = "";
58+
if (process.argv.length > 3) {
59+
restParams = process.argv.slice(2).join(" ");
60+
}
61+
62+
let wdioConfig = "";
63+
if (fs.existsSync("config/wdio.conf.cjs")) {
64+
wdioConfig = "config/wdio.conf.cjs";
65+
} else if (fs.existsSync("config/wdio.conf.js")) {
66+
wdioConfig = "config/wdio.conf.js";
67+
}
68+
69+
// run wdio with calculated parameters
70+
const cmd = `yarn cross-env WDIO_LOG_LEVEL=error wdio ${wdioConfig} ${spec} ${baseUrl} ${restParams}`;
71+
console.log(`executing: ${cmd}`);
72+
child_process.execSync(cmd, {stdio: 'inherit'});
5973
}
6074

61-
let wdioConfig = "";
62-
if (fs.existsSync("config/wdio.conf.cjs")) {
63-
wdioConfig = "config/wdio.conf.cjs";
64-
} else if (fs.existsSync("config/wdio.conf.js")) {
65-
wdioConfig = "config/wdio.conf.js";
75+
if (require.main === module) {
76+
testFn(process.argv)
6677
}
6778

68-
// run wdio with calculated parameters
69-
const cmd = `yarn cross-env WDIO_LOG_LEVEL=error wdio ${wdioConfig} ${spec} ${baseUrl} ${restParams}`;
70-
console.log(`executing: ${cmd}`);
71-
child_process.execSync(cmd, {stdio: 'inherit'});
79+
exports._ui5mainFn = testFn;

0 commit comments

Comments
 (0)