Skip to content

Commit

Permalink
feat(e2e): support event: input,touchstart,touchmove,touchend
Browse files Browse the repository at this point in the history
re #80
  • Loading branch information
fanniehuang committed Sep 17, 2020
1 parent 5a26dc4 commit c432a41
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
14 changes: 7 additions & 7 deletions packages/wxa-cli/scripts/buildLib.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# npx webpack "./lib/shim/promise.finally.js" --mode production --env.platform=node -o ./lib-dist/es/promise.finally.js

# cp -R ./src/tester/wxa-e2eTest ./lib-dist/wxa-e2eTest
rm -f ./dist/tester/wxa-e2eTest/e2eRecord2jsTpl.ejs
rm -rf ./lib-dist/wxa-e2eTest
mkdir ./lib-dist/wxa-e2eTest
ln ./src/tester/wxa-e2eTest/e2eTestSuite.js ./lib-dist/wxa-e2eTest/e2eTestSuite.js
ln ./src/tester/wxa-e2eTest/e2eRecordBtn.wxa ./lib-dist/wxa-e2eTest/e2eRecordBtn.wxa
ln ./src/tester/wxa-e2eTest/e2eRecord2jsTpl.ejs ./dist/tester/wxa-e2eTest/e2eRecord2jsTpl.ejs

echo $MODE;
if test "$MODE" = 'dev'
then
npx babel ./lib/regenerator-runtime/runtime.js --out-dir ./lib-dist/regenerator-runtime/runtime.js --source-maps
Expand All @@ -19,9 +25,3 @@ else

npx babel ./lib/wxa_wrap.js --out-dir ./lib-dist/
fi

cp ./src/tester/wxa-e2eTest/e2eRecord2jsTpl.ejs ./dist/tester/wxa-e2eTest
mkdir ./lib-dist/wxa-e2eTest
cp ./src/tester/wxa-e2eTest/e2eTestSuite.js ./lib-dist/wxa-e2eTest/
cp ./src/tester/wxa-e2eTest/e2eRecordBtn.wxa ./lib-dist/wxa-e2eTest/
echo $MODE;
2 changes: 1 addition & 1 deletion packages/wxa-cli/src/tester/domWalker.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class XMLManager {
constructor(mdl, scheduler) {
this.mdl = mdl;
this.scheduler = scheduler;
this.supportEvents = ['tap', 'longpress', 'change'];
this.supportEvents = ['tap', 'longpress', 'change', 'input', 'touchstart', 'touchmove', 'touchend'];
}

parse(xml) {
Expand Down
8 changes: 7 additions & 1 deletion packages/wxa-cli/src/tester/wxa-e2eTest/e2eRecord2jsTpl.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,16 @@ describe('==== <%= name %> ====', () => {
}
await page.waitFor('.<%= item.id %>');
console.log(JSON.stringify(page.path));
element = await page.$('.<%= item.id %>')
<% if (!!~['tap', 'longpress'].indexOf(item.event)) { %>
await element.<%= item.event%>();
<% } else if (!!~['input'].indexOf(item.event)) { %>
await element.<%= item.event%>("<%= item.detail.value %>");
<% } else if (!!~['touchstart', 'touchmove', 'touchend'].indexOf(item.event)) { %>
await element.<%= item.event%>({
touches: <%-JSON.stringify(item.touches)%>,
changedTouches: <%-JSON.stringify(item.changedTouches)%>
});
<% } else { %>
await element.trigger('<%=item.event%>', <%-JSON.stringify(item.detail)%>);
<% } %>
Expand Down
17 changes: 14 additions & 3 deletions packages/wxa-cli/src/tester/wxa-e2eTest/e2eTestSuite.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,12 @@ const addRecord = function(type, ...args) {
if (shouldRecord.bind(this)(type, ...args)) {
let pages = getCurrentPages();
state.record.push({
...e,
page: pages[pages.length - 1].route,
event: type,
id,
timeStamp: +new Date(),
detail: {
...e.detail,
},

});
console.log('e2eRecord:', e)
}
Expand Down Expand Up @@ -94,6 +93,18 @@ const wrapEvent = {
// input事件 自动化测试不支持,回放要用callMethod
addRecord.bind(this)('input', ...args);
},
$$e2e_touchstart(...args) {
// input事件 自动化测试不支持,回放要用callMethod
addRecord.bind(this)('touchstart', ...args);
},
$$e2e_touchmove(...args) {
// input事件 自动化测试不支持,回放要用callMethod
addRecord.bind(this)('touchmove', ...args);
},
$$e2e_touchend(...args) {
// input事件 自动化测试不支持,回放要用callMethod
addRecord.bind(this)('touchend', ...args);
},
};

// 将替换事件挂载到vm上
Expand Down

0 comments on commit c432a41

Please sign in to comment.