From ed95b1dbd6ce69ac2f809a17a435ef9d8ab39019 Mon Sep 17 00:00:00 2001 From: * <8> Date: Tue, 12 Apr 2022 18:06:43 +0800 Subject: [PATCH 1/2] Match-id-71ff0d0e801ac619571665190bceaf8ccdd61480 --- .../HookTest/UseCallback.test.js | 6 +- .../ComponentTest/HookTest/UseContext.test.js | 6 +- .../ComponentTest/HookTest/UseEffect.test.js | 74 +-- .../HookTest/UseImperativeHandle.test.js | 8 +- .../HookTest/UseLayoutEffect.test.js | 14 +- .../ComponentTest/HookTest/UseMemo.test.js | 18 +- .../ComponentTest/HookTest/UseReducer.test.js | 6 +- .../ComponentTest/HookTest/UseRef.test.js | 9 +- .../ComponentTest/HookTest/UseState.test.js | 28 +- scripts/__tests__/DomTest/Attribute.test.js | 64 +++ scripts/__tests__/DomTest/DomInput.test.js | 428 ++++++++++++++++++ scripts/__tests__/DomTest/DomSelect.test.js | 341 ++++++++++++++ scripts/__tests__/EventTest/EventMain.test.js | 23 +- .../__tests__/EventTest/FocusEvent.test.js | 4 +- .../__tests__/EventTest/KeyboardEvent.test.js | 2 +- .../__tests__/EventTest/MouseEvent.test.js | 34 +- .../__tests__/EventTest/WheelEvent.test.js | 4 +- scripts/__tests__/jest/customMatcher.js | 13 + scripts/__tests__/jest/jestEnvironment.js | 1 + scripts/__tests__/jest/jestSetting.js | 2 + scripts/__tests__/jest/logUtils.js | 2 +- scripts/__tests__/jest/testUtils.js | 3 + 22 files changed, 966 insertions(+), 124 deletions(-) create mode 100755 scripts/__tests__/DomTest/Attribute.test.js create mode 100755 scripts/__tests__/DomTest/DomInput.test.js create mode 100755 scripts/__tests__/DomTest/DomSelect.test.js create mode 100644 scripts/__tests__/jest/customMatcher.js mode change 100644 => 100755 scripts/__tests__/jest/logUtils.js diff --git a/scripts/__tests__/ComponentTest/HookTest/UseCallback.test.js b/scripts/__tests__/ComponentTest/HookTest/UseCallback.test.js index e2d51e9d..f63afe30 100644 --- a/scripts/__tests__/ComponentTest/HookTest/UseCallback.test.js +++ b/scripts/__tests__/ComponentTest/HookTest/UseCallback.test.js @@ -7,15 +7,15 @@ describe('useCallback Hook Test', () => { const App = (props) => { const [num, setNum] = useState(0); const NumUseCallback = useCallback(() => { - setNum(num + props.text) + setNum(num + props.text); }, [props]); return ( <>

{num}

; - ) - - } + ); + }; Horizon.render(, container); expect(LogUtils.getAndClear()).toEqual([1]); expect(container.querySelector('p').innerHTML).toBe('1'); diff --git a/scripts/__tests__/ComponentTest/HookTest/UseState.test.js b/scripts/__tests__/ComponentTest/HookTest/UseState.test.js index 7e485671..01db57c1 100644 --- a/scripts/__tests__/ComponentTest/HookTest/UseState.test.js +++ b/scripts/__tests__/ComponentTest/HookTest/UseState.test.js @@ -19,8 +19,8 @@ describe('useState Hook Test', () => {

{num}

, container) + Horizon.render(, container); container.querySelector('button').click(); expect(handleClick).toHaveBeenCalledTimes(1); for (let i = 0; i < 5; i++) { container.querySelector('button').click(); } expect(handleClick).toHaveBeenCalledTimes(6); - }) - }) + }); + }); const test = (name, config) => { const node = Horizon.render(config, container); @@ -89,7 +81,7 @@ describe('MouseEvent Test', () => { `${name} capture`, `${name} bubble` ]); - } + }; describe('合成鼠标事件', () => { it('onMouseMove', () => { @@ -102,7 +94,7 @@ describe('MouseEvent Test', () => { test('mousemove',
) + />); }); it('onMouseDown', () => { @@ -115,7 +107,7 @@ describe('MouseEvent Test', () => { test('mousedown',
) + />); }); it('onMouseUp', () => { @@ -128,7 +120,7 @@ describe('MouseEvent Test', () => { test('mouseup',
) + />); }); it('onMouseOut', () => { @@ -141,7 +133,7 @@ describe('MouseEvent Test', () => { test('mouseout',
) + />); }); it('onMouseOver', () => { @@ -154,7 +146,7 @@ describe('MouseEvent Test', () => { test('mouseover',
) + />); }); - }) -}) + }); +}); diff --git a/scripts/__tests__/EventTest/WheelEvent.test.js b/scripts/__tests__/EventTest/WheelEvent.test.js index a0ebf933..e4bd9ce0 100644 --- a/scripts/__tests__/EventTest/WheelEvent.test.js +++ b/scripts/__tests__/EventTest/WheelEvent.test.js @@ -22,7 +22,7 @@ describe('合成滚轮事件', () => { ]); }); - it('可以执行preventDefault和 stopPropagation', () => { + it('可以执行preventDefault和stopPropagation', () => { const eventHandler = e => { expect(e.isDefaultPrevented()).toBe(false); e.preventDefault(); @@ -49,4 +49,4 @@ describe('合成滚轮事件', () => { ]); }); -}) \ No newline at end of file +}); \ No newline at end of file diff --git a/scripts/__tests__/jest/customMatcher.js b/scripts/__tests__/jest/customMatcher.js new file mode 100644 index 00000000..b2198341 --- /dev/null +++ b/scripts/__tests__/jest/customMatcher.js @@ -0,0 +1,13 @@ +import { runAsyncEffects } from '../../../libs/horizon/src/renderer/submit/HookEffectHandler'; +import { callRenderQueueImmediate } from '../../../libs/horizon/src/renderer/taskExecutor/RenderQueue'; +import { asyncUpdates } from '../../../libs/horizon/src/renderer/TreeBuilder'; + +const act = (fun) => { + asyncUpdates(fun); + callRenderQueueImmediate(); + runAsyncEffects(); +}; + +module.exports = { + act +}; \ No newline at end of file diff --git a/scripts/__tests__/jest/jestEnvironment.js b/scripts/__tests__/jest/jestEnvironment.js index 59b5a6ee..d19a3b87 100644 --- a/scripts/__tests__/jest/jestEnvironment.js +++ b/scripts/__tests__/jest/jestEnvironment.js @@ -1,6 +1,7 @@ global.MessageChannel = function MessageChannel() { this.port1 = {}; this.port2 = { + // eslint-disable-next-line @typescript-eslint/no-empty-function postMessage() { } }; }; diff --git a/scripts/__tests__/jest/jestSetting.js b/scripts/__tests__/jest/jestSetting.js index 78773f65..331d17b2 100644 --- a/scripts/__tests__/jest/jestSetting.js +++ b/scripts/__tests__/jest/jestSetting.js @@ -1,6 +1,8 @@ import { unmountComponentAtNode } from '../../../libs/horizon/src/dom/DOMExternal'; import * as LogUtils from '../jest/logUtils'; +import failOnConsole from 'jest-fail-on-console'; +failOnConsole(); global.isDev = process.env.NODE_ENV === 'development'; global.container = null; global.beforeEach(() => { diff --git a/scripts/__tests__/jest/logUtils.js b/scripts/__tests__/jest/logUtils.js old mode 100644 new mode 100755 index 276bfb92..fa98f6a8 --- a/scripts/__tests__/jest/logUtils.js +++ b/scripts/__tests__/jest/logUtils.js @@ -19,7 +19,7 @@ const getAndClear = () => { const clear = () => { dataArray = dataArray ? null : dataArray; -} +}; exports.clear = clear; exports.log = log; diff --git a/scripts/__tests__/jest/testUtils.js b/scripts/__tests__/jest/testUtils.js index 4afda9da..161ea659 100644 --- a/scripts/__tests__/jest/testUtils.js +++ b/scripts/__tests__/jest/testUtils.js @@ -12,6 +12,9 @@ export const getEventListeners = (dom) => { for (let key in dom) { keyArray.push(key); } + console.log(keyArray); + console.log('---------------------------------'); + console.log(allDelegatedNativeEvents); try { allDelegatedNativeEvents.forEach(event => { if (!keyArray.includes(event)) { From c3a580fc9747cc79ee3a152da12cedf15f3f8b69 Mon Sep 17 00:00:00 2001 From: * <8> Date: Tue, 12 Apr 2022 19:39:55 +0800 Subject: [PATCH 2/2] Match-id-33d03d13bb50e96e6db086f816052cd2a6c6d7ae --- scripts/__tests__/DomTest/DomInput.test.js | 2 +- scripts/__tests__/jest/customMatcher.js | 13 ------------- 2 files changed, 1 insertion(+), 14 deletions(-) delete mode 100644 scripts/__tests__/jest/customMatcher.js diff --git a/scripts/__tests__/DomTest/DomInput.test.js b/scripts/__tests__/DomTest/DomInput.test.js index 21248e3f..218cecc6 100755 --- a/scripts/__tests__/DomTest/DomInput.test.js +++ b/scripts/__tests__/DomTest/DomInput.test.js @@ -1,9 +1,9 @@ /* eslint-disable @typescript-eslint/no-empty-function */ import * as Horizon from '@cloudsop/horizon/index.ts'; import * as LogUtils from '../jest/logUtils'; -import { act } from '../jest/customMatcher'; describe('Dom Input', () => { + const { act } = Horizon; describe('type checkbox', () => { it('没有设置checked属性时,控制台不会报错', () => { diff --git a/scripts/__tests__/jest/customMatcher.js b/scripts/__tests__/jest/customMatcher.js deleted file mode 100644 index b2198341..00000000 --- a/scripts/__tests__/jest/customMatcher.js +++ /dev/null @@ -1,13 +0,0 @@ -import { runAsyncEffects } from '../../../libs/horizon/src/renderer/submit/HookEffectHandler'; -import { callRenderQueueImmediate } from '../../../libs/horizon/src/renderer/taskExecutor/RenderQueue'; -import { asyncUpdates } from '../../../libs/horizon/src/renderer/TreeBuilder'; - -const act = (fun) => { - asyncUpdates(fun); - callRenderQueueImmediate(); - runAsyncEffects(); -}; - -module.exports = { - act -}; \ No newline at end of file