提交 7a0f4289 编写于 作者: DCloud_iOS_WZT's avatar DCloud_iOS_WZT

Merge branch 'dev' of https://gitcode.net/dcloud/hello-uni-app-x into dev

// 自动化测试 const path = require("path");
const path = require('path'); const fs = require("fs");
const {
configureToMatchImageSnapshot const { configureToMatchImageSnapshot } = require("jest-image-snapshot");
} = require('jest-image-snapshot');
const hbuilderx_version = process.env.HX_Version;
const hbuilderx_version = process.env.HX_Version const uniTestPlatformInfo = process.env.uniTestPlatformInfo
const uniTestPlatformInfo = process.env.uniTestPlatformInfo ? process.env.uniTestPlatformInfo.replace(/\s/g,'_') : '' ? process.env.uniTestPlatformInfo.replace(/\s/g, "_")
const folderName = `__image_snapshots__/${hbuilderx_version}/__${uniTestPlatformInfo}__` : "";
let environment = 'official' const folderName = `__image_snapshots__/${hbuilderx_version}/__${uniTestPlatformInfo}__`;
if(hbuilderx_version.includes('dev')){ let environment = "official";
environment = 'dev' if (hbuilderx_version.includes("dev")) {
}else if(hbuilderx_version.includes('alpha')){ environment = "dev";
environment = 'alpha' } else if (hbuilderx_version.includes("alpha")) {
} environment = "alpha";
const baseFolderName = `__image_snapshots__/base/${environment}/__${uniTestPlatformInfo}__` }
const baseFolderName = `__image_snapshots__/base/${environment}/__${uniTestPlatformInfo}__`;
expect.extend({ expect.extend({
toMatchImageSnapshot: configureToMatchImageSnapshot({ toMatchImageSnapshot: configureToMatchImageSnapshot({
customSnapshotIdentifier(args) { customSnapshotIdentifier(args) {
return args.currentTestName.replace(/\//g, '-').replace(' ', '-'); return args.currentTestName.replace(/\//g, "-").replace(" ", "-");
}, },
customSnapshotsDir: path.join(__dirname, baseFolderName), customSnapshotsDir: path.join(__dirname, baseFolderName),
customDiffDir: path.join(__dirname, `${folderName}/`, 'diff'), customDiffDir: path.join(__dirname, `${folderName}/`, "diff"),
}), }),
toSaveSnapshot,
toSaveImageSnapshot,
}); });
function toSaveSnapshot(received, { customSnapshotsDir, fileName } = {}) {
const { testPath, currentTestName } = this;
const SNAPSHOTS_DIR = "__file_snapshots__";
const snapshotDir =
process.env.saveSnapshotDir ||
createSnapshotDir({
customSnapshotsDir,
testPath,
SNAPSHOTS_DIR,
});
const _fileName = createFileName({
fileName,
testPath,
currentTestName,
});
const filePath = path.join(snapshotDir, _fileName);
let message = () => `${currentTestName} toSaveSnapshot success`;
let pass = true;
try {
checkSnapshotDir(snapshotDir);
fs.writeFileSync(filePath, received);
} catch (e) {
console.log("toSaveSnapshot fail", e);
message = () => e.message;
pass = false;
}
return {
message,
pass,
};
}
function toSaveImageSnapshot(
received,
{ customSnapshotsDir, customSnapshotIdentifier } = {}
) {
const { testPath, currentTestName } = this;
const SNAPSHOTS_DIR = "__image_snapshots__";
const snapshotDir =
process.env.saveImageSnapshotDir ||
createSnapshotDir({
customSnapshotsDir,
testPath,
SNAPSHOTS_DIR,
});
const _fileName = createFileName({
fileName: customSnapshotIdentifier ? customSnapshotIdentifier() : "",
testPath,
currentTestName,
fileType: "png",
});
const filePath = path.join(snapshotDir, _fileName);
let message = () => `${currentTestName} toSaveImageSnapshot success`;
let pass = true;
try {
checkSnapshotDir(snapshotDir);
fs.writeFileSync(filePath, Buffer.from(received, "base64"));
} catch (e) {
console.log("toSaveImageSnapshot fail", e);
message = () => e.message;
pass = false;
}
return {
message,
pass,
};
}
function createSnapshotDir({ customSnapshotsDir, testPath, SNAPSHOTS_DIR }) {
return customSnapshotsDir || path.join(path.dirname(testPath), SNAPSHOTS_DIR);
}
function createFileName({ fileName, testPath, currentTestName, fileType }) {
return (
fileName ||
createSnapshotIdentifier({
testPath,
currentTestName,
fileType,
})
);
}
function createSnapshotIdentifier({
testPath,
currentTestName,
fileType = "txt",
}) {
const snapshotIdentifier = kebabCase(
`${path.basename(testPath)}-${currentTestName}`
);
const counter = timesCalled.get(`${snapshotIdentifier}-${fileType}`) || 1;
timesCalled.set(`${snapshotIdentifier}-${fileType}`, counter + 1);
return `${snapshotIdentifier}-${counter}.${fileType}`;
}
function kebabCase(str) {
return str
.replaceAll(/([a-z])([A-Z])/g, "$1-$2")
.replaceAll(/\s+/g, "-")
.replaceAll(/_+/g, "-")
.replaceAll(/\/+/g, "-")
.replaceAll(/\.+/g, "-")
.toLowerCase();
}
function checkSnapshotDir(snapshotDir) {
if (!fs.existsSync(snapshotDir)) {
fs.mkdirSync(snapshotDir, {
recursive: true,
});
}
}
const timesCalled = new Map();
...@@ -652,18 +652,18 @@ ...@@ -652,18 +652,18 @@
"navigationBarTitleText": "get-window-info" "navigationBarTitleText": "get-window-info"
} }
}, },
// #ifdef APP-ANDROID
{ {
"path": "pages/API/facial-recognition-verify/facial-recognition-verify", "path": "pages/API/element-draw/element-draw",
"style": { "style": {
"navigationBarTitleText": "", "navigationBarTitleText": "getDrawableContext",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, },
// #ifdef APP-ANDROID
{ {
"path": "pages/API/element-draw/element-draw", "path": "pages/API/facial-recognition-verify/facial-recognition-verify",
"style": { "style": {
"navigationBarTitleText": "getDrawableContext", "navigationBarTitleText": "",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, },
...@@ -1153,13 +1153,13 @@ ...@@ -1153,13 +1153,13 @@
} }
}, },
// #endif // #endif
// #ifdef APP-ANDROID
{ {
"path": "pages/template/calendar/calendar", "path": "pages/template/calendar/calendar",
"style": { "style": {
"navigationBarTitleText": "日历" "navigationBarTitleText": "日历"
} }
}, },
// #ifdef APP-ANDROID
{ {
"path": "pages/template/schema/schema", "path": "pages/template/schema/schema",
"style": { "style": {
......
<template> <template>
<scroll-view style="flex:1;" :refresher-enabled="true" :refresher-triggered="refresherTriggered" <scroll-view style="flex:1;" :refresher-enabled="true" :refresher-triggered="refresherTriggered"
refresher-default-style="none" @refresherpulling="onRefresherpulling" @refresherrefresh="onRefresherrefresh" @refresherrestore="onRefreshrestore"> refresher-default-style="none" @refresherpulling="onRefresherpulling" @refresherrefresh="onRefresherrefresh" @refresherrestore="onRefreshrestore" refresher-max-drag-distance="200px">
<view style="height: 25px;"></view> <view style="height: 25px;"></view>
<view v-for="i in 20" class="content-item"> <view v-for="i in 20" class="content-item">
<text class="text">item-{{i}}</text> <text class="text">item-{{i}}</text>
......
...@@ -87,7 +87,7 @@ export default { ...@@ -87,7 +87,7 @@ export default {
// 点击具体的日历格子 // 点击具体的日历格子
clickGrid (x: number, y: number) { clickGrid (x: number, y: number) {
// 小格子数组 // 小格子数组
const gridArray = this.$coords const gridArray = this.$data.$coords
// 遍历小格子数组,找到最接近点击坐标的小格子 // 遍历小格子数组,找到最接近点击坐标的小格子
for (let i = 0; i < gridArray.length; i++) { for (let i = 0; i < gridArray.length; i++) {
...@@ -103,7 +103,7 @@ export default { ...@@ -103,7 +103,7 @@ export default {
if (is_select) { if (is_select) {
const data = grid.data const data = grid.data
this.timeData = this.$calendar.getDateInfo(data.fullDate) this.timeData = this.$data.$calendar.getDateInfo(data.fullDate)
this.drawWeek(this.weeks, grid.data.fullDate) this.drawWeek(this.weeks, grid.data.fullDate)
} }
} }
...@@ -111,10 +111,10 @@ export default { ...@@ -111,10 +111,10 @@ export default {
// 切换上个月 // 切换上个月
preDate () { preDate () {
const fulldate = this.timeData.fullDate const fulldate = this.timeData.fullDate
const time = this.$calendar.getDate(fulldate, -1, 'month') const time = this.$data.$calendar.getDate(fulldate, -1, 'month')
this.timeData = this.$calendar.getDateInfo(time.fullDate) this.timeData = this.$data.$calendar.getDateInfo(time.fullDate)
this.weeks = this.$calendar.getWeeks(time.fullDate) this.weeks = this.$data.$calendar.getWeeks(time.fullDate)
// 重新绘制日历 // 重新绘制日历
this.drawWeek(this.weeks, time.fullDate) this.drawWeek(this.weeks, time.fullDate)
...@@ -123,20 +123,20 @@ export default { ...@@ -123,20 +123,20 @@ export default {
// 切换下个他 // 切换下个他
nextDate () { nextDate () {
const fulldate = this.timeData.fullDate const fulldate = this.timeData.fullDate
const time = this.$calendar.getDate(fulldate, 1, 'month') const time = this.$data.$calendar.getDate(fulldate, 1, 'month')
this.timeData = this.$calendar.getDateInfo(time.fullDate) this.timeData = this.$data.$calendar.getDateInfo(time.fullDate)
this.weeks = this.$calendar.getWeeks(time.fullDate) this.weeks = this.$data.$calendar.getWeeks(time.fullDate)
// 重新绘制日历 // 重新绘制日历
this.drawWeek(this.weeks, time.fullDate) this.drawWeek(this.weeks, time.fullDate)
}, },
// 回到今天 // 回到今天
gotoToday () { gotoToday () {
const time = this.$calendar.getDate() const time = this.$data.$calendar.getDate()
this.timeData = this.$calendar.getDateInfo(time.fullDate) this.timeData = this.$data.$calendar.getDateInfo(time.fullDate)
this.weeks = this.$calendar.getWeeks(time.fullDate) this.weeks = this.$data.$calendar.getWeeks(time.fullDate)
// 重新绘制日历 // 重新绘制日历
this.drawWeek(this.weeks, time.fullDate) this.drawWeek(this.weeks, time.fullDate)
...@@ -183,7 +183,7 @@ export default { ...@@ -183,7 +183,7 @@ export default {
const one_height = height / week_len const one_height = height / week_len
if (time !== '') { if (time !== '') {
this.$coords = [] this.$data.$coords = []
ctx.reset() ctx.reset()
} }
...@@ -232,7 +232,7 @@ export default { ...@@ -232,7 +232,7 @@ export default {
height: day_height, height: day_height,
data: day_item data: day_item
} }
this.$coords.push(coords) this.$data.$coords.push(coords)
// } // }
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
@refresherrefresh="onRefresherrefresh" @refresherrefresh="onRefresherrefresh"
@refresherrestore="onRefreshrestore" @refresherrestore="onRefreshrestore"
:refresher-threshold="refresherThreshold" :refresher-threshold="refresherThreshold"
refresher-max-drag-distance="200px"
> >
<view v-for="i in 20" class="content-item"> <view v-for="i in 20" class="content-item">
<text class="text">item-{{i}}</text> <text class="text">item-{{i}}</text>
......
describe('toSaveSnapshot & toSaveImageSnapshot template', () => {
beforeAll(async () => {
let page = await program.reLaunch('/pages/tabBar/component');
await page.waitFor(1000);
})
it('test toSaveSnapshot 1', async () => {
const text1 = 'test-toSaveSnapshot-1-1-' + Date.now()
expect(text1).toSaveSnapshot()
const text2 = 'test-toSaveSnapshot-1-2-' + Date.now()
expect(text2).toSaveSnapshot()
})
it('test toSaveSnapshot 2', async () => {
const text1 = 'test-toSaveSnapshot-2-1-' + Date.now()
expect(text1).toSaveSnapshot({
customSnapshotsDir: `./customDir/__file_snapshots__`,
fileName: 'test-toSaveSnapshot-2-1.txt'
})
const text2 = 'test-toSaveSnapshot-2-2-' + Date.now()
expect(text2).toSaveSnapshot({
customSnapshotsDir: './customDir/__file_snapshots__'
})
const text3 = 'test-toSaveSnapshot-2-3-' + Date.now()
expect(text3).toSaveSnapshot({
fileName: 'test-toSaveSnapshot-2-3.json'
})
})
it('test toSaveImageSnapshot 1', async () => {
const img1 = await program.screenshot();
expect(img1).toSaveImageSnapshot()
const img2 = await program.screenshot();
expect(img2).toSaveImageSnapshot()
})
it('test toSaveImageSnapshot 2', async () => {
const img1 = await program.screenshot();
expect(img1).toSaveImageSnapshot({
customSnapshotsDir: './customDir/__image_snapshots__',
customSnapshotIdentifier() {
return 'test-toSaveImageSnapshot-2-1.png';
},
})
const img2 = await program.screenshot();
expect(img2).toSaveImageSnapshot({
customSnapshotsDir: './customDir/__image_snapshots__',
})
const img3 = await program.screenshot();
expect(img3).toSaveImageSnapshot({
customSnapshotIdentifier() {
return 'test-toSaveImageSnapshot-2-3.png';
},
})
})
});
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册