karatelabs/karate-npm

CLI parameter for threads is not recognized

steve1337 opened this issue · 8 comments

Problem

I'm trying to configure karate to run scenarios in parallel but the cli options are not recongized

To reproduce

#! /usr/bin/env node
const karate = require("@karatelabs/karate")

karate.config.dir = "./testIntegration"
karate.exec("-T=5")

I also tried

  • -T 5
  • --threads=5
  • --threads 5

Output

using jbang:  -Dkarate.config.dir=./testIntegration com.intuit.karate:karate-core:LATEST:all -T=5
20:23:10.945 [main]  INFO  com.intuit.karate - Karate version: 1.3.0.RC2
Usage: <main class> [-CDhsSW] [-B[=<backupReportDir>]] [-d[=<debugPort>]]
                    [--debug-keepalive[=<keepDebugServerAlive>]] [-c=<cert>]
                    [-e=<env>] [-g=<configDir>] [-j=<jobServerUrl>] [-k=<key>]
                    [-n=<name>] [-o=<output>] [-p=<port>] [-P=<prefix>]
                    [-T=<threads>] [-w=<workingDir>] [-f=<formats>[,
                    <formats>...]]... [-H=<hookFactoryClassNames>[,
                    <hookFactoryClassNames>...]]... [-m=<mocks>[,
                    <mocks>...]]... [-t=<tags>]... [<paths>[($|,)<paths>...]...]
      [<paths>[($|,)<paths>...]...]
                            one or more tests (features) or search-paths to run
  -B, --backup-reportdir[=<backupReportDir>]
                            backup report directory before running tests
  -c, --cert=<cert>         ssl certificate (default: cert.pem)
  -C, --clean               clean output directory
  -d, --debug[=<debugPort>] debug mode (optional port else dynamically chosen)
  -D, --dryrun              dry run, generate html reports only
      --debug-keepalive[=<keepDebugServerAlive>]
                            keep debug server open for connections after
                              disconnect
  -e, --env=<env>           value of 'karate.env'
  -f, --format=<formats>[,<formats>...]
                            comma separate report output formats. tilde
                              excludes the output report. html report is
                              included by default unless it's negated.e.g. '-f
                              ~html,cucumber:json,junit:xml' - possible values
                              [html: Karate HTML, cucumber:json: Cucumber JSON,
                              junit:xml: JUnit XML]
  -g, --configdir=<configDir>
                            directory where 'karate-config.js' is expected
                              (default 'classpath:' or <workingdir>)
  -h, --help                display this help message
  -H, --hook=<hookFactoryClassNames>[,<hookFactoryClassNames>...]
                            class name of a RuntimeHook (or RuntimeHookFactory)
                              to add
  -j, --jobserver=<jobServerUrl>
                            job server url
  -k, --key=<key>           ssl private key (default: key.pem)
  -m, --mock, --mocks=<mocks>[,<mocks>...]
                            one or more mock server files
  -n, --name=<name>         scenario name
  -o, --output=<output>     directory where logs and reports are output
                              (default 'target')
  -p, --port=<port>         server port (default 8080)
  -P, --prefix=<prefix>     mock server path prefix (context-path)
  -s, --ssl                 use ssl / https, will use 'cert.pem' and 'key.pem'
                              if they exist in the working directory, or
                              generate them
  -S, --serve               app server using --workdir (experimental)
  -t, --tags=<tags>         cucumber tags - e.g. '@smoke,~@skipme' [@ignore is
                              always skipped by default]
  -T, --threads=<threads>   number of threads when running tests
  -w, --workdir=<workingDir>
                            working directory, defaults to '.'
  -W, --watch               watch (and hot-reload) mock server file for changes

Expected

Karate runs tests in parallel

not sure if we will get to this soon, as we don't see too many people using this. contributions welcome

I suggest trying to put a path or feature name as the last argument, e.g. karate.exec("-T=5 /some/dir")

note that the alternative to the NPM option is to install the JRE and the stand-alone JAR

@ptrthomas

Wow great hint. This does in fact fix it. I'll open an MR later.

Edit: Actually I don't need an MR because this works

#! /usr/bin/env node
const karate = require("@karatelabs/karate")

karate.config.dir = "./testIntegration"
karate.exec(`-T=5 ${process.argv.slice(2).join(' ')}`)

I could open an MR like this OR just add the example above to the docs what do you think?

karate.exec = function (args) {
	args = (!args ? '' : args + ' ') + process.argv.slice(2).join(' ');

	process.env['KARATE_META'] = 'npm:' + process.env.npm_package_version;
	jbang.exec(karate.executable() + ' ' + args);
};

This would make sure that paths from npm are always passed through as the last option but also allows to define CLI params .

FYI I'm stating my tests via NPM like this

{
    "scripts": {
        "test-integration": "cross-env NODE_ENV=test node ./testIntegration/karate-runner.js ./testIntegration/tests",
        "test-integration:one": "cross-env NODE_ENV=test node ./testIntegration/karate-runner.js",
    }
}

@steve1337 great to hear that. yes I'm ok to accept a PR for the changes you propose.

@ptrthomas finally opened that overdue PR.

Looking forward to some feedback

@steve1337 I merged one and the other has merge conflicts. so I'm confused, do you mind re-doing the second PR that's still open. or should I have merged only one ?

@ptrthomas I'll resolve the merge conflicts later :)

@steve1337 hey no worries take your time

@steve1337 just released 0.2.3