Skip to content

Commit

Permalink
Remove dependency on external promise library
Browse files Browse the repository at this point in the history
  • Loading branch information
nakosung committed Jul 30, 2016
1 parent 34d002f commit def383b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
49 changes: 39 additions & 10 deletions Examples/Content/Scripts/extension-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@

const async_task_timeout_in_seconds = 10

// V8 handles 'Promise' natively and it prevents sync test to control execution.
let Promise = require('promise')

let _ = require('lodash')
let root_path = Root.GetDir('GameContent') + 'Scripts/tests'
let test_files = []
Expand Down Expand Up @@ -73,7 +70,24 @@ function load(file) {
scope = prev

if (!prev) {
// FJavascriptAutomatedTest (V8/Public/JavascriptTestLibrary.h)
// FJavascriptAutomatedTest (V8/Public/JavascriptTestLibrary.h)
let running
let delegate = Root.OnTick.toJSON()
let prev, deadline
function start() {
prev = Date.now()
deadline = $time + async_task_timeout_in_seconds
}

function poll() {
let cur = Date.now()
let elapsed = cur - prev
delegate(elapsed / 1000.0)
prev = cur

return ($time < deadline)
}

let recipe = _.extend({
Name: name.replace(/[ \t]/g, '_'),
bComplexTask: false,
Expand All @@ -82,8 +96,25 @@ function load(file) {
TestFunctionNames: pending.slice(),
Function: function (params) {
let {TestFunctionName, Tester} = params
tests[TestFunctionName](Tester)
}
if (!running) {
start()
Tester.SetContinue(true)
running = tests[TestFunctionName](Tester).then(_ => {
Tester.SetContinue(false)
running = false
}).catch(_ => {
Tester.SetContinue(false)
running = false
})
} else {
if (poll()) {
Tester.SetContinue(true)
} else {
Tester.AddError("Async time out")
running = false
}
}
}
},opts)

pending.length = 0
Expand Down Expand Up @@ -159,9 +190,7 @@ function load(file) {
key = b.join('.')
pending.push(key)
tests[key] = function (Tester) {
if (!run_sync(_ => run(bound, body, Tester))) {
Tester.AddError("Async test time-out")
}
return run(bound, body, Tester)
}
}

Expand All @@ -186,4 +215,4 @@ module.exports = function () {
return function () {
byes.forEach(fn => fn())
}
}
}
1 change: 0 additions & 1 deletion Examples/Content/Scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"license": "ISC",
"description": "",
"dependencies": {
"promise": "^7.1.1",
"springy": "^2.7.1"
}
}

0 comments on commit def383b

Please sign in to comment.