Skip to content

Commit 4b26db1

Browse files
Make path for quickstarts apps independent from the current folder in the quickstarts testing automation scripts (#280)
1 parent 8c30741 commit 4b26db1

File tree

2 files changed

+46
-17
lines changed

2 files changed

+46
-17
lines changed

scripts/ui-library-run-playwright-tests.mjs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212

1313
import { exec } from "child_process";
1414
import { select } from "@inquirer/prompts";
15+
import path from "path";
16+
import { fileURLToPath } from "url";
17+
18+
const __filename = fileURLToPath(import.meta.url);
19+
const __dirname = path.dirname(__filename);
20+
21+
const repoRoot = path.resolve(__dirname, "..");
1522

1623
// The options for the user to choose from
1724
const options = [
@@ -30,6 +37,10 @@ const options = [
3037
{ value: "ui-library-quickstart-composites-with-dependency-isolation" },
3138
];
3239

40+
const quickstartFolderPath = (folder) => {
41+
return path.join(repoRoot, folder);
42+
};
43+
3344
// Prompt the user to choose an option
3445
const promptUser = async (installDependencies) => {
3546
const answer = await select({
@@ -50,11 +61,21 @@ const promptUser = async (installDependencies) => {
5061

5162
// The commands for each option
5263
const commands = {
53-
"ui-library-starting-with-chat-stateful": `cd ../ui-library-starting-with-chat-stateful ${appDepsInstall} && npm run test:e2e`,
54-
"ui-library-quickstart-teams-interop-meeting-chat": `cd ../ui-library-quickstart-teams-interop-meeting-chat ${appDepsInstall} && npm run test:e2e`,
55-
"ui-library-filesharing-chat-composite": `cd ../ui-library-filesharing-chat-composite ${appAndAPIDepsInstall} && npm run test:e2e`,
56-
"ui-library-filesharing-ui-components": `cd ../ui-library-filesharing-ui-components ${appAndAPIDepsInstall} && npm run test:e2e`,
57-
"ui-library-quickstart-composites-with-dependency-isolation": `cd ../ui-library-quickstart-composites-with-dependency-isolation ${appDepsInstall} && npm run test:e2e`,
64+
"ui-library-starting-with-chat-stateful": `cd ${quickstartFolderPath(
65+
"ui-library-starting-with-chat-stateful"
66+
)} ${appDepsInstall} && npm run test:e2e`,
67+
"ui-library-quickstart-teams-interop-meeting-chat": `cd ${quickstartFolderPath(
68+
"ui-library-quickstart-teams-interop-meeting-chat"
69+
)} ${appDepsInstall} && npm run test:e2e`,
70+
"ui-library-filesharing-chat-composite": `cd ${quickstartFolderPath(
71+
"ui-library-filesharing-chat-composite"
72+
)} ${appAndAPIDepsInstall} && npm run test:e2e`,
73+
"ui-library-filesharing-ui-components": `cd ${quickstartFolderPath(
74+
"ui-library-filesharing-ui-components"
75+
)} ${appAndAPIDepsInstall} && npm run test:e2e`,
76+
"ui-library-quickstart-composites-with-dependency-isolation": `cd ${quickstartFolderPath(
77+
"ui-library-quickstart-composites-with-dependency-isolation"
78+
)} ${appDepsInstall} && npm run test:e2e`,
5879
};
5980

6081
// Run the command for the selected option

scripts/ui-library-set-variables-values.mjs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,32 @@
88
// Optionally, use `--restore` to restore default values
99

1010
import fs from "fs";
11+
import path from "path";
1112
import readline from "readline";
13+
import { fileURLToPath } from "url";
1214

15+
const __filename = fileURLToPath(import.meta.url);
16+
const __dirname = path.dirname(__filename);
17+
18+
const repoRoot = path.resolve(__dirname, "..");
1319
// List of files to be updated
1420
const filesToUpdate = [
1521
// ui-library-filesharing-chat-composite
16-
"../ui-library-filesharing-chat-composite/api/local.settings.json",
17-
"../ui-library-filesharing-chat-composite/app/src/App.tsx",
22+
"ui-library-filesharing-chat-composite/api/local.settings.json",
23+
"ui-library-filesharing-chat-composite/app/src/App.tsx",
1824

1925
// ui-library-starting-with-chat-stateful
20-
"../ui-library-starting-with-chat-stateful/src/App.tsx",
26+
"ui-library-starting-with-chat-stateful/src/App.tsx",
2127

2228
// ui-library-filesharing-ui-components
23-
"../ui-library-filesharing-ui-components/api/local.settings.json",
24-
"../ui-library-filesharing-ui-components/app/src/App.tsx",
29+
"ui-library-filesharing-ui-components/api/local.settings.json",
30+
"ui-library-filesharing-ui-components/app/src/App.tsx",
2531

2632
// ui-library-quickstart-teams-interop-meeting-chat
27-
"../ui-library-quickstart-teams-interop-meeting-chat/src/App.tsx",
33+
"ui-library-quickstart-teams-interop-meeting-chat/src/App.tsx",
2834

2935
// ui-library-quickstart-composites-with-dependency-isolation
30-
"../ui-library-quickstart-composites-with-dependency-isolation/src/App.tsx",
36+
"ui-library-quickstart-composites-with-dependency-isolation/src/App.tsx",
3137

3238
// Add more file paths as needed
3339
];
@@ -109,9 +115,11 @@ const defaultValues = {
109115

110116
function updateFiles(files, replacements) {
111117
files.forEach((filePath) => {
112-
fs.readFile(filePath, "utf8", (err, data) => {
118+
// Path to the file from the root of the repository
119+
const fullFilePath = path.join(repoRoot, filePath);
120+
fs.readFile(fullFilePath, "utf8", (err, data) => {
113121
if (err) {
114-
console.error(`Error reading file ${filePath}:`, err);
122+
console.error(`Error reading file ${fullFilePath}:`, err);
115123
return;
116124
}
117125
// delete the next line after the update if it's multiLine string
@@ -142,11 +150,11 @@ function updateFiles(files, replacements) {
142150
.filter((line) => line !== "[TO BE REMOVED]")
143151
.join("\n");
144152

145-
fs.writeFile(filePath, updatedContent, "utf8", (err) => {
153+
fs.writeFile(fullFilePath, updatedContent, "utf8", (err) => {
146154
if (err) {
147-
console.error(`Error writing file ${filePath}:`, err);
155+
console.error(`Error writing file ${fullFilePath}:`, err);
148156
} else {
149-
console.log(`File ${filePath} updated successfully.`);
157+
console.log(`File ${fullFilePath} updated successfully.`);
150158
}
151159
});
152160
});

0 commit comments

Comments
 (0)