Sfoglia il codice sorgente

tests now run on the source (!) and not on compiled js

Raanan Weber 7 anni fa
parent
commit
7cb6a2d4d5

+ 17 - 18
Tools/Gulp/gulpfile.js

@@ -1037,32 +1037,31 @@ gulp.task("tests-unit", ["tests-unit-transpile"], function (done) {
     server.start();
 });
 
+var rmDir = function (dirPath) {
+    try { var files = fs.readdirSync(dirPath); }
+    catch (e) { return; }
+    if (files.length > 0)
+        for (var i = 0; i < files.length; i++) {
+            var filePath = dirPath + '/' + files[i];
+            if (fs.statSync(filePath).isFile())
+                fs.unlinkSync(filePath);
+            else
+                rmDir(filePath);
+        }
+    fs.rmdirSync(dirPath);
+};
+
 /**
  * Transpiles viewer typescript unit tests. 
  */
 gulp.task("tests-viewer-unit-transpile", function (done) {
-    //var tsProject = typescript.createProject('../../Viewer/tests/unit/tsconfig.json');
-
-    //var tsResult = gulp.src("../../Viewer/tests/unit/**/*.ts", { base: "../../Viewer/" })
-    //.pipe(tsProject());
-
-    /*tsResult.once("error", function () {
-        tsResult.once("finish", function () {
-            console.log("Typescript compile failed");
-            process.exit(1);
-        });
-    });*/
 
     let wpBuild = webpack(require('../../Viewer/tests/unit/webpack.config.js'));
 
+    // clean the built directory
+    rmDir("../../Viewer/tests/unit/build/");
+
     return wpBuild
-        .pipe(through.obj(function (file, enc, cb) {
-            // only pipe js files
-            const isJs = /\.js$/.test(file.path);
-            if (isJs) this.push(file);
-            cb();
-        }))
-        .pipe(rename("tests.js"))
         .pipe(gulp.dest("../../Viewer/tests/unit/build/"));
 });
 

+ 2 - 1
Viewer/src/model/modelLoader.ts

@@ -1,5 +1,6 @@
 import { AbstractViewer } from "..";
-import { ISceneLoaderPlugin, ISceneLoaderPluginAsync, Tools, SceneLoader, Tags, GLTFFileLoader } from "babylonjs";
+import { ISceneLoaderPlugin, ISceneLoaderPluginAsync, Tools, SceneLoader, Tags } from "babylonjs";
+import { GLTFFileLoader } from "babylonjs-loaders";
 import { IModelConfiguration } from "../configuration/configuration";
 import { ViewerModel, ModelState } from "./viewerModel";
 

+ 2 - 1
Viewer/src/model/viewerModel.ts

@@ -1,4 +1,5 @@
-import { ISceneLoaderPlugin, ISceneLoaderPluginAsync, AnimationGroup, Animatable, AbstractMesh, Tools, Scene, SceneLoader, Observable, SceneLoaderProgressEvent, Tags, ParticleSystem, Skeleton, IDisposable, Nullable, Animation, GLTFFileLoader, Quaternion } from "babylonjs";
+import { ISceneLoaderPlugin, ISceneLoaderPluginAsync, AnimationGroup, Animatable, AbstractMesh, Tools, Scene, SceneLoader, Observable, SceneLoaderProgressEvent, Tags, ParticleSystem, Skeleton, IDisposable, Nullable, Animation, Quaternion } from "babylonjs";
+import { GLTFFileLoader } from "babylonjs-loaders";
 import { IModelConfiguration } from "../configuration/configuration";
 import { IModelAnimation, GroupModelAnimation, AnimationPlayMode } from "./modelAnimation";
 

+ 3 - 3
Viewer/tests/commons/boot.ts

@@ -1,6 +1,6 @@
 // import webglSupport from './mockWebGL';
-import { viewerGlobals } from 'babylonjs-viewer';
 import { Helper } from "./helper";
+import { viewerGlobals } from "../../src";
 
 export class Boot {
     public static AppendResult = false;
@@ -18,7 +18,7 @@ export class Boot {
             //console.debug('> Executing "' + details.name + '"');
 
             //clear DOM and create canvas and container
-            document.getElementById('working-div').innerHTML = `<div style="font-size:30px;">WORKING CANVASES.</div> 
+            document.getElementById('working-div')!.innerHTML = `<div style="font-size:30px;">WORKING CANVASES.</div> 
 				<div id="viewer-testing" style="width:512px;height:512px;">
 					<div id="renderCanvas" width="512" height="512" style="width:512px;height:512px;"></div>
 					<canvas id="referenceCanvas" width="512" height="512" style="width:512px;height:512px;"></canvas>
@@ -27,7 +27,7 @@ export class Boot {
 
             if (Boot.AppendResult) {
                 var newResult = document.createElement('div');
-                document.getElementById('result-div').appendChild(newResult);
+                document.getElementById('result-div')!.appendChild(newResult);
 
                 newResult.innerHTML = `<div class="result">
 						<div class="resultDisplay"></div>

+ 5 - 5
Viewer/tests/commons/helper.ts

@@ -1,6 +1,6 @@
-import { BABYLON, DefaultViewer, AbstractViewer, ViewerModel, AnimationPlayMode, AnimationState, viewerGlobals } from "babylonjs-viewer";
-import { ViewerConfiguration } from "babylonjs-viewer/configuration/configuration";
-import { IModelAnimation } from "babylonjs-viewer/model/modelAnimation";
+import { AbstractViewer, DefaultViewer, ViewerModel, viewerGlobals, AnimationPlayMode, AnimationState } from "../../src";
+import { ViewerConfiguration } from "../../src/configuration/configuration";
+import { IModelAnimation } from "../../src/model/modelAnimation";
 
 export class Helper {
 
@@ -19,7 +19,7 @@ export class Helper {
     public static disposeViewer() {
         if (Helper.viewer != null) {
             Helper.viewer.dispose();
-            Helper.viewer = null;
+            delete Helper.viewer;
         }
     }
 
@@ -59,7 +59,7 @@ export class Helper {
 
     public static MockScreenCapture(viewer: AbstractViewer, data) {
         BABYLON.Tools.CreateScreenshot = function (viewer, camera, size, successCallback) {
-            successCallback(data);
+            successCallback && successCallback(data || '');
         }
     }
 

+ 14 - 5
Viewer/tests/unit/src/Viewer/viewer.ts

@@ -1,6 +1,6 @@
-import { AbstractViewer } from "babylonjs-viewer";
+import { AbstractViewer } from "../../../../src/viewer/viewer";
 import { Helper, NullEngineDefaultViewer } from "../../../commons/helper";
-import { assert, expect } from "../../viewerReference";
+import { assert, expect } from "../viewerReference";
 
 /**
  * To prevent test-state-leakage ensure that there is a viewer.dispose() for every new DefaultViewer
@@ -16,10 +16,11 @@ describe('Viewer', function () {
         });
     });
 
-    it('should not initialize if canvas is undefined', (done) => {
+    it('should not initialize if element is undefined', (done) => {
         let viewer: AbstractViewer;
         try {
-            viewer = new NullEngineDefaultViewer(undefined);
+            // force typescript to "think" that the element exist with "!"
+            viewer = new NullEngineDefaultViewer(document.getElementById('doesntexist')!);
             expect(viewer).not.to.exist;
             if (viewer) viewer.dispose();
         } catch (e) {
@@ -27,8 +28,16 @@ describe('Viewer', function () {
             assert.isTrue(true);
         }
         done();
-
     });
+
+    it('should be hidden and shown', (done) => {
+        let viewer = new NullEngineDefaultViewer(Helper.getViewerContainer());
+        viewer.onInitDoneObservable.add(() => {
+            assert.isTrue(viewer != undefined, "Viewer can not be instantiated.");
+            viewer.dispose();
+            done();
+        });
+    })
 });
 
 export default (function () {

+ 3 - 2
Viewer/tests/unit/src/viewerReference.ts

@@ -1,5 +1,6 @@
-/// <reference path="../../../../dist/preview release/viewer/babylon.viewer.module.d.ts" />
-
+/// <reference path="../../node_modules/@types/chai/index.d.ts" />
+/// <reference path="../../node_modules/@types/mocha/index.d.ts" />
+/// <reference path="../../node_modules/@types/sinon/index.d.ts" />
 /*
  * Create a constant with the ChaiJS' expect module just to make the code more readable.
  */

+ 21 - 7
Viewer/tests/unit/tsconfig.json

@@ -2,21 +2,35 @@
     "compilerOptions": {
         "target": "es5",
         "module": "commonjs",
-        "noUnusedLocals": true,
-        "noUnusedParameters": false,
-        "forceConsistentCasingInFileNames": true,
         "noResolve": false,
-        "experimentalDecorators": true,
-        "declaration": false,
         "noImplicitAny": false,
-        "noEmitOnError": false,
-        "removeComments": false,
+        "strictNullChecks": true,
+        "removeComments": true,
+        "preserveConstEnums": true,
         "sourceMap": true,
+        "experimentalDecorators": true,
+        "isolatedModules": false,
+        "declaration": false,
         "lib": [
             "dom",
             "es2015.promise",
             "es5"
         ],
+        "types": [
+            "node"
+        ],
+        "baseUrl": "./src/",
+        "paths": {
+            "babylonjs": [
+                "../../../../dist/preview release/babylon.d.ts"
+            ],
+            "babylonjs-loaders": [
+                "../../../src/externalModules.d.ts"
+            ],
+            "babylonjs-gltf2interface": [
+                "../../../../dist/babylon.glTF2Interface.d.ts"
+            ]
+        },
     },
     "include": [
         "./src/**/*.ts"

+ 0 - 12
Viewer/tests/unit/viewerReference.ts

@@ -1,12 +0,0 @@
-/// <reference path="../../../dist/preview release/viewer/babylon.viewer.module.d.ts" />
-
-/// <reference path="../node_modules/@types/chai/index.d.ts" />
-/// <reference path="../node_modules/@types/mocha/index.d.ts" />
-/// <reference path="../node_modules/@types/sinon/index.d.ts" />
-
-/*
- * Create a constant with the ChaiJS' expect module just to make the code more readable.
- */
-export const should = chai.should();
-export const expect = chai.expect;
-export const assert = chai.assert;

+ 1 - 1
Viewer/tsconfig.json

@@ -25,7 +25,7 @@
                 "../../dist/preview release/babylon.d.ts"
             ],
             "babylonjs-loaders": [
-                "../../dist/preview release/loaders/babylonjs.loaders.d.ts"
+                "externalModules.d.ts"
             ],
             "babylonjs-gltf2interface": [
                 "../../dist/babylon.glTF2Interface.d.ts"