Skip to content

Commit

Permalink
Bugfix - don't require render in every test (#6318)
Browse files Browse the repository at this point in the history
## Summary
Since the very beginning of testing framework we had the following bug -
if a given test doesn't include any render then the tests freeze. After
debugging I've found that we should have initiated `_wasRenderedNull`
with the opposite value:

```diff
- private _wasRenderedNull: boolean = false;
+ private _wasRenderedNull: boolean = true;
```

## Test plan
  • Loading branch information
Latropos committed Jul 26, 2024
1 parent 1c805ae commit 183add4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export class TestRunner {
private _currentTestCase: TestCase | null = null;
private _renderHook: (component: ReactElement<Component> | null) => void = () => {};
private _valueRegistry: Record<string, SharedValue> = {};
private _wasRenderedNull: boolean = false;
private _includesOnly: boolean = false;
private _syncUIRunner: SyncUIRunner = new SyncUIRunner();
private _renderLock: RenderLock = new RenderLock();
Expand Down Expand Up @@ -81,10 +80,11 @@ export class TestRunner {
}

public async render(component: ReactElement<Component> | null) {
if (!component && this._wasRenderedNull) {
if (!component && this._renderLock.wasRenderedNull()) {
return;
}
this._wasRenderedNull = !component;

this._renderLock.setRenderedNull(!component);
this._renderLock.lock();

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export class SyncUIRunner extends WaitForUnlock {
}

export class RenderLock extends WaitForUnlock {
private _wasRenderedNull: boolean = true;

public lock() {
this._setLock(true);
}
Expand All @@ -47,6 +49,14 @@ export class RenderLock extends WaitForUnlock {
this._setLock(false);
}

public wasRenderedNull() {
return this._wasRenderedNull;
}

public setRenderedNull(wasRenderedNull: boolean) {
this._wasRenderedNull = wasRenderedNull;
}

public async waitForUnlock(maxWaitTime?: number) {
await this._waitForUnlock(maxWaitTime);
}
Expand Down

0 comments on commit 183add4

Please sign in to comment.