I used @ALDRIN P VINCENT answer to solve this problem. But if you need to pass command line arguments to the npm script, you can do this:
Suppose the following system properties are passed to the gradle script
gradle test-Dsome1=dev -Dsome2=https://www.google.com
In your test script in build.gradle you will do this:
task apifunctionaltest(type: Exec) { String npm = 'npm'; if (Os.isFamily(Os.FAMILY_WINDOWS)) { npm = 'npm.cmd' } commandLine npm, 'run', 'test', '--', '--some1='+System.getProperty("some1"), '--some2='+System.getProperty("some2")
}
The main command begins with commandLine npm ... This line corresponds to:
npm run test -- --some1=dev --some2=https://www.google.com
The test script in package.json must also have the command 'npm install (depends) so that the node modules are installed before running the tests. And if the modules are already installed, the node will not waste time and reinstall them. The test script should look something like this:
"scripts": { "test": "npm install && webpack" }
And then you can select these command line arguments through process.argv[2] and process.argv[3] .
If you have a simple script like mine, then some1 and some2 will be in the 2nd and 3rd positions of the array, respectively.
source share