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/20 08:29:39 UTC

[09/50] incubator-weex git commit: + [html5] rename filename and add more unit test

+ [html5] rename filename and add more unit test


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/7c42710b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/7c42710b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/7c42710b

Branch: refs/heads/0.15-dev
Commit: 7c42710b9e883b31ab4f8eee532048f42e428d6d
Parents: 9591b24
Author: erha19 <fa...@gmail.com>
Authored: Mon Jul 10 15:06:06 2017 +0800
Committer: erha19 <fa...@gmail.com>
Committed: Mon Jul 10 15:06:06 2017 +0800

----------------------------------------------------------------------
 html5/test/render/vue/utils/perf.js | 124 +++++++++++++++++++++++++++++++
 1 file changed, 124 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7c42710b/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
new file mode 100644
index 0000000..87ee213
--- /dev/null
+++ b/html5/test/render/vue/utils/perf.js
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License") you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import {
+  collectStatPerf,
+  tagFirstScreen,
+  tagImg,
+  tagBeforeCreate,
+  tagRootMounted,
+  tagMounted,
+  tagBeforeUpdate,
+  tagUpdated,
+  tagBegin,
+  tagEnd
+} from '../../../../render/vue/utils/perf'
+describe('utils', function () {
+  describe('pref', function () {
+    before(function () {
+      this.clock = sinon.useFakeTimers()
+    })
+    after(function () {
+      this.clock.restore()
+    })
+    it('collectStatPerf', function () {
+      const perf = window._weex_perf
+      const time = (new Date()).getTime()
+      collectStatPerf('totalTime', time)
+      expect(collectStatPerf).to.be.a('function')
+      expect(perf.stat['totalTime']).to.be.equal(time)
+      expect(collectStatPerf()).to.be.a('undefined')
+    })
+    it('tagFirstScreen', function () {
+      const weexEmit = sinon.stub(window.weex, 'emit')
+      expect(tagFirstScreen).to.be.a('function')
+      tagFirstScreen()
+      expect(weexEmit.withArgs('renderfinish').callCount).to.be.equal(1)
+      expect(weexEmit.withArgs('firstscreenfinish').callCount).to.be.equal(0)
+      window._first_screen_detected = false
+      tagFirstScreen()
+      expect(weexEmit.withArgs('renderfinish').callCount).to.be.equal(2)
+      expect(weexEmit.withArgs('firstscreenfinish').callCount).to.be.equal(1)
+      weexEmit.restore()
+    })
+    it('tagImg', function () {
+      const weexEmit = sinon.stub(window.weex, 'emit')
+      tagImg()
+      this.clock.tick(500)
+      expect(weexEmit.withArgs('renderfinish').callCount).to.be.equal(1)
+      expect(tagImg).to.be.a('function')
+      weexEmit.restore()
+    })
+    it('tagBeforeCreate', function () {
+      const perf = window._weex_perf
+      tagBeforeCreate()
+      this.clock.tick(25)
+      const time = perf.earliestBeforeCreates[perf.earliestBeforeCreates.length - 1]
+      expect(time).to.be.a('number')
+      expect(perf.earliestBeforeCreates).to.have.lengthOf(1)
+      expect(tagBeforeCreate).to.be.a('function')
+    })
+    it('tagRootMounted', function () {
+      const perf = window._weex_perf
+      tagRootMounted()
+      const time = perf.latestMounts[perf.latestMounts.length - 1]
+      expect(time).to.be.a('number')
+      expect(perf.stat['totalTime']).to.be.equal(parseInt(time))
+      expect(tagRootMounted).to.be.a('function')
+    })
+    it('tagMounted', function () {
+      const perf = window._weex_perf
+      perf.firstAllMountedTime = 0
+      tagMounted()
+      this.clock.tick(25)
+      expect(tagMounted).to.be.a('function')
+      expect(perf.latestMounts).to.have.lengthOf(2)
+      expect(perf.createTime).to.have.lengthOf(1)
+      expect(perf.createTime[perf.createTime.length - 1]).to.have.all.keys('start', 'end', 'duration')
+      expect(perf.firstAllMountedTime).to.be.above(0)
+    })
+    it('tagBeforeUpdate', function () {
+      const perf = window._weex_perf
+      tagBeforeUpdate()
+      this.clock.tick(25)
+      expect(tagBeforeUpdate).to.be.a('function')
+      expect(perf.earliestBeforeUpdates).to.have.lengthOf(1)
+    })
+    it('tagUpdated', function () {
+      const perf = window._weex_perf
+      tagUpdated()
+      this.clock.tick(25)
+      expect(tagUpdated).to.be.a('function')
+      expect(perf.latestUpdates).to.have.lengthOf(1)
+      expect(perf.updateTime).to.have.lengthOf(1)
+      expect(perf.updateTime[perf.updateTime.length - 1]).to.have.all.keys('start', 'end', 'duration')
+    })
+    it('tagBegin', function () {
+      const name = 'test'
+      tagBegin(name)
+      expect(tagBegin).to.be.a('function')
+    })
+    it('tagEnd', function () {
+      const perf = window._weex_perf
+      const name = 'test'
+      tagEnd(name)
+      expect(tagEnd).to.be.a('function')
+      expect(perf.time[name]).to.be.a('number')
+    })
+  })
+})