You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by da...@apache.org on 2017/07/24 12:37:03 UTC
[11/50] incubator-weex git commit: * [html5] fix collectStat test case
* [html5] fix collectStat test case
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/fdad32f4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/fdad32f4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/fdad32f4
Branch: refs/heads/0.16-dev
Commit: fdad32f47e4b7049aa30bdfb615e3a0719e5bb9d
Parents: 9c84d23
Author: erha19 <fa...@gmail.com>
Authored: Tue Jul 18 17:29:19 2017 +0800
Committer: erha19 <fa...@gmail.com>
Committed: Tue Jul 18 17:29:19 2017 +0800
----------------------------------------------------------------------
html5/test/render/vue/utils/lazyload.js | 82 ++++++++++++++++++----------
html5/test/render/vue/utils/perf.js | 12 ++++
2 files changed, 64 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/fdad32f4/html5/test/render/vue/utils/lazyload.js
----------------------------------------------------------------------
diff --git a/html5/test/render/vue/utils/lazyload.js b/html5/test/render/vue/utils/lazyload.js
index 6f574d4..b390468 100644
--- a/html5/test/render/vue/utils/lazyload.js
+++ b/html5/test/render/vue/utils/lazyload.js
@@ -16,33 +16,44 @@
* specific language governing permissions and limitations
* under the License.
*/
-import * as lazyload from '../../../../render/vue/utils/lazyload'
+import {
+ fireLazyload,
+ getThrottleLazyload
+} from '../../../../render/vue/utils/lazyload'
describe('utils', function () {
describe('lazyload', function () {
const validImageTransparent = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'
const validImageBlack = 'data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs='
const invalidImage = 'data:image/jpeg;base64,'
before(() => {
+ // for test collectStat in utils/perf.js
+ window.performance = {
+ getEntries: () => {
+ return [{
+ entryType: 'resource',
+ name: 'weex-invalid.jpg'
+ }, {
+ entryType: 'resource',
+ name: 'weex-test.jpg'
+ }]
+ }
+ }
+ window.history.pushState(null, null, '?_wx_tpl=./weex-test.jpg')
this.weexEmit = sinon.stub(window.weex, 'emit')
- // this.clock = sinon.useFakeTimers()
})
after(() => {
this.weexEmit.restore()
- // this.clock.restore()
})
it('fireLazyload', (done) => {
- const {
- fireLazyload
- } = lazyload
const node = document.createElement('figure')
const urlReg = /http(s)?:\/\/(\S+):(\d+)\//
const IMG_REC_INDENT = 500
node.setAttribute('img-src', invalidImage)
node.setAttribute('img-placeholder', validImageBlack)
node.style.height = '10px'
- // coverage branch if (item._src_loading)
+ // coverage branch if (item._src_loading)
node._src_loading = true
- // coverage branch if (Array.isArray(el))
+ // coverage branch if (Array.isArray(el))
fireLazyload([node])
node._src_loading = false
fireLazyload(node, true)
@@ -56,29 +67,40 @@ describe('utils', function () {
}, IMG_REC_INDENT)
}, 100)
})
- it('getThrottleLazyload', (done) => {
- const {
- getThrottleLazyload
- } = lazyload
- const node = document.createElement('figure')
- const urlReg = /http(s)?:\/\/(\S+):(\d+)\//
- const wait = 100
- const IMG_REC_INDENT = 500
- node.style.height = '10px'
- node.setAttribute('img-src', validImageTransparent)
- node.setAttribute('img-placeholder', validImageBlack)
- document.body.appendChild(node)
- window._first_screen_detected = false
- getThrottleLazyload(wait, node)()
- setTimeout(() => {
- expect(node.style.backgroundImage.replace(urlReg, '')).to.be.equal('url(' + validImageTransparent + ')')
+ describe('getThrottleLazyload', () => {
+ it('should use default value while parmas is undefined', (done) => {
+ const IMG_REC_INDENT = 500
+ window._first_screen_detected = true
+ getThrottleLazyload()()
setTimeout(() => {
- expect(this.weexEmit.withArgs('renderfinish').callCount).to.be.equal(2)
- expect(this.weexEmit.withArgs('firstscreenfinish').callCount).to.be.equal(1)
- done()
- document.body.removeChild(node)
- }, IMG_REC_INDENT)
- }, 100)
+ setTimeout(() => {
+ expect(this.weexEmit.withArgs('renderfinish').callCount).to.be.equal(1)
+ expect(this.weexEmit.withArgs('firstscreenfinish').callCount).to.be.equal(0)
+ done()
+ }, IMG_REC_INDENT)
+ }, 16)
+ })
+ it('should be work', (done) => {
+ const node = document.createElement('figure')
+ const urlReg = /http(s)?:\/\/(\S+):(\d+)\//
+ const wait = 100
+ const IMG_REC_INDENT = 500
+ node.style.height = '10px'
+ node.setAttribute('img-src', validImageTransparent)
+ node.setAttribute('img-placeholder', validImageBlack)
+ document.body.appendChild(node)
+ window._first_screen_detected = false
+ getThrottleLazyload(wait, node)()
+ setTimeout(() => {
+ expect(node.style.backgroundImage.replace(urlReg, '')).to.be.equal('url(' + validImageTransparent + ')')
+ setTimeout(() => {
+ expect(this.weexEmit.withArgs('renderfinish').callCount).to.be.equal(2)
+ expect(this.weexEmit.withArgs('firstscreenfinish').callCount).to.be.equal(1)
+ done()
+ document.body.removeChild(node)
+ }, IMG_REC_INDENT)
+ }, 100)
+ })
})
})
})
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/fdad32f4/html5/test/render/vue/utils/perf.js
----------------------------------------------------------------------
diff --git a/html5/test/render/vue/utils/perf.js b/html5/test/render/vue/utils/perf.js
index 824daa3..c582334 100644
--- a/html5/test/render/vue/utils/perf.js
+++ b/html5/test/render/vue/utils/perf.js
@@ -44,6 +44,18 @@ describe('utils', function () {
this.weexEmit.restore()
})
it('collectStatPerf', () => {
+ window.performance = {
+ getEntries: () => {
+ return [{
+ entryType: 'resource',
+ name: 'weex-invalid.jpg'
+ }, {
+ entryType: 'resource',
+ name: 'weex-test.jpg'
+ }]
+ }
+ }
+ window.history.pushState(null, null, '?_wx_tpl=./weex-test.jpg')
const time = (new Date()).getTime()
collectStatPerf('totalTime', time)
expect(collectStatPerf).to.be.a('function')