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

[No QA] [TS migration] Migrate 'format.js' test to TypeScript #36223

Merged
merged 7 commits into from
Mar 4, 2024
Merged
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
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};
Loading