提交 5c285042 编写于 作者: W wangjinxin613

Merge branch 'dev' of gitcode.net:dcloud/hello-uvue into dev

...@@ -66,7 +66,7 @@ const pages = [ ...@@ -66,7 +66,7 @@ const pages = [
'pages/composition-api/lifecycle/page-lifecycle/page-lifecycle', 'pages/composition-api/lifecycle/page-lifecycle/page-lifecycle',
'pages/composition-api/lifecycle/component-lifecycle/component-lifecycle', 'pages/composition-api/lifecycle/component-lifecycle/component-lifecycle',
'pages/built-in-component/teleport/teleport', 'pages/built-in-component/teleport/teleport',
'pages/component-instance/watch-function/watch-function' 'pages/component-instance/watch-function/watch-function'
// 仅app // 仅app
// 'pages/composition/mixins/mixins', // 'pages/composition/mixins/mixins',
...@@ -102,13 +102,13 @@ const pages = [ ...@@ -102,13 +102,13 @@ const pages = [
// 'pages/composition-api/reactivity/watch-effect/watch-effect', // 'pages/composition-api/reactivity/watch-effect/watch-effect',
// 'pages/composition-api/reactivity/watch-post-effect/watch-post-effect', // 'pages/composition-api/reactivity/watch-post-effect/watch-post-effect',
// 'pages/composition-api/reactivity/watch-sync-effect/watch-sync-effect', // 'pages/composition-api/reactivity/watch-sync-effect/watch-sync-effect',
// 'pages/composition-api/reactivity/watch/watch', // 'pages/composition-api/reactivity/watch/watch',
// 'pages/composition/provide/provide', // 'pages/composition/provide/provide',
// 'pages/composition/provide/provide-page2', // 'pages/composition/provide/provide-page2',
// 'pages/state/data/data', // 'pages/state/data/data',
// 功能差异 // 功能差异
// 'pages/composition/setup/setup', // 'pages/composition/setup/setup',
// 'pages/component-instance/el/el', // 'pages/component-instance/el/el',
// 样式差异 // 样式差异
...@@ -144,12 +144,12 @@ describe("shot-compare", () => { ...@@ -144,12 +144,12 @@ describe("shot-compare", () => {
shouldCompareScreenShot = version > 9 shouldCompareScreenShot = version > 9
} }
if (!shouldCompareScreenShot) { if (!shouldCompareScreenShot) {
it("other platform not support", async () => { it("other platform not support", async () => {
expect(1).toBe(1); expect(1).toBe(1);
}); });
return return
} }
let page = null; let page = null;
let pageIndex = 0; let pageIndex = 0;
...@@ -158,14 +158,14 @@ describe("shot-compare", () => { ...@@ -158,14 +158,14 @@ describe("shot-compare", () => {
page = await program.reLaunch(PAGE_PATH); page = await program.reLaunch(PAGE_PATH);
await page.waitFor(500); await page.waitFor(500);
// set webview-screenshot-comparison page baseSrc // set webview-screenshot-comparison page baseSrc
baseSrc = baseSrc =
process.env.UNI_WEB_SERVICE_URL ? `${process.env.UNI_WEB_SERVICE_URL}/#/` : process.env.UNI_WEB_SERVICE_URL ? `${process.env.UNI_WEB_SERVICE_URL}/#/` :
"http://192.168.31.223:5173/#/"; "http://test.dcloud.io/unix_h5_build/98_dev_hello-uvue/#/";
page.setData({ page.setData({
baseSrc, baseSrc,
}); });
}); });
beforeEach(async () => { beforeEach(async () => {
page = await program.reLaunch(PAGE_PATH); page = await program.reLaunch(PAGE_PATH);
...@@ -175,23 +175,23 @@ describe("shot-compare", () => { ...@@ -175,23 +175,23 @@ describe("shot-compare", () => {
pageIndex++; pageIndex++;
}); });
test.each(pages)("%s", async () => { test.each(pages)("%s", async () => {
const isNeedAdbScreenshot = needAdbScreenshot(pages[pageIndex]); const isNeedAdbScreenshot = needAdbScreenshot(pages[pageIndex]);
const isCustomNavigationBar = customNavigationPages.includes(pages[pageIndex]); const isCustomNavigationBar = customNavigationPages.includes(pages[pageIndex]);
const { const {
statusBarHeight, statusBarHeight,
devicePixelRatio devicePixelRatio
} = await page.data(); } = await page.data();
const screenshotParams = { const screenshotParams = {
fullPage: true, fullPage: true,
adb: isNeedAdbScreenshot, adb: isNeedAdbScreenshot,
// adb 截图时跳过状态栏 // adb 截图时跳过状态栏
area: { area: {
x: 0, x: 0,
y: statusBarHeight * devicePixelRatio, y: statusBarHeight * devicePixelRatio,
}, },
} }
const screenshotPath = `__webview__${pages[pageIndex].replace(/\//g, "-")}`; const screenshotPath = `__webview__${pages[pageIndex].replace(/\//g, "-")}`;
// web in webview screenshot // web in webview screenshot
// 加载依赖页面 // 加载依赖页面
...@@ -212,36 +212,36 @@ describe("shot-compare", () => { ...@@ -212,36 +212,36 @@ describe("shot-compare", () => {
isCustomNavigationBar, isCustomNavigationBar,
}); });
const startTime = Date.now(); const startTime = Date.now();
await page.waitFor(async () => { await page.waitFor(async () => {
const isLoaded = await page.data("isLoaded"); const isLoaded = await page.data("isLoaded");
return isLoaded || Date.now() - startTime > 3000; return isLoaded || Date.now() - startTime > 3000;
}); });
await page.waitFor(4500); await page.waitFor(800);
// web 端非 adb 截图时设置 offsetY 移除导航栏 // web 端非 adb 截图时设置 offsetY 移除导航栏
const webSnapshot = await program.screenshot({ const webSnapshot = await program.screenshot({
...screenshotParams, ...screenshotParams,
id: 'webview-screenshot-comparison', id: 'webview-screenshot-comparison',
offsetY: `${isCustomNavigationBar ? 0 : 44}` offsetY: `${isCustomNavigationBar ? 0 : 44}`
}); });
expect(webSnapshot).toMatchImageSnapshot({ expect(webSnapshot).toMatchImageSnapshot({
customSnapshotIdentifier() { customSnapshotIdentifier() {
return screenshotPath; return screenshotPath;
}, },
}); });
// app-android page screenshot comparison // app-android page screenshot comparison
const navigateMethod = pages[pageIndex].startsWith("pages/tab-bar") ? const navigateMethod = pages[pageIndex].startsWith("pages/tab-bar") ?
"switchTab" : "switchTab" :
"navigateTo"; "navigateTo";
page = await program[navigateMethod](`/${pages[pageIndex]}`); page = await program[navigateMethod](`/${pages[pageIndex]}`);
await page.waitFor(500); await page.waitFor(500);
const appAndroidSnapshot = await program.screenshot(screenshotParams); const appAndroidSnapshot = await program.screenshot(screenshotParams);
expect(appAndroidSnapshot).toMatchImageSnapshot({ expect(appAndroidSnapshot).toMatchImageSnapshot({
customSnapshotIdentifier() { customSnapshotIdentifier() {
return screenshotPath; return screenshotPath;
}, },
}); });
}); });
}); });
\ No newline at end of file
...@@ -27,33 +27,15 @@ ...@@ -27,33 +27,15 @@
this.webviewContext = uni.createWebviewContext('webview-screenshot-comparison', this) this.webviewContext = uni.createWebviewContext('webview-screenshot-comparison', this)
}, },
methods: { methods: {
customNavigationBarPageAppendWebHeadPlaceholder() {
if (this.src.indexOf('pages/template/navbar-lite/navbar-lite') > -1) {
this.webviewContext?.evalJS(`
const uniNavbar = document.querySelector('.uni-navbar');
uniNavbar.style.paddingTop = '${this.statusBarHeight}px';
`)
} else if (this.src.indexOf('pages/template/scroll-fold-nav/scroll-fold-nav') > -1) {
this.webviewContext?.evalJS(`
const heightSeat = document.querySelector('.height-seat');
heightSeat.style.height = '125px';
heightSeat.style.backgroundColor = '#f0f8ff';
const topBox = document.querySelector('.top-box');
topBox.style.top = '35px';
`)
}
},
loaded() { loaded() {
this.isLoaded = true this.isLoaded = true
this.customNavigationBarPageAppendWebHeadPlaceholder();
}, },
error(event : WebViewErrorEvent) { error(event : WebViewErrorEvent) {
console.log('webview load error', JSON.stringify(event.detail)); console.log('webview load error', JSON.stringify(event.detail));
}, },
getWindowInfo() { getWindowInfo() {
const res = uni.getWindowInfo(); const res = uni.getWindowInfo();
// 获取状态栏+导航栏高度, 供截图对比使用 // 获取状态栏, 供截图对比使用
this.statusBarHeight = res.statusBarHeight; this.statusBarHeight = res.statusBarHeight;
}, },
getDeviceInfo: function () { getDeviceInfo: function () {
......
...@@ -152,7 +152,7 @@ describe("shot-compare", () => { ...@@ -152,7 +152,7 @@ describe("shot-compare", () => {
// set webview-screenshot page baseSrc // set webview-screenshot page baseSrc
baseSrc = baseSrc =
process.env.UNI_WEB_SERVICE_URL ? `${process.env.UNI_WEB_SERVICE_URL}/#/` : process.env.UNI_WEB_SERVICE_URL ? `${process.env.UNI_WEB_SERVICE_URL}/#/` :
"http://192.168.31.223:5173/#/"; "http://test.dcloud.io/unix_h5_build/98_dev_hello-uvue/#/";
page.setData({ page.setData({
baseSrc, baseSrc,
}); });
...@@ -208,8 +208,7 @@ describe("shot-compare", () => { ...@@ -208,8 +208,7 @@ describe("shot-compare", () => {
const isLoaded = await page.data("isLoaded"); const isLoaded = await page.data("isLoaded");
return isLoaded || Date.now() - startTime > 3000; return isLoaded || Date.now() - startTime > 3000;
}); });
await page.waitFor(800);
await page.waitFor(5000)
// web 端非 adb 截图时设置 offsetY 移除导航栏 // web 端非 adb 截图时设置 offsetY 移除导航栏
const webSnapshot = await program.screenshot({ const webSnapshot = await program.screenshot({
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
}, },
getWindowInfo() { getWindowInfo() {
const res = uni.getWindowInfo(); const res = uni.getWindowInfo();
// 获取状态栏+导航栏高度, 供截图对比使用 // 获取状态栏, 供截图对比使用
this.headerHeight = res.statusBarHeight; this.headerHeight = res.statusBarHeight;
}, },
getDeviceInfo: function () { getDeviceInfo: function () {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册