Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function runApp(platform, junitFilePath) {
const mochaConfig = {};
// Check if an argument for junit path was requested
if (junitFilePath) {
mochaConfig.reporter = "mocha-junit-reporter";
mochaConfig.reporterOptions = {
mochaFile: junitFilePath,
};
}
const server = new MochaRemoteServer(mochaConfig, {
// Accept connections only from the expected platform, to prevent cross-talk when both emulators are open
id: platform,
});
await server.start();
// Spawn a react-native metro server
const metro = rn.async("start", /*"--verbose", "--reset-cache"*/);
// Kill metro when the process is killed
process.on("exit", (code) => {
metro.kill("SIGHUP");
});
// Close the runner if metro closes unexpectedly
metro.on("close", (code) => {
if (code !== 0) {
console.error(`Metro server unexpectedly closed (code = ${code})`);
process.exit(code);
const processType = process.argv[2];
if (processType !== "main" && processType !== "renderer") {
throw Error("You need to call this with a runtime argument specifying the process type");
}
// Check if an argument for junit path was requested
const junitFilePath = process.argv[3];
if (junitFilePath) {
mochaConfig.reporter = "mocha-junit-reporter";
mochaConfig.reporterOptions = {
mochaFile: junitFilePath,
};
}
// Start the mocha remote server
const server = new MochaRemoteServer(mochaConfig, {
id: processType,
// Listing on all interfaces
host: "0.0.0.0",
port: 0,
});
await server.start();
// Spawn the electron process
const appProcess = runElectron(processType, server.getUrl());
console.log(`Started the Electron app (pid = ${appProcess.pid})`);
try {
await new Promise((resolve, reject) => {
// Succeed after the tests has run
server.run(resolve);
// Fail if the electron app closes (before the mocha tests completes)