最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - How to debug tests with yarn - Stack Overflow

matteradmin6PV0评论

I have a number of UI tests written in javascript (using selenium and cucumber). Currently I am running tests as follows:

yarn run loginTest

Is there a mand for debugging the test?

Update: Below is a snapshot of my package.json that includes the loginTest script reference:

"scripts": {
    "loginTest": "node ./scripts/loginTest.js"
    ....
},

The loginTest.js file is shown below:

const chalk = require('chalk');
const path = require('path');
const fs = require('fs-extra');
const cp = require('child_process');

const srcPath = './projects/';

const projects = fs.readdirSync(srcPath)
    .filter(file => fs.lstatSync(path.join(srcPath, file)).isDirectory())
    .filter(file => file !== 'mons');

process.env.HOST = process.argv.slice(2)[0] || 'localhost';

console.log(chalk.magenta('Carrying out integration tests against: ') + process.env.HOST);

projects.forEach((project) => {
    if (fs.existsSync(`./projects/${project}/login-tests/features/`)) {
        console.log(chalk.yellow('Starting integration tests for: ') + project);
        cp.fork(__dirname + '/runtime/pickle.js',
            [
                '-f', `./projects/${project}/login-tests/features/`,
                '-s', `./projects/${project}/login-tests/step-definitions/`,
                '-p', `./projects/${project}/login-tests/page-objects/`,
                '-r', `./build/reports/${project}`
            ]);
    }
});

The pickle.js file that was referenced above is shown here:

#!/usr/bin / env node

'use strict';

const fs = require('fs-plus');
const path = require('path');
const program = require('mander');
const cucumber = require('cucumber');

function collectPaths(value, paths) {
    paths.push(value);
    return paths;
}

function coerceInt(value, defaultValue) {
    const int = parseInt(value);
    if (typeof int === 'number') return int;
    return defaultValue;
}

let config = {
    steps: './step-definitions',
    pageObjects: './page-objects',
    sharedObjects: './shared-objects',
    reports: './reports',
    browser: 'chrome',
    timeout: 15000
};

const configFileName = path.resolve(process.cwd(), 'selenium-cucumber-js.json');

if (fs.isFileSync(configFileName)) {
    config = Object.assign(config, require(configFileName));
}

program
    .option('-s, --steps <path>', 'path to step definitions. defaults to ' + config.steps, config.steps)
    .option('-p, --pageObjects <path>', 'path to page objects. defaults to ' + config.pageObjects, config.pageObjects)
    .option('-o, --sharedObjects [paths]', 'path to shared objects (repeatable). defaults to ' + config.sharedObjects, collectPaths, [config.sharedObjects])
    .option('-b, --browser <path>', 'name of browser to use. defaults to ' + config.browser, config.browser)
    .option('-r, --reports <path>', 'output path to save reports. defaults to ' + config.reports, config.reports)
    .option('-d, --disableLaunchReport [optional]', 'Disables the auto opening the browser with test report')
    .option('-j, --junit <path>', 'output path to save junit-report.xml defaults to ' + config.reports)
    .option('-t, --tags <tagName>', 'name of tag to run', collectPaths, [])
    .option('-f, --featureFiles <paths>', 'ma-separated list of feature files to run')
    .option('-x, --timeOut <n>', 'steps definition timeout in milliseconds. defaults to ' + config.timeout, coerceInt, config.timeout)
    .option('-n, --noScreenshot [optional]', 'disable auto capturing of screenshots when an error is encountered')
    .parse(process.argv);

program.on('--help', function () {
    console.log('  For more details please visit \n');
});

// store browserName globally (used within world.js to build driver)
global.browserName = program.browser;

// store Eyes Api globally (used within world.js to set Eyes)
global.eyesKey = config.eye_key;

// used within world.js to import page objects
global.pageObjectPath = path.resolve(program.pageObjects);

// used within world.js to output reports
global.reportsPath = path.resolve(program.reports);
if (!fs.existsSync(program.reports)) {
    fs.makeTreeSync(program.reports);
}

// used within world.js to decide if reports should be generated
global.disableLaunchReport = (program.disableLaunchReport);

// used with world.js to determine if a screenshot should be captured on error
global.noScreenshot = (program.noScreenshot);

// used within world.js to output junit reports
global.junitPath = path.resolve(program.junit || program.reports);

// set the default timeout to 10 seconds if not already globally defined or passed via the mand line
global.DEFAULT_TIMEOUT = global.DEFAULT_TIMEOUT || program.timeOut || 10 * 1000;

// used within world.js to import shared objects into the shared namespace
global.sharedObjectPaths = program.sharedObjects.map(function (item) {
    return path.resolve(item);
});

// rewrite mand line switches for cucumber
process.argv.splice(2, 100);

// allow specific feature files to be executed
if (program.featureFiles) {
    var splitFeatureFiles = program.featureFiles.split(',');

    splitFeatureFiles.forEach(function (feature) {
        process.argv.push(feature);
    });
}

// add switch to tell cucumber to produce json report files
process.argv.push('-f');
process.argv.push('pretty');
process.argv.push('-f');
process.argv.push('json:' + path.resolve(__dirname, global.reportsPath, 'cucumber-report.json'));

// add cucumber world as first required script (this sets up the globals)
process.argv.push('-r');
process.argv.push(path.resolve(__dirname, 'world.js'));

// add path to import step definitions
process.argv.push('-r');
process.argv.push(path.resolve(program.steps));

// add tag
if (program.tags) {
    program.tags.forEach(function (tag) {
        process.argv.push('-t');
        process.argv.push(tag);
    });
}

// add strict option (fail if there are any undefined or pending steps)
process.argv.push('-S');

//
// execute cucumber
//
var cucumberCli = cucumber.Cli(process.argv);
global.cucumber = cucumber;
cucumberCli.run(function (succeeded) {

    var code = succeeded ? 0 : 1;

    function exitNow() {
        process.exit(code);
    }

    if (process.stdout.write('')) {
        exitNow();
    } else {
        // write() returned false, kernel buffer is not empty yet...
        process.stdout.on('drain', exitNow);
    }
}); 
Post a comment

comment list (0)

  1. No comments so far