Get current time in milliseconds.
Function which runs a cross-environment resource loader which gets the static resources requested. (e.g. needed for tests purposes).
The following folders are mapped in test environment for resources that are needed for testing purposes:
@here/${module}/test/resources
@here/${module}/resources
The fileName
must be relative to package root.
Exemplary methods invocation:
const binaryData = await loadTestResourceWeb('test-utils', 'test/resources/test.bin', 'binary');
const textData = await loadTestResourceWeb('test-utils', 'test/resources/test.txt', 'text');
const theme = await loadTestResource('map-theme', 'resources/berlin_tilezen_base.json', 'json');
These locations above are mapped in the same way regardless of the runtime environment used (node.js or browser).
Internally this function loads resources in an environment-agnostic way, using the following:
fs
module when run in a node.js environmentfetch
module when run in a browser environmentFunction which runs a cross-environment resource loader which gets the static resources requested. (e.g. needed for tests purposes).
The following folders are mapped in test environment for resources that are needed for testing purposes:
@here/${module}/test/resources
@here/${module}/resources
The fileName
must be relative to package root.
Exemplary methods invocation:
const binaryData = await loadTestResourceWeb('test-utils', 'test/resources/test.bin', 'binary');
const textData = await loadTestResourceWeb('test-utils', 'test/resources/test.txt', 'text');
const theme = await loadTestResource('map-theme', 'resources/berlin_tilezen_base.json', 'json');
These locations above are mapped in the same way regardless of the runtime environment used (node.js or browser).
Internally this function loads resources in an environment-agnostic way, using the following:
fs
module when run in a node.js environmentfetch
module when run in a browser environmentAssert that synchronous test function fn
will logs specfic message.
Captures error messages of type
from channel
and asserts that at least one contain
message that matches errorMessagePattern
.
Swallows matching messages, so they don't appear in actual output so "test log" is clean from expected messages.
Example with console.warn
assertWillLogSync(() => {
console.warn("error: fooBar"),
console,
"warn"
/error/
);
test function that shall provoke certain log output
Console
like object
type of console message i.e "log" | "error" | "warn" | "info
string or regular expression that we look for in logs
Assert that promise is rejected.
Check that promise v
(passed directly or result of function) is eventually rejected with error
that matches errorMessagePattern
.
Captures raw image from canvas with fallback for 'webgl' canvases, for which '2d' context cannot
be obtained as they have webgl
context already attached.
Note, on MS Edge it requires this polyfill: https://github.com/blueimp/JavaScript-Canvas-to-Blob
Compare two images with specified threshold and returns json with comparison result.
Report call.
Convenience utility to be used temporarily in development to confirm expectations about number of calls when measuring performance.
Call counts are logged after all tests (if in Mocha environment). See reportCallCountsAndReset.
Usage:
class Foo {
push() {
countCall("Foo#bar")
}
}
It reports following after all tests:
#countCall: Foo#push called=123
Count function/method calls decorator.
Convenience utility to be used temporarily in development to confirm expectations about number of calls when measuring performance.
Call counts are logged after all tests (if in Mocha environment). See reportCallCountsAndReset.
Usage - basic functional composition:
const bar = countCalls("bar", () => { ... })
Usage - experimental TypeScript decorators:
class Foo {
@countCalls()
push() {}
}
It reports following after execution of all tests:
ProfileHelper: Foo#push called=123
ProfileHelper: bar called=1111
Create a HTML element from either
ImageData
, ImageBitmap
or just source URL.
Default reference image resolver URL of reference image.
Relative to baseUrl
of test runner page, which is usually test/rendering.html
,
so relative to mapsdk/test
.
Get image path in filesystem.
Relative to process.cwd()
, which is usually mapsdk
folder.
-
-
Get platform
property.
Reads platform from:
IBCT_PLATFORM_OVERRIDE
- overrides any detectionnavigator.userAgent
in form $name-$version-$os, optionally adds query param
IBCT_PLATATFORM_EXTRA
IBCT_PLATATFORM_EXTRA
is intended to inform about platform properties not detecatble from
browser api like "no-gpu" or "headless" or "-nvidia-gtx-whatever".
Get URL of reference image.
Uses resolver set by setReferenceImageResolver, by default, use defaultReferenceImageResolver.
Get URL of test resource.
Calculates URL of test resource in same way as loadTestResource.
-: file relative to module path (e.g. test/resources/berlin.bin)
Get URL of test resource.
Calculates URL of test resource in same way as loadTestResource.
-: file relative to module path (e.g. test/resources/berlin.bin)
Helper function to return options required for stub when mocking the WebGLRenderer
The sinon sandbox
The stub for clearing the color
Returns image which can be used in another canvas or html element.
Check if we're executing in Web Browser environment (but not in Web Worker)
https://stackoverflow.com/questions/17575790/environment-detection-node-js-or-browser
Define a suite that is executed only in Node.JS environment.
Check if we're executing in Web Worker environment.
Install magnifier control on set of images.
When user hover mouse over any of images, an popup with information given pixel will be shown. If window has focus, one can also move focus point with keyboard.
-
-
-
Install RenderingTestResultServer in express.Router
.
Example usage i.e webpack-dev-server
configuration in webpack.config.js
:
devServer: {
before: function(app) {
require('ts-node/register'); // so we can load typescript seamlessly
const RenderingTestResultServer = require(
"coresdk/@here/harp-test-utils/lib/rendering/RenderingTestResultServer"
);
RenderingTestResultServer.installMiddleware(app);
}
}
Load image from URL as ImageData
so it can be easily compared by image comparision libraries.
Search for IBCT results in searchPath
.
-
Measure time performance of code.
Executes test
code repeats
times and measures: min
, med
(median), sum
and avg
(average) execution times.
[[performance.now]] is used as time provider, with fallback to new Date().getTime()
.
Measurement reports are saved for later and logged after all tests (if in Mocha environment). See reportPerformanceAndReset.
Example:
it('performance test', async () => {
await measurePerformanceSync("Array/grow", 50, () => {
// the code under test
// will be executed 50 times ----^^
});
});
Will print report like this after all tests:
#performance: Array/grow: min=1 med=2 avg=1.8 sum=72 (50 repeats)
name of performance test
number of test repeats
tested code
Measure throughput performance of code.
Executes test
code for timeout
milliseconds and reports throughput and aggregated times:
min
, med
(median), sum
and avg
(average) execution times.
[[performance.now]] is used as time provider, with fallback to new Date().getTime()
.
Measurement reports are saved for later and logged after all tests (if in Mocha environment). See reportPerformanceAndReset.
Example:
it('throughput test', async () => {
await measureThroughputSync("Array/grow", 100, () => {
// the code under test
// will be executed for 100 milliseconds ----^^
});
});
Will print report like this after all tests:
#performance: Array/grow: min=1 med=2 avg=1.8 sum=72 repeats=123 throughput=1242/s
name of performance test
tested code
Report and reset performance measurement results.
Designed to be called after round of tests. Shows results of all performance tests executed by measurePerformanceSync and measureThroughputSync.
It resets results afterwards.
If baseline is available (.profile-helper-baseline.json
, customized by PROFILEHELPER_OUTPUT
_)
then this run results are compared to baseline
If PROFILEHELPER_COMMAND=baseline
resutls are saved as baseline.
In Mocha
runtime it is called automatically in global after
callback.
Sets the specified loggers to only log at the given minLogLevel. Only use this function when you know that you can safely ignore a warning, otherwise you should consider to fix the issue. All previous logging levels are reset after the function is executed.
The loggerName, or array of names to set to error
The function to execute with the changed logging
The minimum log level that is shown, defaults to LogLevel.Error
Start RenderingTestResultServer
as simple, standalone HTTP server which
process.cwd()
Create stub of global constructor managed by sandbox.
A prototype
preserving, node/browser environment aware version of
`sandbox.stub(window | global, name).
Use to stub global constructors like Worker
or XMLHttpRequest
.
sinon.Sandbox
instance, required for proper cleanup after test
name of global symbol to be constructor
Wait for particular event on THREE.EventDispatcher
or DOM EventTarget
compatible objects.
Automatically unregisters itself receiving the event.
event source or target that has add/removeEventListener(type, listener) method. protocol
type of event
promise that resolves to first event that is received
Repeats block of code until it passes without AssertionError
.
Additionally, if test fails due to timeout, last error that was encountered is rethrown, so any
error that have constructor called AssertionError
(matches chai assertions) will cause test
to be repeated after 1ms delay.
The last error that blocked willEventually
from resolving will be rethrown in afterEach
to
mark which assertion didn't hold (see [[reportWillEventuallyBlockingAssertion]]).
Use for APIs that are internally asynchronous without explicit means to monitor completion of tasks.
Example:
const foo = someCodeThatIsAsync({count: 6})
await willEventually(() => { assert.equals(foo.readyCount, 6); });
closure with assertions that must pass
promise that resolves when test
passes without any error
Generated using TypeDoc
@here/harp-test-utils
Overview
This module provides utilities used in tests.