Skip to content

Commit

Permalink
fix(test): 优化测试用例类型 & update snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakaryCode committed Sep 23, 2022
1 parent e33da7c commit 4c45ced
Show file tree
Hide file tree
Showing 13 changed files with 427 additions and 259 deletions.
4 changes: 2 additions & 2 deletions packages/taro-h5/__tests__/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createReactApp } from '@tarojs/plugin-framework-react/dist/runtime'
import { createRouter } from '@tarojs/router'
import React, { Component } from 'react'
import React, { Component, PropsWithChildren } from 'react'
import ReactDOM from 'react-test-renderer'

const appConfig: any = {
Expand Down Expand Up @@ -63,7 +63,7 @@ export const delay = (ms) => {

export function buildApp () {
const config: any = { ...appConfig }
class App extends Component {
class App extends Component<PropsWithChildren> {
render () {
return this.props.children
}
Expand Down
16 changes: 11 additions & 5 deletions packages/taro-h5/src/api/base/weapp/life-cycle.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import Taro from '@tarojs/api'

import taro, { eventCenter } from '../../taro'
const launchOptions: Taro.getLaunchOptionsSync.LaunchOptions = {
path: '',
query: {},
scene: 0,
shareTicket: '',
referrerInfo: {}
}

function initLaunchOptions (options = {}) {
(taro as any).launchOptions = options
Object.assign(launchOptions, options)
}

eventCenter.once('__taroRouterLaunch', initLaunchOptions)
Taro.eventCenter.once('__taroRouterLaunch', initLaunchOptions)

// 生命周期
export const getLaunchOptionsSync: typeof Taro.getLaunchOptionsSync = () => (taro as any).launchOptions
export const getEnterOptionsSync: typeof Taro.getEnterOptionsSync = () => (taro as any).launchOptions
export const getLaunchOptionsSync: typeof Taro.getLaunchOptionsSync = () => launchOptions
export const getEnterOptionsSync: typeof Taro.getEnterOptionsSync = () => launchOptions
Original file line number Diff line number Diff line change
Expand Up @@ -3844,40 +3844,45 @@ exports[`babel should convert do expressions 2`] = `
router_RouterConfig.config = config;
handler = new multi_page_MultiPageHandler(config);
launchParam = {
\\"query\\": handler.getQuery()
\\"path\\": config.pageName,
\\"query\\": handler.getQuery(),
\\"scene\\": 0,
\\"shareTicket\\": \\"\\",
\\"referrerInfo\\": {}
};
undefined.trigger(\\"__taroRouterLaunch\\", launchParam);
(_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
app.onError && window.addEventListener(\\"error\\", (function(e) {
var _a;
return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message);
}));
pathName = config.pageName;
pageConfig = handler.pageConfig;
_context.prev = 7;
_context.next = 10;
_context.prev = 8;
_context.next = 11;
return (_b = pageConfig.load) === null || _b === void 0 ? void 0 : _b.call(pageConfig);
case 10:
case 11:
element = _context.sent;
if (element instanceof Array) {
element = element[0];
}
_context.next = 17;
_context.next = 18;
break;
case 14:
_context.prev = 14;
_context.t0 = _context[\\"catch\\"](7);
case 15:
_context.prev = 15;
_context.t0 = _context[\\"catch\\"](8);
throw new Error(_context.t0);
case 17:
case 18:
if (element) {
_context.next = 19;
_context.next = 20;
break;
}
return _context.abrupt(\\"return\\");
case 19:
case 20:
enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false;
undefined.trigger(\\"__taroRouterChange\\", {
\\"toLocation\\": {
Expand All @@ -3898,12 +3903,12 @@ exports[`babel should convert do expressions 2`] = `
handler.load(page, pageConfig);
(_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam);
case 29:
case 30:
case \\"end\\":
return _context.stop();
}
}
}), _callee, null, [ [ 7, 14 ] ]);
}), _callee, null, [ [ 8, 15 ] ]);
})));
}
var path_to_regexp = __webpack_require__(8);
Expand Down Expand Up @@ -4505,8 +4510,12 @@ exports[`babel should convert do expressions 2`] = `
});
var launchParam = {
\\"path\\": handler.homePage,
\\"query\\": handler.getQuery(stack.length)
\\"query\\": handler.getQuery(stack.length),
\\"scene\\": 0,
\\"shareTicket\\": \\"\\",
\\"referrerInfo\\": {}
};
undefined.trigger(\\"__taroRouterLaunch\\", launchParam);
(_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
app.onError && window.addEventListener(\\"error\\", (function(e) {
var _a;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3839,40 +3839,45 @@ exports[`compiler-macros - defineAppConfig and definePageConfig should read app
router_RouterConfig.config = config;
handler = new multi_page_MultiPageHandler(config);
launchParam = {
\\"query\\": handler.getQuery()
\\"path\\": config.pageName,
\\"query\\": handler.getQuery(),
\\"scene\\": 0,
\\"shareTicket\\": \\"\\",
\\"referrerInfo\\": {}
};
undefined.trigger(\\"__taroRouterLaunch\\", launchParam);
(_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
app.onError && window.addEventListener(\\"error\\", (function(e) {
var _a;
return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message);
}));
pathName = config.pageName;
pageConfig = handler.pageConfig;
_context.prev = 7;
_context.next = 10;
_context.prev = 8;
_context.next = 11;
return (_b = pageConfig.load) === null || _b === void 0 ? void 0 : _b.call(pageConfig);
case 10:
case 11:
element = _context.sent;
if (element instanceof Array) {
element = element[0];
}
_context.next = 17;
_context.next = 18;
break;
case 14:
_context.prev = 14;
_context.t0 = _context[\\"catch\\"](7);
case 15:
_context.prev = 15;
_context.t0 = _context[\\"catch\\"](8);
throw new Error(_context.t0);
case 17:
case 18:
if (element) {
_context.next = 19;
_context.next = 20;
break;
}
return _context.abrupt(\\"return\\");
case 19:
case 20:
enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false;
undefined.trigger(\\"__taroRouterChange\\", {
\\"toLocation\\": {
Expand All @@ -3893,12 +3898,12 @@ exports[`compiler-macros - defineAppConfig and definePageConfig should read app
handler.load(page, pageConfig);
(_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam);
case 29:
case 30:
case \\"end\\":
return _context.stop();
}
}
}), _callee, null, [ [ 7, 14 ] ]);
}), _callee, null, [ [ 8, 15 ] ]);
})));
}
var path_to_regexp = __webpack_require__(8);
Expand Down Expand Up @@ -4500,8 +4505,12 @@ exports[`compiler-macros - defineAppConfig and definePageConfig should read app
});
var launchParam = {
\\"path\\": handler.homePage,
\\"query\\": handler.getQuery(stack.length)
\\"query\\": handler.getQuery(stack.length),
\\"scene\\": 0,
\\"shareTicket\\": \\"\\",
\\"referrerInfo\\": {}
};
undefined.trigger(\\"__taroRouterLaunch\\", launchParam);
(_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
app.onError && window.addEventListener(\\"error\\", (function(e) {
var _a;
Expand Down
Loading

0 comments on commit 4c45ced

Please sign in to comment.