Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace node util isNullOrUndefined with own helper due to deprecation #627

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions src/processor/Config.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,54 @@
import { isNullOrUndefined } from "util";
import { Constants } from "./Constants";
import { IJestStareConfig, PACKAGE_JSON_KEY } from "./doc/IJestStareConfig";
import { EnvVars } from "./EnvVars";
import { Logger } from "../utils/Logger";
import { IProcessParms } from "./doc/IProcessParms";
import { IO } from "../utils/IO";
import { isNullOrUndefined } from "../utils/helpers";

/**
* Configuration for processor
* @export
* @class Config
*/
export class Config {

/**
* Creates an instance of Config.
* @param {IJestStareConfig} mExplicitConfig - explicit configuration
* @memberof Config
*/
constructor(private mLogger: Logger, private mExplicitConfig: IJestStareConfig, private mProcessParms: IProcessParms) { }
constructor(
private mLogger: Logger,
private mExplicitConfig: IJestStareConfig,
private mProcessParms: IProcessParms
) {}

/**
* Build config from explicit config, package.json, and defaults
* @returns {IJestStareConfig} - constructed config
* @memberof Config
*/
public buildConfig(): IJestStareConfig {

// get configuration
const packageJsonConfig = this.getJestStareConfig();

// read environmental variables and merge them with the package.json config (env takes precedence)
const envVars = new EnvVars();
const mergedEnvAndPackageJsonConfig = envVars.resolve(packageJsonConfig, envVars.read());
const mergedEnvAndPackageJsonConfig = envVars.resolve(
packageJsonConfig,
envVars.read()
);

// explicit config takes precedence over env and package.json
const config = this.mExplicitConfig || mergedEnvAndPackageJsonConfig;

// take packagejson options after setting explicit config (concatenate both)
if (this.mExplicitConfig != null) {
Object.keys(mergedEnvAndPackageJsonConfig).forEach((key) => {
if (isNullOrUndefined(this.mExplicitConfig[key]) && !isNullOrUndefined(mergedEnvAndPackageJsonConfig[key])) {
if (
isNullOrUndefined(this.mExplicitConfig[key]) &&
!isNullOrUndefined(mergedEnvAndPackageJsonConfig[key])
) {
config[key] = mergedEnvAndPackageJsonConfig[key];
}
});
Expand All @@ -54,7 +62,6 @@ export class Config {
config.resultDir += "/"; // append an extra slash in case the user didn't add one
}


// suppress logging if requested
// NOTE(Kelosky): must be first, to suppress all logging
if (!isNullOrUndefined(config.log)) {
Expand All @@ -64,7 +71,6 @@ export class Config {
// record if we were invoked programmatically
// NOTE(Kelosky): should be second, to record if override config
if (!isNullOrUndefined(this.mExplicitConfig)) {

// display if not internal invocation
if (this.mProcessParms && this.mProcessParms.reporter) {
// do nothing
Expand All @@ -79,7 +85,8 @@ export class Config {
} else {
if (config.resultHtml.indexOf(Constants.HTML_EXTENSION) === -1) {
// add .html if the user did not specify it
config.resultHtml = config.resultHtml + Constants.HTML_EXTENSION;
config.resultHtml =
config.resultHtml + Constants.HTML_EXTENSION;
}
}

Expand All @@ -90,7 +97,6 @@ export class Config {
return config;
}


/**
* Read from the user's package.json, if present
* @private
Expand All @@ -107,5 +113,4 @@ export class Config {
return packageJsonObject[PACKAGE_JSON_KEY];
}
}

}
Loading