-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added more automation. Updated scripts
- Loading branch information
1 parent
33d27c3
commit 77f4ba2
Showing
22 changed files
with
755 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,92 @@ | ||
// Script to automate testing for various chat UI library samples. | ||
// This script prompts the user to select a project and optionally installs dependencies | ||
// before running end-to-end tests using Playwright. The test will open a browser window and | ||
// run the initial steps for the samples. The user can continue testing in the same window. | ||
// The session is set to be closed after 10 minutes. | ||
// Please make sure to CLOSE the browser tab or window after the test is complete. | ||
// Otherwise, the process will continue running and you might need to kill it manually. | ||
// | ||
// Usage: Change to the scripts directory | ||
// Run `node ui-library-run-playwright-tests.mjs [--install]` | ||
// Optionally, use `--install` to install the dependencies before running the tests. | ||
|
||
import { exec } from "child_process"; | ||
import { select } from "@inquirer/prompts"; | ||
|
||
// Define the options | ||
// The options for the user to choose from | ||
const options = [ | ||
{ | ||
name: "ui-library-starting-with-chat-stateful", | ||
value: "ui-library-starting-with-chat-stateful", | ||
}, | ||
{ | ||
name: "ui-library-quickstart-teams-interop-meeting-chat", | ||
value: "ui-library-quickstart-teams-interop-meeting-chat", | ||
}, | ||
{ | ||
value: "ui-library-filesharing-chat-composite", | ||
}, | ||
{ | ||
value: "ui-library-filesharing-ui-components", | ||
}, | ||
{ value: "ui-library-quickstart-composites-with-dependency-isolation" }, | ||
]; | ||
|
||
// Prompt the user to choose an option | ||
const promptUser = async () => { | ||
const promptUser = async (installDependencies) => { | ||
const answer = await select({ | ||
message: "Choose a quickstart to set up:", | ||
message: | ||
"Choose a quickstart to set up below. You ALWAYS need to close the tab or browser where test is run to finish the test. Otherwise, you will stuck with running process for the app.", | ||
choices: options.map((option) => ({ | ||
name: option.name, | ||
value: option.value, | ||
})), | ||
}); | ||
|
||
const selectedOption = answer; | ||
|
||
// Define the commands for each option | ||
// add dependencies install command based on the user input | ||
const appDepsInstall = installDependencies ? "&& npm install" : ""; | ||
const appAndAPIDepsInstall = installDependencies | ||
? "&& npm install && cd ./app && npm install && cd ../api && npm install && cd .." | ||
: ""; | ||
|
||
// The commands for each option | ||
const commands = { | ||
"ui-library-starting-with-chat-stateful": | ||
"cd ../ui-library-starting-with-chat-stateful && npm run test:e2e", | ||
"ui-library-quickstart-teams-interop-meeting-chat": | ||
"cd ../ui-library-quickstart-teams-interop-meeting-chat && npm run test:e2e", | ||
"ui-library-starting-with-chat-stateful": `cd ../ui-library-starting-with-chat-stateful ${appDepsInstall} && npm run test:e2e`, | ||
"ui-library-quickstart-teams-interop-meeting-chat": `cd ../ui-library-quickstart-teams-interop-meeting-chat ${appDepsInstall} && npm run test:e2e`, | ||
"ui-library-filesharing-chat-composite": `cd ../ui-library-filesharing-chat-composite ${appAndAPIDepsInstall} && npm run test:e2e`, | ||
"ui-library-filesharing-ui-components": `cd ../ui-library-filesharing-ui-components ${appAndAPIDepsInstall} && npm run test:e2e`, | ||
"ui-library-quickstart-composites-with-dependency-isolation": `cd ../ui-library-quickstart-composites-with-dependency-isolation ${appDepsInstall} && npm run test:e2e`, | ||
}; | ||
|
||
// Run the command for the selected option | ||
const command = commands[selectedOption]; | ||
if (command) { | ||
exec(command, (error, stdout, stderr) => { | ||
if (error) { | ||
console.error(`Error executing command: ${error.message}`); | ||
return; | ||
} | ||
if (stderr) { | ||
console.error(`Error output: ${stderr}`); | ||
return; | ||
} | ||
console.log(`Command output: ${stdout}`); | ||
console.log(`Executing command: ${command}`); | ||
const child = exec(command); | ||
|
||
// Capture and log stdout | ||
child.stdout.on("data", (data) => { | ||
console.log(`${data}`); | ||
}); | ||
|
||
// Capture and log stderr | ||
child.stderr.on("data", (data) => { | ||
console.error(`${data}`); | ||
}); | ||
|
||
// Handle command completion | ||
child.on("close", (code) => { | ||
console.log(`Command finished with exit code ${code}`); | ||
}); | ||
} else { | ||
console.error("Invalid option selected."); | ||
} | ||
}; | ||
|
||
// Run the prompt | ||
promptUser().catch((error) => { | ||
console.error(`Error: ${error.message}`); | ||
}); | ||
const runPrompt = async (installDependencies) => { | ||
await promptUser(installDependencies).catch((error) => { | ||
console.error(`Error: ${error.message}`); | ||
}); | ||
}; | ||
|
||
// Check if the script should also install dependencies | ||
runPrompt(process.argv.includes("--install")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.