want to use cli to do unit testing under the project
There are no configuration files under the project, only files like entry and xxx.test.js
. I want to execute cli test
in the root directory of the project and run the test unit with the configuration in cli instead of writing the test configuration again in the project
went to see create-react-app
and the larger cli project, but I didn"t know where to come from.
all I can think of now is that when I execute test, I copy the configuration file to the project and add it to ignore, but I don"t feel very comfortable.
related codes
-sharp!/usr/bin/env node
const { spawn } = require("child_process");
const path = require("path");
function runCmd(cmd, args, callback) {
args = args || [];
const ls = spawn(cmd, args, {
// keep color
stdio: "inherit",
});
ls.on("close", code => {
callback && callback(code);
});
}
// jest --config jest.js --verbose=false
const jestBin = require.resolve("jest/bin/jest");
// cwd cli
// __dirname
const jestConfig = path.join(process.cwd(), "/scripts/jest.js");
const args = [
jestBin,
"--config",
jestConfig,
"--verbose=false",
];
runCmd("node", args);
the command you want to execute here is jest-- config jest.js-- verbose=false
want to give a thought or keyword