Skip to content

Commit

Permalink
fix: fail resolve DIContainer when the value is null.
Browse files Browse the repository at this point in the history
  • Loading branch information
ytetsuro committed Nov 12, 2023
1 parent 25c5e84 commit 1cab566
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
28 changes: 16 additions & 12 deletions src/Reporter/JSON/MetricsCalculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,32 @@ export class MetricsCalculator {
.toNumber();
}

max<T extends MetricsValue>(identity: MetricsValueConstructor<T>): Metrics {
max<T extends MetricsValue>(identity: MetricsValueConstructor<T>): Metrics | null {
return (
this.metrics
.filter((metrics) => metrics.hasMetricsValue(identity))
.reduce((max, metrics) =>
Number(max?.getMetricsByMetricsValue(identity) ?? -Infinity) >
Number(metrics.getMetricsByMetricsValue(identity))
? max
: metrics
.reduce(
(max, metrics) =>
Number(max?.getMetricsByMetricsValue(identity) ?? -Infinity) >
Number(metrics.getMetricsByMetricsValue(identity))
? max
: metrics,
<Metrics | null>null
) ?? null
);
}

min<T extends MetricsValue>(identity: MetricsValueConstructor<T>): Metrics {
min<T extends MetricsValue>(identity: MetricsValueConstructor<T>): Metrics | null {
return (
this.metrics
.filter((metrics) => metrics.hasMetricsValue(identity))
.reduce((min, metrics) =>
Number(min?.getMetricsByMetricsValue(identity) ?? Infinity) <
Number(metrics.getMetricsByMetricsValue(identity))
? min
: metrics
.reduce(
(min, metrics) =>
Number(min?.getMetricsByMetricsValue(identity) ?? Infinity) <
Number(metrics.getMetricsByMetricsValue(identity))
? min
: metrics,
<Metrics | null>null
) ?? null
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Fo r HTML or CSV, specify the directory, and for JSON, specify the file.`

const rootPath = fs.statSync(analyzedTarget).isDirectory() ? analyzedTarget : dirname(analyzedTarget);
container.rebind<string>(Types.rootPath).toConstantValue(rootPath);
container.rebind<string | null>(Types.outputPath).toConstantValue(outputPath);
container.rebind<string | null>(Types.outputPath).toConstantValue(outputPath ?? '');
container.rebind<RegExp>(Types.fileMatches).toConstantValue(matches);
container.rebind<RegExp[]>(Types.fileExcludes).toConstantValue(excludes);

Expand Down

0 comments on commit 1cab566

Please sign in to comment.