@makechart/viewer 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Change Logs
2
2
 
3
+ ## v0.0.6
4
+
5
+ - dash cases load the panel block from `@plotdb/dash`'s `block/panel/index.html` ( versioned in the package )
6
+ instead of `web/static/initiative/1st/...`, a generated demo path that has been renamed
7
+ - add `timeout` ( case or suite, default 30000ms ): a case that takes longer is an `error` naming the stage
8
+ it stopped at ( `load`, `render` or `step n` ), instead of hanging the whole run
9
+ - `settle` also resolves by a timer after `limit`, in case `requestAnimationFrame` stops firing
10
+
11
+
3
12
  ## v0.0.5
4
13
 
5
14
  - `block`: the chart's block data ( e.g. a map's `{level: 'town'}` ), on the suite or on a case ( the case
package/README.md CHANGED
@@ -80,8 +80,12 @@ engine 自己起一個 server,前端依賴走與 makechart 相同的路徑 `/a
80
80
  - `skip: true` 略過。`suite.chart` 預設是 package.json 的 name。
81
81
  - `block`:圖的 block data ( 例如地圖的 `{level: \town}` ),suite 與 case 都可以給,case 的優先。
82
82
  playground 用網址參數 `?block=<json>`。
83
+ - `timeout`:整個 case ( 載入、第一次畫完、所有 step ) 超過這麼多 ms 就算 `error`,訊息會寫停在哪一步。
84
+ suite 與 case 都可以給,預設 30000。
83
85
 
84
- 資料請用固定種子產生,否則每次跑都不一樣。
86
+ 資料請用固定種子產生,否則每次跑都不一樣。在 step 裡 ( 執行時 ) 才產生的資料要用自己的種子
87
+ ( `mctest.random seed` ),不要跟載入時共用同一個產生器:共用的話數字會隨之前跑過哪些 case 而變,
88
+ 單獨跑 ( `-g` ) 跟全部跑的結果會不同。
85
89
 
86
90
 
87
91
  ## 怎麼比對
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makechart/viewer",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "makechart 圖表的 test suite engine: 用不同資料、參數跑圖, 比對輸出 snapshot, 並以 @plotdb/dash 測 crossfilter",
5
5
  "homepage": "https://github.com/makechart/viewer",
6
6
  "repository": {
package/src/suite.ls CHANGED
@@ -161,22 +161,30 @@ mctest.split-snaps = (text) ->
161
161
  # 150ms 後才發 filter, board 再重畫 ). 期間每一幀都 flush, 有 anim 的圖補間會直接跳到終點.
162
162
  # list 是回傳目前所有圖的 function ( dash 的 panel 圖是非同步建立的, 每次都重抓 ),
163
163
  # 新抓到的圖一律切 manual. 沒有 anim 的圖 ( 還在用 d3 transition ) 只能靠 quiet 等它跑完
164
+ # rAF 停掉時 ( 例如頁面被當成在背景 ) tick 不會再跑, 所以另用 timer 保底, limit 一定會生效
164
165
  settle = (root, list, quiet = 250, limit = 10000) ->
165
166
  new Promise (res) ->
166
167
  last = performance.now!
167
168
  t0 = last
168
169
  mo = new MutationObserver -> last := performance.now!
169
170
  mo.observe root, {subtree: true, childList: true, attributes: true, characterData: true}
171
+ done = false
172
+ finish = ->
173
+ if done => return
174
+ done := true
175
+ mo.disconnect!
176
+ clearTimeout timer
177
+ res!
178
+ timer = setTimeout finish, limit + 1000
170
179
  tick = ->
180
+ if done => return
171
181
  charts = list!filter -> it
172
182
  charts.map ->
173
183
  if !it.anim => return
174
184
  if !it.anim._manual => it.anim.manual true
175
185
  it.anim.flush!
176
186
  now = performance.now!
177
- if now - last >= quiet or now - t0 > limit =>
178
- mo.disconnect!
179
- return res!
187
+ if now - last >= quiet or now - t0 > limit => return finish!
180
188
  requestAnimationFrame tick
181
189
  requestAnimationFrame tick
182
190
 
@@ -223,7 +231,20 @@ load-dash = ->
223
231
  document.head.appendChild js
224
232
 
225
233
  # 跑一個 case. root 是給它用的容器 ( 大小由這裡設 ). 回傳 {snaps, chart | board}
234
+ # 整個 case 超過 timeout ms ( case 或 suite 的 `timeout`, 預設 30000 ) 就算 error, 並寫出停在哪一步,
235
+ # 否則一個不會 resolve 的 step ( 或載不到的模組 ) 會讓整個 run 停住
226
236
  mctest.run-case = (c, root) ->
237
+ t = c.timeout ? c.suite.timeout ? 30000
238
+ at = {v: \load}
239
+ timer = null
240
+ Promise.race [
241
+ run-case c, root, at
242
+ new Promise (res, rej) ->
243
+ timer := setTimeout (-> rej new Error("[mctest] timeout after #{t}ms ( at #{at.v} )")), t
244
+ ]
245
+ .finally -> clearTimeout timer
246
+
247
+ run-case = (c, root, at) ->
227
248
  s = c.suite
228
249
  [w, h] = c.size or (c.dash and c.dash.size) or s.size
229
250
  root.style <<< {width: "#{w}px", height: "#{h}px"}
@@ -244,7 +265,8 @@ mctest.run-case = (c, root) ->
244
265
  random: mctest.random
245
266
  run-steps = (target) ->
246
267
  # 先等第一次畫完, step 才找得到節點
247
- ([].concat(c.steps or [])).reduce ((p, f) -> p.then(-> f target, ctx).then -> settle(root, list, q)), settle(root, list, q)
268
+ at.v = \render
269
+ ([].concat(c.steps or [])).reduce ((p, f, i) -> p.then(-> at.v = "step #{i + 1}"; f target, ctx).then -> settle(root, list, q)), settle(root, list, q)
248
270
  .then -> snaps.push {label: \final, markup: normalize(root, s.normalize)}
249
271
  .then -> {snaps, target}
250
272
  if c.dash => return load-dash!then (dash) ->
@@ -252,7 +274,7 @@ mctest.run-case = (c, root) ->
252
274
  root: root
253
275
  manager: mgr
254
276
  def: JSON.parse(JSON.stringify(c.dash.def))
255
- panel: {name: "@plotdb/dash", version: \main, path: "web/static/initiative/1st/block/panel/0.0.1/index.html"}
277
+ panel: {name: "@plotdb/dash", version: \main, path: "block/panel/index.html"}
256
278
  ctx.chart = (id) -> ((board.panels.filter(-> it.id == id).0 or {}).itf or {}).chart
257
279
  list := -> board.panels.map -> (it.itf or {}).chart
258
280
  board.init!then -> settle root, list, q