Skip to content

Commit

Permalink
Add browser runner
Browse files Browse the repository at this point in the history
  • Loading branch information
ggetz committed Apr 13, 2022
1 parent b3f0fad commit a040026
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 131 deletions.
2 changes: 0 additions & 2 deletions Documentation/Contributors/TestingGuide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ Alternatively, test suites can be run from the command line with the `includeNam

`npm run test -- --includeName Cartesian2`

Similarly, test suites can be excluded with the `--excludeName` flag.

#### Using Browser Debugging Tools

If it is helpful to step through a unit test in a browser debugger, run the tests with the `debug` flag:
Expand Down
14 changes: 0 additions & 14 deletions Specs/CesiumJasmineHtml.css

This file was deleted.

4 changes: 2 additions & 2 deletions Specs/Scene/CameraFlightPathSpec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Cartesian3 } from "../../Source/Cesium.js";
import { Cartographic } from "../../Source/Cesium.js";
import { Ellipsoid } from "../../Source/Cesium.js";
import { GeographicProjection } from "../../../Source/Cesium.js";
import { Globe } from "../../../Source/Cesium.js";
import { GeographicProjection } from "../../Source/Cesium.js";
import { Globe } from "../../Source/Cesium.js";
import { Math as CesiumMath } from "../../Source/Cesium.js";
import { OrthographicOffCenterFrustum } from "../../Source/Cesium.js";
import { CameraFlightPath } from "../../Source/Cesium.js";
Expand Down
4 changes: 2 additions & 2 deletions Specs/Scene/IonImageryProviderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe("Scene/IonImageryProvider", function () {
}).toThrowDeveloperError(ImageryProvider);
});

it("readyPromise rejects with non-imagery asset", function (done) {
it("readyPromise rejects with non-imagery asset", function () {
const provider = createTestProvider({
type: "3DTILES",
url: "http://test.invalid/layer",
Expand All @@ -80,7 +80,7 @@ describe("Scene/IonImageryProvider", function () {
});
});

it("readyPromise rejects with unknown external asset type", function (done) {
it("readyPromise rejects with unknown external asset type", function () {
const provider = createTestProvider({
type: "IMAGERY",
externalType: "TUBELCANE",
Expand Down
3 changes: 1 addition & 2 deletions Specs/Scene/PntsParserSpec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { PntsParser } from "../../Source/Cesium.js";
import { RuntimeError } from "../Source/Cesium.js";
import { PntsParser, RuntimeError } from "../../Source/Cesium.js";
import Cesium3DTilesTester from "../Cesium3DTilesTester.js";

describe("Scene/PntsParser", function () {
Expand Down
35 changes: 35 additions & 0 deletions Specs/SpecRunner.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Jasmine Spec Runner v4.0.1</title>

<link
rel="stylesheet"
href="../node_modules/jasmine-core/lib/jasmine-core/jasmine.css"
/>

<script src="../node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script>
<script src="../node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script>
<script src="../node_modules/jasmine-core/lib/jasmine-core/boot0.js"></script>
<script type="module" src="./spec-main.js"></script>
<script src="../node_modules/jasmine-core/lib/jasmine-core/boot1.js"></script>
</head>
<body>
<script>
if (window.location.search.indexOf("built") !== -1) {
if (window.location.search.indexOf("release") !== -1) {
document.write('<script src="../Build/Cesium/Cesium.js"><\/script>');
} else {
document.write(
'<script src="../Build/CesiumUnminified/Cesium.js"><\/script>'
);
}
document.write('<script src="../Build/Specs/Specs.js"><\/script>');
} else {
window.CESIUM_BASE_URL = "../Source/";
document.write('<script type="module" src="./SpecList.js"><\/script>');
}
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion Specs/addDefaultMatchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function makeThrowFunction(debug, Type, name) {
}

if (exception) {
result = exception instanceof Type;
result = exception instanceof Type || exception.name === name;
}

let message;
Expand Down
115 changes: 16 additions & 99 deletions Specs/customizeJasmine.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ function customizeJasmine(
env,
includedCategory,
excludedCategory,
includedName,
excludedName,
webglValidation,
webglStub,
release
Expand All @@ -18,104 +16,25 @@ function customizeJasmine(

const originalDescribe = window.describe;

window.describe = function (name, suite, categories) {
window.describe = function (name, suite, category) {
// exclude this spec if we're filtering by category and it's not the selected category
// otherwise if we have an excluded category, exclude this test if the category of this spec matches
if (includedCategory && categories !== includedCategory) {
return;
} else if (excludedCategory && categories === excludedCategory) {
return;
if (
includedCategory &&
includedCategory !== "" &&
includedCategory !== "none" &&
category !== includedCategory
) {
window.xdescribe(name, suite);
} else if (
excludedCategory &&
excludedCategory !== "" &&
category === excludedCategory
) {
window.xdescribe(name, suite);
} else {
originalDescribe(name, suite);
}

if (includedName && !name.includes(includedName)) {
return;
} else if (excludedName && name.includes(excludedName)) {
return;
}

originalDescribe(name, suite, categories);
};

// Override beforeEach(), afterEach(), beforeAll(), afterAll(), and it() to automatically
// call done() when a returned promise resolves.
const originalIt = window.it;

window.it = function (description, f, timeout, categories) {
originalIt(
description,
function (done) {
const result = f(done);
Promise.resolve(result)
.then(function () {
done();
})
.catch(function (e) {
done.fail(`promise rejected: ${e.toString()}`);
});
},
timeout,
categories
);
};

const originalBeforeEach = window.beforeEach;

window.beforeEach = function (f) {
originalBeforeEach(function (done) {
const result = f(done);
Promise.resolve(result)
.then(function () {
done();
})
.catch(function (e) {
done.fail(`promise rejected: ${e.toString()}`);
});
});
};

const originalAfterEach = window.afterEach;

window.afterEach = function (f) {
originalAfterEach(function (done) {
const result = f(done);
Promise.resolve(result)
.then(function () {
done();
})
.catch(function (e) {
done.fail(`promise rejected: ${e.toString()}`);
});
});
};

const originalBeforeAll = window.beforeAll;

window.beforeAll = function (f) {
originalBeforeAll(function (done) {
const result = f(done);
Promise.resolve(result)
.then(function () {
done();
})
.catch(function (e) {
done.fail(`promise rejected: ${e.toString()}`);
});
});
};

const originalAfterAll = window.afterAll;

window.afterAll = function (f) {
originalAfterAll(function (done) {
const result = f(done);
Promise.resolve(result)
.then(function () {
done();
})
.catch(function (e) {
done.fail(`promise rejected: ${e.toString()}`);
});
});
};

if (webglValidation) {
Expand All @@ -126,8 +45,6 @@ function customizeJasmine(
window.webglStub = true;
}

//env.catchExceptions(true);

env.beforeEach(function () {
addDefaultMatchers(!release).call(env);
env.addCustomEqualityTester(equalsMethodEqualityTester);
Expand Down
6 changes: 0 additions & 6 deletions Specs/karma-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@ import customizeJasmine from "./customizeJasmine.js";

let includeCategory = "";
let excludeCategory = "";
let includeName = "";
let excludeName = "";
let webglValidation = false;
let webglStub = false;
let release = false;

if (__karma__.config.args) {
includeCategory = __karma__.config.args[0];
excludeCategory = __karma__.config.args[1];
includeName = __karma__.config.args[2];
excludeName = __karma__.config.args[3];
webglValidation = __karma__.config.args[4];
webglStub = __karma__.config.args[5];
release = __karma__.config.args[6];
Expand All @@ -30,8 +26,6 @@ customizeJasmine(
jasmine.getEnv(),
includeCategory,
excludeCategory,
includeName,
excludeName,
webglValidation,
webglStub,
release
Expand Down
2 changes: 1 addition & 1 deletion Specs/karma.conf.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module.exports = function (config) {
},

// list of files to exclude
exclude: ["Specs/SpecList.js"],
exclude: ["Specs/SpecList.js", "Specs/SpecRunner.js", "Specs/spec-main.js"],

// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
Expand Down
64 changes: 64 additions & 0 deletions Specs/spec-main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import customizeJasmine from "./customizeJasmine.js";
import { defined, queryToObject } from "../Source/Cesium.js";

const queryString = queryToObject(window.location.search.substring(1));

let webglValidation = false;
let webglStub = false;
const built = window.location.search.indexOf("built") !== -1;
const release = window.location.search.indexOf("release") !== -1;
const categoryString = queryString.category;
const excludeCategoryString = queryString.not;

if (defined(queryString.webglValidation)) {
webglValidation = true;
}

if (defined(queryString.webglStub)) {
webglStub = true;
}

if (built) {
if (release) {
window.CESIUM_BASE_URL = "../Build/Cesium";
} else {
window.CESIUM_BASE_URL = "../Build/CesiumUnminified";
}
} else {
window.CESIUM_BASE_URL = "../Source/";
}

jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;

const specFilter = new jasmine.HtmlSpecFilter({
filterString: function () {
return queryString.spec;
},
});

const env = jasmine.getEnv();
env.configure({
stopSpecOnExpectationFailure: false,
stopOnSpecFailure: false,
random: false,
hideDisabled: true,
specFilter: function (spec) {
if (
!specFilter.matches(spec.getFullName()) ||
(categoryString === "none" && !defined(queryString.spec))
) {
return false;
}

return true;
},
});

customizeJasmine(
env,
categoryString,
excludeCategoryString,
webglValidation,
webglStub,
release
);
4 changes: 2 additions & 2 deletions gulpfile.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ const filesToConvertES6 = [
"!Source/Workers/transferTypedArrayTest.js",
"!Specs/karma-main.js",
"!Specs/karma.conf.cjs",
"!Specs/spec-main.js",
"!Specs/SpecList.js",
"!Specs/TestWorkers/**",
];
Expand Down Expand Up @@ -995,7 +996,6 @@ gulp.task("test", function (done) {
const suppressPassed = argv.suppressPassed ? argv.suppressPassed : false;
const debug = argv.debug ? false : true;
const includeName = argv.includeName ? argv.includeName : "";
const excludeName = argv.excludeName ? argv.excludeName : "";

let browsers = ["Chrome"];
if (argv.browsers) {
Expand Down Expand Up @@ -1049,8 +1049,8 @@ gulp.task("test", function (done) {
args: [
includeCategory,
excludeCategory,
"--grep",
includeName,
excludeName,
webglValidation,
webglStub,
release,
Expand Down
Loading

0 comments on commit a040026

Please sign in to comment.