How to use mocha-remote-server - 3 common examples

To help you get started, weโ€™ve selected a few mocha-remote-server examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github realm / realm-js / integration-tests / environments / react-native / harness / runner.js View on Github external
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);
github realm / realm-js / integration-tests / environments / react-native / harness / runner.js View on Github external
// 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);
        }
    });

    if (platform === "android") {
        const devices = android.adb.devices();
        const activeDevices = devices.filter(({ state }) => state === "device");
        if (activeDevices.length === 0) {
            throw new Error("Missing an active device: Attach a device via USB or start an emulator");
        } else {
            // Ensure the device can access the mocha remote server
            android.adb.reverseServerPort(MochaRemoteServer.DEFAULT_CONFIG.port);
        }
        // Ask React Native to run the android app
        rn.sync("run-android", "--no-packager");
    } else if (platform === "ios") {
        const deviceName = "realm-js-integration-tests";
        ensureSimulator(deviceName, 'com.apple.CoreSimulator.SimDeviceType.iPhone-11');
        console.log("Simulator is ready ๐Ÿš€");
        // Ask React Native to run the ios app
        rn.sync("run-ios", "--no-packager", "--simulator", deviceName);
    } else {
        throw new Error(`Unexpected platform: '${platform}'`);
    }

    // Run tests with a 5 minute timeout
    return timeout(new Promise((resolve) => {
        console.log("Running tests ๐Ÿƒโ€โ™‚๏ธ");
github realm / realm-js / integration-tests / environments / electron / runner.js View on Github external
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)

mocha-remote-server

Run Mocha tests somewhere - get reporting elsewhere

ISC
Latest version published 1 month ago

Package Health Score

70 / 100
Full package analysis