Skip to content
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
3 changes: 3 additions & 0 deletions .changeset/thirty-snakes-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---

---
3 changes: 1 addition & 2 deletions packages/react/runtime/__test__/clone.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';

import { elementTree } from './utils/nativeMethod';
import { setupPage } from '../src/snapshot';
import { BackgroundSnapshotInstance } from '../src/backgroundSnapshot';
import { setupPage, BackgroundSnapshotInstance } from '../src/snapshot';
import { cloneElement, createRef } from '../src/index';
import { __root } from '../src/root';
import { globalEnvManager } from './utils/envManager';
Expand Down
10 changes: 7 additions & 3 deletions packages/react/runtime/__test__/compat.test.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';

import { elementTree } from './utils/nativeMethod';
import { backgroundSnapshotInstanceManager, setupPage, snapshotInstanceManager } from '../src/snapshot';
import { setupPage, snapshotInstanceManager, backgroundSnapshotInstanceManager } from '../src/snapshot';
import { ComponentFromReactRuntime, wrapWithLynxComponent } from '../src/compat/lynxComponent';
import { setupDocument } from '../src/document';
import { Fragment, render } from 'preact';
Expand Down Expand Up @@ -38,7 +38,7 @@ describe('addComponentElement', () => {
}
}

const jsx = wrapWithLynxComponent((__c) => <view>{__c}</view>, <C />);
const jsx = wrapWithLynxComponent(__c => <view>{__c}</view>, <C />);

scratch.ensureElements();
render(jsx, scratch);
Expand All @@ -53,7 +53,11 @@ describe('addComponentElement', () => {
`);
});

let snapshot = (__c) => <view id='1' className='2' style='flex: 3'>{__c}</view>;
let snapshot = __c => (
<view id='1' className='2' style='flex: 3'>
{__c}
</view>
);
it('should render a fake component element \'view\' - with some component attr', () => {
class C extends ComponentFromReactRuntime {
render() {
Expand Down
16 changes: 10 additions & 6 deletions packages/react/runtime/__test__/compat/initData.test.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { Component, render } from 'preact';
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
import { elementTree, waitSchedule } from '../utils/nativeMethod';
import { BackgroundSnapshotInstance } from '../../src/backgroundSnapshot';
import { setupBackgroundDocument } from '../../src/document';
import { backgroundSnapshotInstanceManager, setupPage, SnapshotInstance } from '../../src/snapshot';
import {
setupPage,
SnapshotInstance,
BackgroundSnapshotInstance,
backgroundSnapshotInstanceManager,
} from '../../src/snapshot';
import { backgroundSnapshotInstanceToJSON } from '../utils/debug';
import { useState } from 'preact/compat';
import { useInitData, withInitDataInState } from '../../src/lynx-api';
Expand Down Expand Up @@ -49,7 +53,7 @@ describe('initData', () => {
render(<App />, scratch);
_setD(1);
lynx.__initData = {
'key1': 'value1',
key1: 'value1',
};
lynx.getJSModule('GlobalEventEmitter').emit('onDataChanged');
_setD(2);
Expand Down Expand Up @@ -83,7 +87,7 @@ describe('withInitDataInState', () => {
const tt = lynxCoreInject.tt;
expect(app.state).toMatchInlineSnapshot(`{}`);
tt.updateCardData({
'key2': 'value2',
key2: 'value2',
});
expect(lynx.__initData).toMatchInlineSnapshot(`
{
Expand Down Expand Up @@ -111,7 +115,7 @@ describe('withInitDataInState', () => {
const tt = lynxCoreInject.tt;
expect(app.state).toMatchInlineSnapshot(`{}`);
tt.updateCardData({
'key3': 'value3',
key3: 'value3',
});
await waitSchedule();
// state is updated
Expand All @@ -121,7 +125,7 @@ describe('withInitDataInState', () => {
}
`);
app.setState({
'key3': null,
key3: null,
});
await waitSchedule();
expect(app.state).toMatchInlineSnapshot(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@
import { options, render } from 'preact';
import { afterEach, beforeAll, beforeEach, describe, expect, it } from 'vitest';

import { BackgroundSnapshotInstance, hydrate } from '../../src/backgroundSnapshot';
import { setupDocument } from '../../src/document';
import { setupVNodeSourceHook } from '../../src/debug/vnodeSource';
import { SnapshotOperation, SnapshotOperationParams } from '../../src/lifecycle/patch/snapshotPatch';
import { DIFFED, DOM } from '../../src/renderToOpcodes/constants';
import { __root } from '../../src/root';
import {
backgroundSnapshotInstanceManager,
setupPage,
SnapshotInstance,
snapshotInstanceManager,
BackgroundSnapshotInstance,
backgroundSnapshotInstanceManager,
hydrate,
} from '../../src/snapshot';
import { elementTree } from '../utils/nativeMethod';

Expand Down Expand Up @@ -248,13 +249,11 @@ describe('backgroundSnapshot profile', () => {
);

expect(
setAttributeCalls.some(([, option]) => (
setAttributeCalls.some(([, option]) =>
option?.args?.dynamicPartIndex === 'meta' && option?.args?.valueType === 'null'
)),
).toBe(true);
expect(
insertBeforeCalls.some(([, option]) => option?.args?.targetId === ''),
),
).toBe(true);
expect(insertBeforeCalls.some(([, option]) => option?.args?.targetId === '')).toBe(true);
});

it('should apply non-profile move branch with defined target id', () => {
Expand All @@ -265,11 +264,9 @@ describe('backgroundSnapshot profile', () => {

const patch = hydrate(before, after);
const operations = decodePatch(patch);
const moveWithDefinedTarget = operations.find(({ op, args }) => (
op === SnapshotOperation.InsertBefore
&& args[0] === before.id
&& args[2] !== undefined
));
const moveWithDefinedTarget = operations.find(
({ op, args }) => op === SnapshotOperation.InsertBefore && args[0] === before.id && args[2] !== undefined,
);

expect(moveWithDefinedTarget).toBeDefined();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
// LICENSE file in the root directory of this source tree.
*/
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { backgroundSnapshotInstanceManager, snapshotInstanceManager } from '../../src/snapshot';
import { elementTree } from '../utils/nativeMethod';
import { BackgroundSnapshotInstance } from '../../src/backgroundSnapshot';
import {
BackgroundSnapshotInstance,
backgroundSnapshotInstanceManager,
SnapshotInstance,
snapshotInstanceManager,
} from '../../src/snapshot';
import { printSerializedSnapshotInstance, printSnapshotInstance } from '../../src/debug/printSnapshot';
import { SnapshotInstance } from '../../src/snapshot';

const HOLE = null;

Expand Down
2 changes: 1 addition & 1 deletion packages/react/runtime/__test__/element.test.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { beforeEach, describe, expect, it } from 'vitest';

import { BackgroundSnapshotInstance } from '../src/backgroundSnapshot';
import { BackgroundSnapshotInstance } from '../src/snapshot';

describe('BackgroundSnapshotInstance', () => {
let root, child1, child2, child3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ import { render } from 'preact';
import { useState } from 'preact/compat';
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';

import { BackgroundSnapshotInstance } from '../../src/backgroundSnapshot';
import { setupBackgroundDocument } from '../../src/document';
import { useLynxGlobalEventListener } from '../../src/lynx-api';
import { SnapshotInstance, backgroundSnapshotInstanceManager, setupPage } from '../../src/snapshot';
import {
BackgroundSnapshotInstance,
backgroundSnapshotInstanceManager,
SnapshotInstance,
setupPage,
} from '../../src/snapshot';
import { backgroundSnapshotInstanceToJSON } from '../utils/debug.js';
import { elementTree } from '../utils/nativeMethod';

Expand All @@ -29,7 +33,7 @@ describe('useLynxGlobalEventListener', () => {

const lynx = {
...globalThis.lynx,
getJSModule: (moduleName) => {
getJSModule: moduleName => {
if (moduleName === 'GlobalEventEmitter') {
return ee;
}
Expand Down Expand Up @@ -109,7 +113,7 @@ describe('useLynxGlobalEventListener', () => {
};
vi.stubGlobal('lynx', {
...globalThis.lynx,
getJSModule: (moduleName) => {
getJSModule: moduleName => {
if (moduleName === 'GlobalEventEmitter') {
return fakeEE;
}
Expand Down
11 changes: 8 additions & 3 deletions packages/react/runtime/__test__/hydrate.test.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { elementTree } from './utils/nativeMethod';
import { BackgroundSnapshotInstance, hydrate } from '../src/backgroundSnapshot';
import { backgroundSnapshotInstanceManager, SnapshotInstance, snapshotInstanceManager } from '../src/snapshot';
import {
SnapshotInstance,
snapshotInstanceManager,
backgroundSnapshotInstanceManager,
BackgroundSnapshotInstance,
hydrate,
} from '../src/snapshot';

const HOLE = null;

Expand Down Expand Up @@ -244,7 +249,7 @@ describe('dual-runtime hydrate', () => {
aa.insertBefore(bb2);

// happens when first-screen render is failed
expect(hydrate({ 'id': -1, 'type': 'root' }, aa)).toMatchInlineSnapshot(`
expect(hydrate({ id: -1, type: 'root' }, aa)).toMatchInlineSnapshot(`
[
0,
"__snapshot_a94a8_test_2",
Expand Down
35 changes: 13 additions & 22 deletions packages/react/runtime/__test__/lifecycle.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { deinitGlobalSnapshotPatch, initGlobalSnapshotPatch } from '../src/lifec
import { LifecycleConstant } from '../src/lifecycleConstant';
import { CATCH_ERROR } from '../src/renderToOpcodes/constants';
import { __root } from '../src/root';
import { backgroundSnapshotInstanceManager, setupPage } from '../src/snapshot';
import { setupPage, backgroundSnapshotInstanceManager } from '../src/snapshot';

beforeAll(() => {
setupPage(__CreatePage('0', 0));
Expand Down Expand Up @@ -352,11 +352,7 @@ describe('componentWillUnmount', () => {
}

render() {
return (
<view>
{showB && <B></B>}
</view>
);
return <view>{showB && <B></B>}</view>;
}
}

Expand Down Expand Up @@ -397,20 +393,15 @@ describe('BackgroundSnapshotInstance remove', () => {
function Comp() {
const [show, setShow] = useState(1);
setShow_ = setShow;
return (
<view>
{show && <text>1</text>}
</view>
);
return <view>{show && <text>1</text>}</view>;
}

initGlobalSnapshotPatch();

render(<Comp />, __root);
await Promise.resolve().then(() => {});
vi.runAllTimers();
expect([...backgroundSnapshotInstanceManager.values.keys()])
.toMatchInlineSnapshot(`
expect([...backgroundSnapshotInstanceManager.values.keys()]).toMatchInlineSnapshot(`
[
1,
2,
Expand All @@ -424,8 +415,7 @@ describe('BackgroundSnapshotInstance remove', () => {
vi.runAllTimers();

mtCallbacks[0][2]();
expect([...backgroundSnapshotInstanceManager.values.keys()])
.toMatchInlineSnapshot(`
expect([...backgroundSnapshotInstanceManager.values.keys()]).toMatchInlineSnapshot(`
[
1,
2,
Expand All @@ -434,8 +424,7 @@ describe('BackgroundSnapshotInstance remove', () => {
`);
await Promise.resolve().then(() => {});
vi.runAllTimers();
expect([...backgroundSnapshotInstanceManager.values.keys()])
.toMatchInlineSnapshot(`
expect([...backgroundSnapshotInstanceManager.values.keys()]).toMatchInlineSnapshot(`
[
1,
2,
Expand Down Expand Up @@ -516,11 +505,13 @@ describe('useState', () => {

setShow_ = setShow;

return show && (
<view>
<text attr={boolValue}></text>
<text attr={objValue}></text>
</view>
return (
show && (
<view>
<text attr={boolValue}></text>
<text attr={objValue}></text>
</view>
)
);
}

Expand Down
10 changes: 7 additions & 3 deletions packages/react/runtime/__test__/lynx/suspense.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ import { replaceCommitHook } from '../../src/lifecycle/patch/commit';
import { injectUpdateMainThread } from '../../src/lifecycle/patch/updateMainThread';
import '../../src/lynx/component';
import { __root } from '../../src/root';
import { setupPage, SnapshotInstance, snapshotInstanceManager } from '../../src/snapshot';
import {
setupPage,
SnapshotInstance,
snapshotInstanceManager,
BackgroundSnapshotInstance,
backgroundSnapshotInstanceManager,
} from '../../src/snapshot';
import { globalEnvManager } from '../utils/envManager';
import { elementTree } from '../utils/nativeMethod';
import { backgroundSnapshotInstanceManager } from '../../src/snapshot';
import { prettyFormatSnapshotPatch } from '../../src/debug/formatPatch';
import { createSuspender } from '../createSuspender';
import { BackgroundSnapshotInstance } from '../../src/backgroundSnapshot';

beforeAll(() => {
setupPage(__CreatePage('0', 0));
Expand Down
Loading
Loading