Skip to content

Commit

Permalink
feat: pre-v1 updates backport (#459)
Browse files Browse the repository at this point in the history
* refactor: rename `meassurePerformance` to `measureRenders` (#433)

* refactor: rename measurePerformance to measureRenders

* refactor: expose legacy `measurePerformance` alias

* chore: file naming

* chore: add changeset

* refactor: add `writeFile` option

* refactor: warn once

* docs: tweaks

* refactor: rename MeasureRendersOptions

* refactor: rename resetToDefaults

* refactor: cleanup logger exports (#434)

* chore: yarn upgrade

* refactor: cleanup logger exports

* chore: add change sets

* chore: upgrade deps 2024-01-05 (#435)

* chore: update some deps

* chore: upgrade babel

* chore upgrade types

* chore: upgrade line

* chore: upgrade react-native

* fix: fix logger outputing undefined in report

* chore: upgrade danger and turborepo

* chore: upgrade eslint config (#437)

* chore: upgrade eslint config

* refactor: fix issues

* chore: update test-app

* chore: fix ts

* chore: update snapshots

* chore: ignore `lib` in test

* chore: fix tests

* chore: fix ci dangerfile

* chore: simplify folder structure (#438)

* refactor: revert measureRenders name

# Conflicts:
#	packages/measure/CHANGELOG.md
#	packages/reassure/CHANGELOG.md
#	test-apps/native/CHANGELOG.md

* refactor: revert reset to defaults rename

* chore: reformat

* refactor: revert measureRender rename
  • Loading branch information
mdjastrzebski authored Feb 21, 2024
1 parent b88261f commit b455bd4
Show file tree
Hide file tree
Showing 92 changed files with 1,930 additions and 1,692 deletions.
7 changes: 7 additions & 0 deletions .changeset/chatty-paws-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@callstack/reassure-measure': minor
'reassure': minor
'test-app-native': minor
---

- Add `writeFile` option to `measureRenders`/`measureFunction`.
8 changes: 8 additions & 0 deletions .changeset/many-cups-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@callstack/reassure-logger': minor
'@callstack/reassure-compare': patch
'@callstack/reassure-measure': patch
'@callstack/reassure-cli': patch
---

refactor: simplify `reassure-logger` package exports
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
docusaurus/build/**
**/*.js
packages/**/lib/**
dangerfile.ts
10 changes: 9 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
module.exports = {
extends: '@callstack/eslint-config',
extends: '@callstack/eslint-config/node',
rules: {
'require-await': 'error',
},
ignorePatterns: ['docusaurus/**'],
overrides: [
{
files: ['*.ts', '*.tsx'],
parserOptions: {
project: './packages/**/tsconfig.json',
},
},
],
};
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,15 @@ interface MeasureOptions {
warmupRuns?: number;
wrapper?: React.ComponentType<{ children: ReactElement }>;
scenario?: (view?: RenderResult) => Promise<any>;
writeFile?: boolean;
}
```

- **`runs`**: number of runs per series for the particular test
- **`warmupRuns`**: number of additional warmup runs that will be done and discarded before the actual runs (default 1).
- **`wrapper`**: React component, such as a `Provider`, which the `ui` will be wrapped with. Note: the render duration of the `wrapper` itself is excluded from the results; only the wrapped component is measured.
- **`scenario`**: a custom async function, which defines user interaction within the UI by utilising RNTL or RTL functions
- **`writeFile`**: (default `true`) should write output to file.

#### `measureFunction` function

Expand Down Expand Up @@ -435,10 +437,11 @@ const defaultConfig: Config = {
```

**`runs`**: the number of repeated runs in a series per test (allows for higher accuracy by aggregating more data). Should be handled with care.

- **`warmupRuns`**: the number of additional warmup runs that will be done and discarded before the actual runs.
**`outputFile`**: the name of the file the records will be saved to
**`verbose`**: make Reassure log more, e.g. for debugging purposes
**`testingLibrary`**: where to look for `render` and `cleanup` functions, supported values `'react-native'`, `'react'` or object providing custom `render` and `cleanup` functions
**`outputFile`**: the name of the file the records will be saved to
**`verbose`**: make Reassure log more, e.g. for debugging purposes
**`testingLibrary`**: where to look for `render` and `cleanup` functions, supported values `'react-native'`, `'react'` or object providing custom `render` and `cleanup` functions

#### `configure` function

Expand Down
30 changes: 20 additions & 10 deletions docusaurus/docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ sidebar_position: 4

## Measurements

### `measurePerformance` function
### `measurePerformance()` function {#measure-renders}

Custom wrapper for the RNTL `render` function responsible for rendering the passed screen inside a `React.Profiler` component,
:::info

Prior to version 1.0, this function has been named `measurePerformance`.

:::

Custom wrapper for the RNTL/RTL's `render` function responsible for rendering the passed screen inside a `React.Profiler` component,
measuring its performance and writing results to the output file. You can use optional `options` object allows customizing aspects
of the testing
of the testing.

```ts
async function measurePerformance(
Expand All @@ -20,7 +26,7 @@ async function measurePerformance(
): Promise<MeasureResults> {
```
#### Example
#### Example {#measure-renders-example}
```ts
// sample.perf-test.tsx
Expand All @@ -38,23 +44,25 @@ test('Test with scenario', async () => {
});
```
### `MeasureOptions` type
### `MeasureOptions` type {#measure-renders-options}
```ts
interface MeasureOptions {
runs?: number;
warmupRuns?: number;
wrapper?: React.ComponentType<{ children: ReactElement }>;
scenario?: (view?: RenderResult) => Promise<any>;
writeFile?: boolean;
}
```
- **`runs`**: number of runs per series for the particular test
- **`warmupRuns`**: number of additional warmup runs that will be done and discarded before the actual runs.
- **`wrapper`**: React component, such as a `Provider`, which the `ui` will be wrapped with. Note: the render duration of the `wrapper` itself is excluded from the results, only the wrapped component is measured.
- **`scenario`**: a custom async function, which defines user interaction within the ui by utilized RNTL functions
- **`writeFile`**: (default `true`) should write output to file.
### `measureFunction` function
### `measureFunction` function {#measure-function}
Allows you to wrap any synchronous function, measure its performance and write results to the output file. You can use optional `options` to customize aspects of the testing.
Expand All @@ -65,7 +73,7 @@ async function measureFunction(
): Promise<MeasureResults> {
```
#### Example
#### Example {#measure-function-example}
```ts
// sample.perf-test.tsx
Expand All @@ -77,17 +85,19 @@ test('fib 30', async () => {
});
```
### `MeasureFunctionOptions` type
### `MeasureFunctionOptions` type {#measure-function-options}
```ts
interface MeasureFunctionOptions {
runs?: number;
warmupRuns?: number;
writeFile?: boolean;
}
```
- **`runs`**: number of runs per series for the particular test
- **`warmupRuns`**: number of additional warmup runs that will be done and discarded before the actual runs.
- **`writeFile`**: (default `true`) should write output to file.
## Configuration
Expand Down Expand Up @@ -133,7 +143,7 @@ function configure(customConfig: Partial<Config>): void;
You can use the `configure` function to override the default config parameters.
#### Example
#### Example {#configure-example}
```ts
import { configure } from 'reassure';
Expand All @@ -144,7 +154,7 @@ configure({
});
```
### `resetToDefault` function
### `resetToDefault` function {#reset-to-defaults}
```ts
resetToDefault(): void
Expand Down
1 change: 1 addition & 0 deletions docusaurus/docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ If your test contains any async changes, you will need to make sure that the sce
`findBy` queries, `waitFor` or `waitForElementToBeRemoved` functions from RNTL.

For more examples look into our example apps:

- [React Native (CLI)](https://github.com/callstack/reassure-examples/tree/main/examples/native)
- [React Native (Expo)](https://github.com/callstack/reassure-examples/tree/main/examples/native-expo)
- [React (Next.js)](https://github.com/callstack/reassure-examples/tree/main/examples/web-nextjs)
Expand Down
38 changes: 19 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,31 @@
},
"homepage": "https://github.com/callstack/reassure#readme",
"devDependencies": {
"@babel/core": "^7.20.12",
"@babel/plugin-transform-flow-strip-types": "^7.19.0",
"@babel/preset-typescript": "^7.20.7",
"@babel/runtime": "^7.20.7",
"@callstack/eslint-config": "^13.0.2",
"@babel/core": "^7.23.7",
"@babel/plugin-transform-flow-strip-types": "^7.23.3",
"@babel/preset-env": "^7.23.7",
"@babel/preset-typescript": "^7.23.3",
"@babel/runtime": "^7.23.7",
"@callstack/eslint-config": "^14.1.0",
"@changesets/cli": "^2.26.0",
"@testing-library/react": "^14.0.0",
"@testing-library/react-native": "^12.0.0",
"@types/jest": "^29.2.5",
"@types/react": "^18.0.26",
"@types/react-native": "0.71.3",
"babel-jest": "^29.3.1",
"danger": "^11.2.3",
"eslint": "^8.32.0",
"eslint-config-prettier": "^8.6.0",
"@relmify/jest-serializer-strip-ansi": "^1.0.2",
"@testing-library/react": "^14.1.2",
"@testing-library/react-native": "^12.4.3",
"@types/jest": "^29.5.11",
"@types/react": "^18.2.46",
"babel-jest": "^29.7.0",
"danger": "^11.3.1",
"eslint": "^8.56.0",
"eslint-config-prettier": "^8.10.0",
"eslint-plugin-prettier": "^4.2.1",
"jest": "^29.3.1",
"pod-install": "^0.1.38",
"prettier": "^2.8.3",
"jest": "^29.7.0",
"prettier": "^2.8.8",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-native": "0.72.5",
"react-native": "0.73.1",
"react-native-builder-bob": "^0.20.3",
"react-test-renderer": "18.2.0",
"turbo": "^1.6.3",
"turbo": "^1.11.3",
"typescript": "^5.2.2"
},
"peerDependencies": {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@
"output": "lib",
"targets": [
"commonjs",
"module"
"module",
[
"typescript",
{
"project": "tsconfig.build.json"
}
]
]
},
"publishConfig": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { command as init } from './commands/init';
import { command as checkStability } from './commands/check-stability';
import { command as measure } from './commands/measure';

yargs(hideBin(process.argv))
void yargs(hideBin(process.argv))
.command(measure)
.command(init)
.command(checkStability)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { copyFileSync, existsSync, readFileSync, appendFileSync } from 'node:fs';
import * as path from 'node:path';
import { logger } from '@callstack/reassure-logger';
import * as logger from '@callstack/reassure-logger';
import type { CommandModule } from 'yargs';
import {
CI_SCRIPT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { spawnSync } from 'node:child_process';
import type { CommandModule } from 'yargs';
import { compare, formatMetadata } from '@callstack/reassure-compare';
import type { PerformanceMetadata } from '@callstack/reassure-compare';
import { logger } from '@callstack/reassure-logger';
import * as logger from '@callstack/reassure-logger';
import { RESULTS_DIRECTORY, RESULTS_FILE, BASELINE_FILE } from '../constants';
import { applyCommonOptions, CommonOptions } from '../options';
import { getGitBranch, getGitCommitHash } from '../utils/git';
Expand Down Expand Up @@ -87,7 +87,7 @@ export async function run(options: MeasureOptions) {
},
});

logger.log();
logger.newLine();

if (spawnInfo.status !== 0) {
logger.error(`❌ Test runner (${testRunnerPath}) exited with error code ${spawnInfo.status}`);
Expand All @@ -110,7 +110,7 @@ export async function run(options: MeasureOptions) {

if (options.compare) {
if (existsSync(BASELINE_FILE)) {
compare();
await compare();
} else {
logger.log(
`Baseline performance file does not exist, run 'reassure --baseline' on your baseline code branch to create it.\n`
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import simpleGit from 'simple-git';
import { logger } from '@callstack/reassure-logger';
import * as logger from '@callstack/reassure-logger';

export async function getGitBranch() {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { logger } from '@callstack/reassure-logger';
import { configure } from '@callstack/reassure-logger';
import type { CommonOptions } from '../options';

export function configureLoggerOptions(options: CommonOptions) {
logger.configure({
configure({
silent: options.silent,
verbose: options.verbose,
});
Expand Down
5 changes: 5 additions & 0 deletions packages/cli/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "./tsconfig",
"include": ["src/**/*"],
"exclude": ["**/__tests__/**"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,5 @@
"skipLibCheck": true,
"strict": true,
"target": "esnext"
},
"include": ["src/**/*"],
"exclude": ["**/__tests__/**"]
}
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module.exports = {
preset: '@testing-library/react-native',
transformIgnorePatterns: ['node_modules/(?!(jest-)?@?react-native|@react-native-community|@react-navigation)'],
modulePathIgnorePatterns: ['<rootDir>/lib/'],
snapshotSerializers: ['@relmify/jest-serializer-strip-ansi/always'],
clearMocks: true,
};
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@
"targets": [
"commonjs",
"module",
"typescript"
[
"typescript",
{
"project": "tsconfig.build.json"
}
]
]
},
"publishConfig": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type CompareOptions = {
*
* Responsible for loading baseline and current performance results and outputting data in various formats.
*/
export function compare({
export async function compare({
baselineFile = '.reassure/baseline.perf',
currentFile = '.reassure/current.perf',
outputFile = '.reassure/output.json',
Expand Down Expand Up @@ -88,10 +88,10 @@ export function compare({
printToConsole(output);
}
if (outputFormat === 'json' || outputFormat === 'all') {
writeToJson(outputFile, output);
await writeToJson(outputFile, output);
}
if (outputFormat === 'markdown' || outputFormat === 'all') {
writeToMarkdown('.reassure/output.md', output);
await writeToMarkdown('.reassure/output.md', output);
}
}

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { logger } from '@callstack/reassure-logger';
import * as logger from '@callstack/reassure-logger';
import type { AddedEntry, CompareResult, CompareEntry, RemovedEntry } from '../types';
import { formatCount, formatDuration, formatMetadata, formatCountChange, formatDurationChange } from '../utils/format';
import type { PerformanceMetadata } from '../types';
Expand All @@ -25,7 +25,7 @@ export function printToConsole(data: CompareResult) {
logger.log('\n➡️ Removed scenarios');
data.removed.forEach(printRemovedLine);

logger.log();
logger.newLine();
}

function printMetadata(name: string, metadata?: PerformanceMetadata) {
Expand Down
Loading

0 comments on commit b455bd4

Please sign in to comment.