@procore/core-scripts
Version:
A CLI to enhance your development experience
94 lines • 3.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const command_1 = require("@oclif/command");
const jest = tslib_1.__importStar(require("jest-cli"));
const BaseCommand_1 = require("../BaseCommand");
const config_1 = require("../jest/config");
class TestCommand extends BaseCommand_1.BaseCommand {
constructor() {
super(...arguments);
this.env = 'test';
}
async run() {
// eslint-disable-next-line no-shadow
const { flags, argv } = this.parse(TestCommand);
const config = flags.config ? flags.config : this.getConfig();
argv.push('--config', config);
if (this.isCI) {
argv.push('--ci');
if (this.isCoverageCommand(argv) && !this.isThreadOptionSet(argv)) {
this.debug('Running Coverage Command In CI with --maxWorkers=1');
argv.push('--maxWorkers=1');
}
}
jest.run(argv);
}
isCoverageCommand(args) {
const coverageFlags = ['--coverage', '--collectCoverage'];
return args.some((arg) => coverageFlags.includes(arg));
}
isThreadOptionSet(args) {
const threadFlags = [
'-w',
'--w',
'--maxWorkers',
'-i',
'--i',
'--runInBand',
];
return args.some((arg) => threadFlags.includes(arg));
}
getConfig() {
const jestConfig = this.getJestConfig();
const config = this.workspace.procoreConfig.jestOverride
? this.workspace.procoreConfig.jestOverride(jestConfig)
: jestConfig;
return JSON.stringify(config);
}
getJestConfig() {
return this.findReactDependency()
? this.getReactConfig()
: this.getDefaultConfig();
}
findReactDependency() {
var _a, _b;
return (
// eslint-disable-next-line no-prototype-builtins
((_a = this.workspace.packageJson.dependencies) === null || _a === void 0 ? void 0 : _a.hasOwnProperty('react')) ||
(
// eslint-disable-next-line no-prototype-builtins
(_b = this.workspace.packageJson.devDependencies) === null || _b === void 0 ? void 0 : _b.hasOwnProperty('react')));
}
getDefaultConfig() {
this.debug('Using Default Preset.');
return (0, config_1.jestConfigFactory)(this.workspace, {
transformAssets: false,
});
}
getReactConfig() {
this.debug('Using React Preset.');
return (0, config_1.jestConfigFactory)(this.workspace, {
environment: config_1.JestEnvironments.browser,
react: {
svg: true,
},
transformAssets: true,
});
}
}
TestCommand.description = [
'Runs Jest. Visit https://jestjs.io/docs/en/cli for more information about',
'available options, only --config is documented.',
].join(' ');
TestCommand.flags = {
config: command_1.flags.string({
description: [
'The path to a Jest config file specifying how to find and',
'execute tests.',
].join(' '),
}),
};
TestCommand.strict = false;
exports.default = TestCommand;
//# sourceMappingURL=test.js.map