Skip to content

Commit 204efb9

Browse files
committed
Merge remote-tracking branch 'origin/master' into async-fixes
2 parents c999153 + d414bcf commit 204efb9

File tree

42 files changed

+761
-421
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+761
-421
lines changed

.github/workflows/nightly.yml

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,12 @@ jobs:
1414
uses: actions/checkout@master
1515
with:
1616
submodules: 'recursive'
17-
- name: Download babylon.max.js
18-
run: curl.exe -o Apps/node_modules/babylonjs/babylon.max.js --create-dirs https://preview.babylonjs.com/babylon.max.js
19-
- name: Download babylon.max.js.map
20-
run: curl.exe -o Apps/node_modules/babylonjs/babylon.max.js.map --create-dirs https://preview.babylonjs.com/babylon.max.js.map
21-
- name: Download babylonjs.materials.js
22-
run: curl.exe -o Apps/node_modules/babylonjs-materials/babylonjs.materials.js --create-dirs https://preview.babylonjs.com/materialsLibrary/babylonjs.materials.js
23-
- name: Download babylonjs.materials.js.map
24-
run: curl.exe -o Apps/node_modules/babylonjs-materials/babylonjs.materials.js.map --create-dirs https://preview.babylonjs.com/materialsLibrary/babylonjs.materials.js.map
25-
- name: Download babylon.loaders.js
26-
run: curl.exe -o Apps/node_modules/babylonjs-loaders/babylonjs.loaders.js --create-dirs https://preview.babylonjs.com/loaders/babylonjs.loaders.js
27-
- name: Download babylon.loaders.js.map
28-
run: curl.exe -o Apps/node_modules/babylonjs-loaders/babylonjs.loaders.js.map --create-dirs https://preview.babylonjs.com/loaders/babylonjs.loaders.js.map
29-
- name: Download babylon.gui.js
30-
run: curl.exe -o Apps/node_modules/babylonjs-gui/babylon.gui.js --create-dirs https://preview.babylonjs.com/gui/babylon.gui.js
31-
- name: Download babylon.gui.js.map
32-
run: curl.exe -o Apps/node_modules/babylonjs-gui/babylon.gui.js.map --create-dirs https://preview.babylonjs.com/gui/babylon.gui.js.map
33-
- name: Download chai.js
34-
run: curl.exe -o Apps/node_modules/chai/chai.js --create-dirs https://unpkg.com/chai/chai.js
35-
- name: Download mocha.js
36-
run: curl.exe -o Apps/node_modules/mocha/mocha.js --create-dirs https://unpkg.com/mocha/mocha.js
17+
- name: NPM Install
18+
run: npm install
19+
working-directory: ./Apps
20+
- name: NPM download nightly
21+
run: npm run getNightly
22+
working-directory: ./Apps
3723
- name: View Apps\node_modules content
3824
run: Get-ChildItem -Path .\Apps\node_modules -Recurse
3925
- name: Make Solution

Apps/UnitTests/Apple/App.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "../Shared/Tests.cpp"
1+
#include "../Shared/Tests.h"
22

33
int main() {
44
Babylon::Graphics::DeviceConfiguration graphicsConfig{};

Apps/UnitTests/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ set(NPM_SCRIPTS
1414
"../node_modules/chai/chai.js"
1515
"../node_modules/mocha/mocha.js")
1616

17+
set(HEADERS
18+
"Shared/Tests.h")
19+
1720
set(ADDITIONAL_LIBRARIES "")
1821

1922
if(APPLE)
@@ -26,7 +29,7 @@ elseif(WIN32)
2629
set(TEST_APP "Win32/App.cpp")
2730
endif()
2831

29-
add_executable(UnitTests ${LOCAL_SCRIPTS} ${NPM_SCRIPTS} ${TEST_APP})
32+
add_executable(UnitTests ${LOCAL_SCRIPTS} ${NPM_SCRIPTS} ${TEST_APP} ${HEADERS})
3033

3134
target_link_to_dependencies(UnitTests
3235
UrlLib

Apps/UnitTests/Scripts/tests.js

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,119 @@ describe("PostProcesses", function() {
327327
});*/
328328
})
329329

330+
describe("setTimeout", function () {
331+
this.timeout(1000);
332+
it("should return an id greater than zero", function () {
333+
const id = setTimeout(() => { }, 0);
334+
expect(id).to.be.greaterThan(0);
335+
});
336+
it("should return an id greater than zero when given an undefined function", function () {
337+
const id = setTimeout(undefined, 0);
338+
expect(id).to.be.greaterThan(0);
339+
});
340+
it("should call the given function after the given delay", function (done) {
341+
const startTime = new Date().getTime();
342+
setTimeout(() => {
343+
try {
344+
expect(new Date().getTime() - startTime).to.be.at.least(10);
345+
done();
346+
}
347+
catch (e) {
348+
done(e);
349+
}
350+
}, 10);
351+
});
352+
it("should call the given nested function after the given delay", function (done) {
353+
const startTime = new Date().getTime();
354+
setTimeout(() => {
355+
setTimeout(() => {
356+
try {
357+
expect(new Date().getTime() - startTime).to.be.at.least(20);
358+
done();
359+
}
360+
catch (e) {
361+
done(e);
362+
}
363+
}, 10);
364+
}, 10);
365+
});
366+
it("should call the given function after the given delay when the delay is a string representing a valid number", function (done) {
367+
const startTime = new Date().getTime();
368+
setTimeout(() => {
369+
try {
370+
expect(new Date().getTime() - startTime).to.be.at.least(10);
371+
done();
372+
}
373+
catch (e) {
374+
done(e);
375+
}
376+
}, "10");
377+
});
378+
it("should call the given function after zero milliseconds when the delay is a string representing an invalid number", function (done) {
379+
setTimeout(() => {
380+
done();
381+
}, "a");
382+
});
383+
it("should call the given function after other tasks execute when the given delay is zero", function (done) {
384+
let trailingCodeExecuted = false;
385+
setTimeout(() => {
386+
try {
387+
expect(trailingCodeExecuted).to.be.true;
388+
done();
389+
}
390+
catch (e) {
391+
done(e);
392+
}
393+
}, 0);
394+
trailingCodeExecuted = true;
395+
});
396+
it("should call the given function after other tasks execute when the given delay is undefined", function (done) {
397+
let trailingCodeExecuted = false;
398+
setTimeout(() => {
399+
try {
400+
expect(trailingCodeExecuted).to.be.true;
401+
done();
402+
}
403+
catch (e) {
404+
done(e);
405+
}
406+
}, undefined);
407+
trailingCodeExecuted = true;
408+
});
409+
it("should call the given functions in the correct order", function (done) {
410+
const called = [];
411+
for (let i = 9; i >= 0; i--) {
412+
setTimeout(() => {
413+
called.push(i * 2);
414+
if (called.length === 10) {
415+
try {
416+
expect(called).to.deep.equal([0, 2, 4, 6, 8, 10, 12, 14, 16, 18]);
417+
done();
418+
}
419+
catch (e) {
420+
done(e);
421+
}
422+
}
423+
}, i * 2);
424+
}
425+
});
426+
})
427+
428+
describe("clearTimeout", function () {
429+
this.timeout(0);
430+
it("should stop the timeout matching the given timeout id", function (done) {
431+
const id = setTimeout(() => {
432+
done(new Error("Timeout was not cleared"));
433+
}, 0);
434+
clearTimeout(id);
435+
setTimeout(done, 100);
436+
});
437+
it("should do nothing if the given timeout id is undefined", function (done) {
438+
setTimeout(() => { done(); }, 0);
439+
clearTimeout(undefined);
440+
});
441+
})
442+
330443
mocha.run(failures => {
331444
// Test program will wait for code to be set before exiting
332445
if (failures > 0) {

Apps/UnitTests/Shared/Tests.cpp renamed to Apps/UnitTests/Shared/Tests.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ int Run(std::unique_ptr<Babylon::Graphics::Device> device)
4848
});
4949
Babylon::ScriptLoader loader{*runtime};
5050
loader.Eval("global = {};", ""); // Required for Chai.js as we do not have global in Babylon Native
51-
loader.Eval("window.clearTimeout = () => {};", ""); // TODO: implement clear timeout, required for Mocha timeouts to work correctly
5251
loader.Eval("location = {href: ''};", ""); // Required for Mocha.js as we do not have a location in Babylon Native
5352
loader.LoadScript("app:///Scripts/babylon.max.js");
5453
loader.LoadScript("app:///Scripts/babylonjs.materials.js");

Apps/UnitTests/Win32/App.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "../Shared/Tests.cpp"
1+
#include "../Shared/Tests.h"
22

33
LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
44
{

Apps/UnitTests/X11/App.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <X11/Xlib.h> // will include X11 which #defines None... Don't mess with order of includes.
44
#include <X11/Xutil.h>
55
#undef None
6-
#include "../Shared/Tests.cpp"
6+
#include "../Shared/Tests.h"
77

88
namespace
99
{

Apps/package-lock.json

Lines changed: 42 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Apps/package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
"name": "BabylonNative",
33
"version": "0.0.1",
44
"private": true,
5+
"scripts": {
6+
"getNightly": "node scripts/getNightly.js"
7+
},
58
"dependencies": {
6-
"babylonjs": "^5.17.0",
7-
"babylonjs-gui": "^5.17.0",
8-
"babylonjs-loaders": "^5.17.0",
9-
"babylonjs-materials": "^5.17.0",
9+
"babylonjs": "^5.27.0",
10+
"babylonjs-gui": "^5.27.0",
11+
"babylonjs-loaders": "^5.27.0",
12+
"babylonjs-materials": "^5.27.0",
1013
"chai": "^4.3.4",
1114
"jsc-android": "^241213.1.0",
1215
"mocha": "^9.2.2",

Apps/scripts/getNightly.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var https = require('https');
2+
var fs = require('fs');
3+
4+
function download(filename, url) {
5+
var file = fs.createWriteStream(filename);
6+
var request = https.get(url, function(response) {
7+
response.pipe(file);
8+
});
9+
}
10+
11+
console.log('Downloading babylon.js nightly');
12+
download('node_modules/babylonjs/babylon.max.js', 'https://preview.babylonjs.com/babylon.max.js');
13+
download('node_modules/babylonjs/babylon.max.js.map', 'https://preview.babylonjs.com/babylon.max.js.map');
14+
download('node_modules/babylonjs-materials/babylonjs.materials.js', 'https://preview.babylonjs.com/materialsLibrary/babylonjs.materials.js');
15+
download('node_modules/babylonjs-materials/babylonjs.materials.js.map', 'https://preview.babylonjs.com/materialsLibrary/babylonjs.materials.js.map');
16+
download('node_modules/babylonjs-loaders/babylonjs.loaders.js', 'https://preview.babylonjs.com/loaders/babylonjs.loaders.js');
17+
download('node_modules/babylonjs-loaders/babylonjs.loaders.js.map', 'https://preview.babylonjs.com/loaders/babylonjs.loaders.js.map');
18+
download('node_modules/babylonjs-gui/babylon.gui.js', 'https://preview.babylonjs.com/gui/babylon.gui.js');
19+
download('node_modules/babylonjs-gui/babylon.gui.js.map', 'https://preview.babylonjs.com/gui/babylon.gui.js.map');

0 commit comments

Comments
 (0)