Skip to content

Commit

Permalink
Merge pull request #36223 from VickyStash/ts-migration/format-test
Browse files Browse the repository at this point in the history
[No QA] [TS migration] Migrate 'format.js' test to TypeScript
  • Loading branch information
robertjchen authored Mar 4, 2024
2 parents 22cb01c + 77d1ffb commit cb45bb2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
8 changes: 8 additions & 0 deletions tests/e2e/compare/output/console.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import type {Stats} from '../../measure/math';
import * as format from './format';

type Entry = {
name: string;
baseline: Stats;
current: Stats;
diff: number;
relativeDurationDiff: number;
isDurationDiffOfSignificance: boolean;
};

type Data = {
Expand Down Expand Up @@ -29,3 +35,5 @@ export default (data: Data) => {

console.debug('');
};

export type {Entry};
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
* Utility for formatting text for result outputs.
* from: https://github.com/callstack/reassure/blob/main/packages/reassure-compare/src/utils/format.ts
*/
import type {Entry} from './console';

const formatPercent = (value) => {
const formatPercent = (value: number): string => {
const valueAsPercent = value * 100;
return `${valueAsPercent.toFixed(1)}%`;
};

const formatPercentChange = (value) => {
const formatPercentChange = (value: number): string => {
const absValue = Math.abs(value);

// Round to zero
Expand All @@ -19,9 +20,9 @@ const formatPercentChange = (value) => {
return `${value >= 0 ? '+' : '-'}${formatPercent(absValue)}`;
};

const formatDuration = (duration) => `${duration.toFixed(3)} ms`;
const formatDuration = (duration: number): string => `${duration.toFixed(3)} ms`;

const formatDurationChange = (value) => {
const formatDurationChange = (value: number): string => {
if (value > 0) {
return `+${formatDuration(value)}`;
}
Expand All @@ -31,7 +32,7 @@ const formatDurationChange = (value) => {
return '0 ms';
};

const formatChange = (value) => {
const formatChange = (value: number): string => {
if (value > 0) {
return `+${value}`;
}
Expand All @@ -41,7 +42,7 @@ const formatChange = (value) => {
return '0';
};

const getDurationSymbols = (entry) => {
const getDurationSymbols = (entry: Entry): string => {
if (!entry.isDurationDiffOfSignificance) {
if (entry.relativeDurationDiff > 0.15) {
return '🟡';
Expand All @@ -68,7 +69,7 @@ const getDurationSymbols = (entry) => {
return '';
};

const formatDurationDiffChange = (entry) => {
const formatDurationDiffChange = (entry: Entry): string => {
const {baseline, current} = entry;

let output = `${formatDuration(baseline.mean)}${formatDuration(current.mean)}`;
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/measure/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ const getStats = (entries: Entries): Stats => {
};

export default getStats;

export type {Stats};

0 comments on commit cb45bb2

Please sign in to comment.