From 7b934a06beb5a93c0f1dc9cbf22504c2b7bbfb7e Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Wed, 28 Apr 2021 15:00:04 -0700 Subject: [PATCH] Add node tests --- .github/workflows/test.yml | 41 +- package.json | 5 +- test/README.md | 2 +- test/browser/spec/ol/asserts.test.js | 11 - test/browser/spec/ol/index.test.js | 22 - test/browser/spec/ol/math.test.js | 162 ----- test/browser/spec/ol/objectutil.test.js | 64 -- test/node/.eslintrc | 8 + test/node/expect.js | 36 ++ .../ol/AssertionError.test.js} | 7 +- .../ol/Collection.test.js} | 10 +- .../ol/Disposable.test.js} | 6 +- .../ol/Feature.test.js} | 12 +- .../object.test.js => node/ol/Object.test.js} | 8 +- .../ol/Observable.test.js} | 8 +- test/node/ol/array.test.js | 612 ++++++++++++++++++ test/node/ol/asserts.test.js | 12 + .../spec => node}/ol/coordinate.test.js | 9 +- test/{browser/spec => node}/ol/css.test.js | 3 +- test/{browser/spec => node}/ol/events.test.js | 8 +- .../ol/events/Target.test.js} | 13 +- .../spec => node}/ol/events/event.test.js | 6 +- test/{browser/spec => node}/ol/extent.test.js | 11 +- .../spec => node}/ol/functions.test.js | 5 +- .../ol/geom/Circle.test.js} | 6 +- .../ol/geom/GeometryCollection.test.js} | 14 +- .../ol/geom/LineString.test.js} | 8 +- .../ol/geom/MultiLineString.test.js} | 9 +- .../ol/geom/MultiPoint.test.js} | 10 +- .../ol/geom/MultiPolygon.test.js} | 7 +- .../ol/geom/Point.test.js} | 8 +- .../ol/geom/Polygon.test.js} | 11 +- .../spec => node}/ol/geom/flat/area.test.js | 12 +- .../spec => node}/ol/geom/flat/center.test.js | 9 +- .../ol/geom/flat/closest.test.js | 15 +- .../ol/geom/flat/contains.test.js | 7 +- .../ol/geom/flat/deflate.test.js | 9 +- .../spec => node}/ol/geom/flat/flip.test.js | 7 +- .../ol/geom/flat/inflate.test.js | 9 +- .../ol/geom/flat/interpolate.test.js | 7 +- .../ol/geom/flat/intersectsextent.test.js | 11 +- .../spec => node}/ol/geom/flat/length.test.js | 9 +- .../spec => node}/ol/geom/flat/orient.test.js | 15 +- .../ol/geom/flat/reverse.test.js | 7 +- .../ol/geom/flat/segments.test.js | 8 +- .../ol/geom/flat/simplify.test.js | 13 +- .../ol/geom/flat/straightchunk.test.js | 7 +- .../ol/geom/flat/textpath.test.js | 7 +- .../ol/geom/flat/topologyflatgeom.test.js | 7 +- .../ol/geom/flat/transform.test.js | 18 +- test/node/ol/math.test.js | 165 +++++ test/node/ol/obj.test.js | 67 ++ test/{browser/spec => node}/ol/proj.test.js | 16 +- .../ol/structs/linkedlist.test.js | 5 +- .../spec => node}/ol/structs/lrucache.test.js | 5 +- .../ol/structs/priorityqueue.test.js | 7 +- .../spec => node}/ol/structs/rbush.test.js | 5 +- .../ol/tilegrid/TileGrid.test.js} | 19 +- test/node/ol/util.test.js | 25 + .../spec => node}/ol/vec/mat4.test.js | 9 +- test/node/readme.md | 11 + 61 files changed, 1216 insertions(+), 449 deletions(-) delete mode 100644 test/browser/spec/ol/asserts.test.js delete mode 100644 test/browser/spec/ol/index.test.js delete mode 100644 test/browser/spec/ol/math.test.js delete mode 100644 test/browser/spec/ol/objectutil.test.js create mode 100644 test/node/.eslintrc create mode 100644 test/node/expect.js rename test/{browser/spec/ol/assertionerror.test.js => node/ol/AssertionError.test.js} (82%) rename test/{browser/spec/ol/collection.test.js => node/ol/Collection.test.js} (97%) rename test/{browser/spec/ol/disposable.test.js => node/ol/Disposable.test.js} (86%) rename test/{browser/spec/ol/feature.test.js => node/ol/Feature.test.js} (97%) rename test/{browser/spec/ol/object.test.js => node/ol/Object.test.js} (96%) rename test/{browser/spec/ol/observable.test.js => node/ol/Observable.test.js} (94%) create mode 100644 test/node/ol/array.test.js create mode 100644 test/node/ol/asserts.test.js rename test/{browser/spec => node}/ol/coordinate.test.js (97%) rename test/{browser/spec => node}/ol/css.test.js (94%) rename test/{browser/spec => node}/ol/events.test.js (93%) rename test/{browser/spec/ol/events/eventtarget.test.js => node/ol/events/Target.test.js} (94%) rename test/{browser/spec => node}/ol/events/event.test.js (90%) rename test/{browser/spec => node}/ol/extent.test.js (99%) rename test/{browser/spec => node}/ol/functions.test.js (92%) rename test/{browser/spec/ol/geom/circle.test.js => node/ol/geom/Circle.test.js} (98%) rename test/{browser/spec/ol/geom/geometrycollection.test.js => node/ol/geom/GeometryCollection.test.js} (94%) rename test/{browser/spec/ol/geom/linestring.test.js => node/ol/geom/LineString.test.js} (98%) rename test/{browser/spec/ol/geom/multilinestring.test.js => node/ol/geom/MultiLineString.test.js} (98%) rename test/{browser/spec/ol/geom/multipoint.test.js => node/ol/geom/MultiPoint.test.js} (97%) rename test/{browser/spec/ol/geom/multipolygon.test.js => node/ol/geom/MultiPolygon.test.js} (97%) rename test/{browser/spec/ol/geom/point.test.js => node/ol/geom/Point.test.js} (97%) rename test/{browser/spec/ol/geom/polygon.test.js => node/ol/geom/Polygon.test.js} (98%) rename test/{browser/spec => node}/ol/geom/flat/area.test.js (69%) rename test/{browser/spec => node}/ol/geom/flat/center.test.js (87%) rename test/{browser/spec => node}/ol/geom/flat/closest.test.js (94%) rename test/{browser/spec => node}/ol/geom/flat/contains.test.js (89%) rename test/{browser/spec => node}/ol/geom/flat/deflate.test.js (79%) rename test/{browser/spec => node}/ol/geom/flat/flip.test.js (84%) rename test/{browser/spec => node}/ol/geom/flat/inflate.test.js (72%) rename test/{browser/spec => node}/ol/geom/flat/interpolate.test.js (91%) rename test/{browser/spec => node}/ol/geom/flat/intersectsextent.test.js (92%) rename test/{browser/spec => node}/ol/geom/flat/length.test.js (91%) rename test/{browser/spec => node}/ol/geom/flat/orient.test.js (94%) rename test/{browser/spec => node}/ol/geom/flat/reverse.test.js (96%) rename test/{browser/spec => node}/ol/geom/flat/segments.test.js (87%) rename test/{browser/spec => node}/ol/geom/flat/simplify.test.js (97%) rename test/{browser/spec => node}/ol/geom/flat/straightchunk.test.js (88%) rename test/{browser/spec => node}/ol/geom/flat/textpath.test.js (95%) rename test/{browser/spec => node}/ol/geom/flat/topologyflatgeom.test.js (83%) rename test/{browser/spec => node}/ol/geom/flat/transform.test.js (93%) create mode 100644 test/node/ol/math.test.js create mode 100644 test/node/ol/obj.test.js rename test/{browser/spec => node}/ol/proj.test.js (98%) rename test/{browser/spec => node}/ol/structs/linkedlist.test.js (97%) rename test/{browser/spec => node}/ol/structs/lrucache.test.js (98%) rename test/{browser/spec => node}/ol/structs/priorityqueue.test.js (96%) rename test/{browser/spec => node}/ol/structs/rbush.test.js (98%) rename test/{browser/spec/ol/tilegrid/tilegrid.test.js => node/ol/tilegrid/TileGrid.test.js} (98%) create mode 100644 test/node/ol/util.test.js rename test/{browser/spec => node}/ol/vec/mat4.test.js (73%) create mode 100644 test/node/readme.md diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c142073ea7..e6a74332ee 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -47,8 +47,8 @@ jobs: - name: Run Tests run: npm run pretest - spec: - name: Spec + browser: + name: Browser runs-on: ubuntu-latest strategy: @@ -80,7 +80,42 @@ jobs: run: npm ci - name: Run Tests - run: npm run test-spec + run: npm run test-browser + + node: + name: Node + runs-on: ubuntu-latest + + strategy: + fail-fast: false + + steps: + - name: Clone Repository + uses: actions/checkout@v2 + + - name: Set Node.js Version + uses: actions/setup-node@v1 + with: + node-version: 16 + + - name: Determine Cache Directory + id: npm-cache + run: | + echo "::set-output name=dir::$(npm config get cache)" + + - name: Configure Job Cache + uses: actions/cache@v1 + with: + path: ${{ steps.npm-cache.outputs.dir }} + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + + - name: Install Dependencies + run: npm ci + + - name: Run Tests + run: npm run test-node build: name: Build diff --git a/package.json b/package.json index 295dc4712c..d4da79b8fc 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,9 @@ "lint": "eslint tasks test src/ol examples config", "pretest": "npm run lint && npm run typecheck", "test-rendering": "node test/rendering/test.js", - "test-spec": "npm run karma -- --single-run --log-level error", - "test": "npm run test-spec && npm run test-rendering -- --force", + "test-browser": "npm run karma -- --single-run --log-level error", + "test-node": "mocha --recursive test/node", + "test": "npm run test-browser && npm run test-node && npm run test-rendering -- --force", "karma": "karma start test/browser/karma.config.cjs", "start": "npm run serve-examples", "serve-examples": "webpack serve --config examples/webpack/config.js --mode development", diff --git a/test/README.md b/test/README.md index 841dce0f2a..76148408df 100644 --- a/test/README.md +++ b/test/README.md @@ -1,7 +1,7 @@ ## Included in this directory - browser - Unit/integration tests run in a browser - +- node - Unit tests run with Node.js - rendering - Tests that make assertions about rendered map output diff --git a/test/browser/spec/ol/asserts.test.js b/test/browser/spec/ol/asserts.test.js deleted file mode 100644 index d73603d738..0000000000 --- a/test/browser/spec/ol/asserts.test.js +++ /dev/null @@ -1,11 +0,0 @@ -import {assert} from '../../../../src/ol/asserts.js'; - -describe('ol.asserts', function () { - describe('ol.asserts.assert', function () { - it('throws an exception', function () { - expect(function () { - assert(false, 42); - }).to.throwException(); - }); - }); -}); diff --git a/test/browser/spec/ol/index.test.js b/test/browser/spec/ol/index.test.js deleted file mode 100644 index c715e5903c..0000000000 --- a/test/browser/spec/ol/index.test.js +++ /dev/null @@ -1,22 +0,0 @@ -import {getUid} from '../../../../src/ol/util.js'; - -describe('getUid()', function () { - it('is constant once generated', function () { - const a = {}; - expect(getUid(a)).to.be(getUid(a)); - }); - - it('generates a strictly increasing sequence', function () { - const a = {}; - const b = {}; - const c = {}; - getUid(a); - getUid(c); - getUid(b); - - //uid order should be a < c < b - expect(getUid(a)).to.be.lessThan(getUid(c)); - expect(getUid(c)).to.be.lessThan(getUid(b)); - expect(getUid(a)).to.be.lessThan(getUid(b)); - }); -}); diff --git a/test/browser/spec/ol/math.test.js b/test/browser/spec/ol/math.test.js deleted file mode 100644 index d1634fa1f9..0000000000 --- a/test/browser/spec/ol/math.test.js +++ /dev/null @@ -1,162 +0,0 @@ -import { - clamp, - cosh, - lerp, - log2, - modulo, - solveLinearSystem, - toDegrees, - toRadians, -} from '../../../../src/ol/math.js'; - -describe('ol.math.clamp', function () { - it('returns the correct value at -Infinity', function () { - expect(clamp(-Infinity, 10, 20)).to.eql(10); - }); - - it('returns the correct value at min', function () { - expect(clamp(10, 10, 20)).to.eql(10); - }); - - it('returns the correct value at mid point', function () { - expect(clamp(15, 10, 20)).to.eql(15); - }); - - it('returns the correct value at max', function () { - expect(clamp(20, 10, 20)).to.eql(20); - }); - - it('returns the correct value at Infinity', function () { - expect(clamp(Infinity, 10, 20)).to.eql(20); - }); -}); - -describe('ol.math.cosh', function () { - it('returns the correct value at -Infinity', function () { - expect(cosh(-Infinity)).to.eql(Infinity); - }); - - it('returns the correct value at -1', function () { - expect(cosh(-1)).to.roughlyEqual(1.5430806348152437, 1e-9); - }); - - it('returns the correct value at 0', function () { - expect(cosh(0)).to.eql(1); - }); - - it('returns the correct value at 1', function () { - expect(cosh(1)).to.roughlyEqual(1.5430806348152437, 1e-9); - }); - - it('returns the correct value at Infinity', function () { - expect(cosh(Infinity)).to.eql(Infinity); - }); -}); - -describe('ol.math.log2', function () { - it('returns the correct value at Infinity', function () { - expect(log2(Infinity)).to.eql(Infinity); - }); - - it('returns the correct value at 3', function () { - expect(log2(3)).to.roughlyEqual(1.584962500721156, 1e-9); - }); - - it('returns the correct value at 2', function () { - expect(log2(2)).to.eql(1); - }); - - it('returns the correct value at 1', function () { - expect(log2(1)).to.eql(0); - }); - - it('returns the correct value at 0', function () { - expect(log2(0)).to.eql(-Infinity); - }); - - it('returns the correct value at -1', function () { - expect(log2(-1).toString()).to.eql('NaN'); - }); -}); - -describe('ol.math.solveLinearSystem', function () { - it('calculates correctly', function () { - const result = solveLinearSystem([ - [2, 1, 3, 1], - [2, 6, 8, 3], - [6, 8, 18, 5], - ]); - expect(result[0]).to.roughlyEqual(0.3, 1e-9); - expect(result[1]).to.roughlyEqual(0.4, 1e-9); - expect(result[2]).to.roughlyEqual(0, 1e-9); - }); - - it('can handle singular matrix', function () { - const result = solveLinearSystem([ - [2, 1, 3, 1], - [2, 6, 8, 3], - [2, 1, 3, 1], - ]); - expect(result).to.be(null); - }); -}); - -describe('ol.math.toDegrees', function () { - it('returns the correct value at -π', function () { - expect(toDegrees(-Math.PI)).to.be(-180); - }); - it('returns the correct value at 0', function () { - expect(toDegrees(0)).to.be(0); - }); - it('returns the correct value at π', function () { - expect(toDegrees(Math.PI)).to.be(180); - }); -}); - -describe('ol.math.toRadians', function () { - it('returns the correct value at -180', function () { - expect(toRadians(-180)).to.be(-Math.PI); - }); - it('returns the correct value at 0', function () { - expect(toRadians(0)).to.be(0); - }); - it('returns the correct value at 180', function () { - expect(toRadians(180)).to.be(Math.PI); - }); -}); - -describe('ol.math.modulo', function () { - it('256 / 8 returns 0', function () { - expect(modulo(256, 8)).to.be(0); - }); - it('positive and positive returns a positive ', function () { - expect(modulo(7, 8)).to.be(7); - }); - it('same Dividend and Divisor returns 0', function () { - expect(modulo(4, 4)).to.be(0); - }); - it('negative and positive returns positive', function () { - expect(modulo(-3, 4)).to.be(1); - }); - it('negative and negative returns negative', function () { - expect(modulo(-4, -5)).to.be(-4); - expect(modulo(-3, -4)).to.be(-3); - }); - it('positive and negative returns negative', function () { - expect(modulo(3, -4)).to.be(-1); - expect(modulo(1, -5)).to.be(-4); - expect(modulo(6, -5)).to.be(-4); - }); -}); - -describe('ol.math.lerp', function () { - it('correctly interpolated numbers', function () { - expect(lerp(0, 0, 0)).to.be(0); - expect(lerp(0, 1, 0)).to.be(0); - expect(lerp(1, 11, 5)).to.be(51); - }); - it('correctly interpolates floats', function () { - expect(lerp(0, 1, 0.5)).to.be(0.5); - expect(lerp(0.25, 0.75, 0.5)).to.be(0.5); - }); -}); diff --git a/test/browser/spec/ol/objectutil.test.js b/test/browser/spec/ol/objectutil.test.js deleted file mode 100644 index 944333e3bc..0000000000 --- a/test/browser/spec/ol/objectutil.test.js +++ /dev/null @@ -1,64 +0,0 @@ -import {assign, clear, getValues, isEmpty} from '../../../../src/ol/obj.js'; - -describe('ol.obj.assign()', function () { - it('is an alias for Object.assign() where available', function () { - if (typeof Object.assign === 'function') { - expect(assign).to.be(Object.assign); - } - }); - - it('assigns properties from a source object to a target object', function () { - const source = { - sourceProp1: 'sourceValue1', - sourceProp2: 'sourceValue2', - }; - - const target = { - sourceProp1: 'overridden', - targetProp1: 'targetValue1', - }; - - const assigned = assign(target, source); - expect(assigned).to.be(target); - expect(assigned.sourceProp1).to.be('sourceValue1'); - expect(assigned.sourceProp2).to.be('sourceValue2'); - expect(assigned.targetProp1).to.be('targetValue1'); - }); - - it('throws a TypeError with `undefined` as target', function () { - expect(() => assign()).to.throwException( - /Cannot convert undefined or null to object/ - ); - }); - - it('throws a TypeError with `null` as target', function () { - expect(() => assign(null)).to.throwException( - /Cannot convert undefined or null to object/ - ); - }); -}); - -describe('ol.obj.clear()', function () { - it('removes all properties from an object', function () { - expect(isEmpty(clear({foo: 'bar'}))).to.be(true); - expect(isEmpty(clear({foo: 'bar', num: 42}))).to.be(true); - expect(isEmpty(clear({}))).to.be(true); - expect(isEmpty(clear(null))).to.be(true); - }); -}); - -describe('ol.obj.getValues()', function () { - it('gets a list of property values from an object', function () { - expect(getValues({foo: 'bar', num: 42}).sort()).to.eql([42, 'bar']); - expect(getValues([])).to.eql([]); - }); -}); - -describe('ol.obj.isEmpty()', function () { - it('checks if an object has any properties', function () { - expect(isEmpty({})).to.be(true); - expect(isEmpty(null)).to.be(true); - expect(isEmpty({foo: 'bar'})).to.be(false); - expect(isEmpty({foo: false})).to.be(false); - }); -}); diff --git a/test/node/.eslintrc b/test/node/.eslintrc new file mode 100644 index 0000000000..570d7bbef0 --- /dev/null +++ b/test/node/.eslintrc @@ -0,0 +1,8 @@ +{ + "env": { + "mocha": true + }, + "parserOptions": { + "ecmaVersion": 2017 + } +} diff --git a/test/node/expect.js b/test/node/expect.js new file mode 100644 index 0000000000..6f27c59977 --- /dev/null +++ b/test/node/expect.js @@ -0,0 +1,36 @@ +import expect from 'expect.js'; + +/** + * Assert value is within some tolerance of a number. + * @param {number} n Number. + * @param {number} tol Tolerance. + * @return {expect.Assertion} The assertion. + */ +expect.Assertion.prototype.roughlyEqual = function (n, tol) { + this.assert( + Math.abs(this.obj - n) <= tol, + function () { + return ( + 'expected ' + + expect.stringify(this.obj) + + ' to be within ' + + tol + + ' of ' + + n + ); + }, + function () { + return ( + 'expected ' + + expect.stringify(this.obj) + + ' not to be within ' + + tol + + ' of ' + + n + ); + } + ); + return this; +}; + +export default expect; diff --git a/test/browser/spec/ol/assertionerror.test.js b/test/node/ol/AssertionError.test.js similarity index 82% rename from test/browser/spec/ol/assertionerror.test.js rename to test/node/ol/AssertionError.test.js index d3e6d07f2e..859a8c37be 100644 --- a/test/browser/spec/ol/assertionerror.test.js +++ b/test/node/ol/AssertionError.test.js @@ -1,7 +1,8 @@ -import AssertionError from '../../../../src/ol/AssertionError.js'; -import {VERSION} from '../../../../src/ol/util.js'; +import AssertionError from '../../../src/ol/AssertionError.js'; +import expect from '../expect.js'; +import {VERSION} from '../../../src/ol/util.js'; -describe('ol.AssertionError', function () { +describe('ol/AssertionError.js', function () { it('generates an error', function () { const error = new AssertionError(42); expect(error).to.be.an(Error); diff --git a/test/browser/spec/ol/collection.test.js b/test/node/ol/Collection.test.js similarity index 97% rename from test/browser/spec/ol/collection.test.js rename to test/node/ol/Collection.test.js index f509f03cd0..6723172706 100644 --- a/test/browser/spec/ol/collection.test.js +++ b/test/node/ol/Collection.test.js @@ -1,8 +1,10 @@ -import Collection from '../../../../src/ol/Collection.js'; -import CollectionEventType from '../../../../src/ol/CollectionEventType.js'; -import {listen} from '../../../../src/ol/events.js'; +import Collection from '../../../src/ol/Collection.js'; +import CollectionEventType from '../../../src/ol/CollectionEventType.js'; +import expect from '../expect.js'; +import sinon from 'sinon'; +import {listen} from '../../../src/ol/events.js'; -describe('ol.collection', function () { +describe('ol/Collection.js', function () { let collection; beforeEach(function () { diff --git a/test/browser/spec/ol/disposable.test.js b/test/node/ol/Disposable.test.js similarity index 86% rename from test/browser/spec/ol/disposable.test.js rename to test/node/ol/Disposable.test.js index 278eceeaa3..f53a4cb83b 100644 --- a/test/browser/spec/ol/disposable.test.js +++ b/test/node/ol/Disposable.test.js @@ -1,6 +1,8 @@ -import Disposable from '../../../../src/ol/Disposable.js'; +import Disposable from '../../../src/ol/Disposable.js'; +import expect from '../expect.js'; +import sinon from 'sinon'; -describe('ol.Disposable', function () { +describe('ol/Disposable.js', function () { describe('constructor', function () { it('creates an instance', function () { const disposable = new Disposable(); diff --git a/test/browser/spec/ol/feature.test.js b/test/node/ol/Feature.test.js similarity index 97% rename from test/browser/spec/ol/feature.test.js rename to test/node/ol/Feature.test.js index 3941602b9b..28c8f000c8 100644 --- a/test/browser/spec/ol/feature.test.js +++ b/test/node/ol/Feature.test.js @@ -1,9 +1,11 @@ -import Feature, {createStyleFunction} from '../../../../src/ol/Feature.js'; -import Point from '../../../../src/ol/geom/Point.js'; -import Style from '../../../../src/ol/style/Style.js'; -import {isEmpty} from '../../../../src/ol/obj.js'; +import Feature, {createStyleFunction} from '../../../src/ol/Feature.js'; +import Point from '../../../src/ol/geom/Point.js'; +import Style from '../../../src/ol/style/Style.js'; +import expect from '../expect.js'; +import sinon from 'sinon'; +import {isEmpty} from '../../../src/ol/obj.js'; -describe('ol.Feature', function () { +describe('ol/Feature.js', function () { describe('constructor', function () { it('creates a new feature', function () { const feature = new Feature(); diff --git a/test/browser/spec/ol/object.test.js b/test/node/ol/Object.test.js similarity index 96% rename from test/browser/spec/ol/object.test.js rename to test/node/ol/Object.test.js index f54429cf9b..4ff443464f 100644 --- a/test/browser/spec/ol/object.test.js +++ b/test/node/ol/Object.test.js @@ -1,7 +1,9 @@ -import BaseObject from '../../../../src/ol/Object.js'; -import {listen} from '../../../../src/ol/events.js'; +import BaseObject from '../../../src/ol/Object.js'; +import expect from '../expect.js'; +import sinon from 'sinon'; +import {listen} from '../../../src/ol/events.js'; -describe('ol.Object', function () { +describe('ol/Object.js', function () { let o; beforeEach(function () { o = new BaseObject(); diff --git a/test/browser/spec/ol/observable.test.js b/test/node/ol/Observable.test.js similarity index 94% rename from test/browser/spec/ol/observable.test.js rename to test/node/ol/Observable.test.js index 73ea92a177..6a893cd31c 100644 --- a/test/browser/spec/ol/observable.test.js +++ b/test/node/ol/Observable.test.js @@ -1,7 +1,9 @@ -import EventTarget from '../../../../src/ol/events/Target.js'; -import Observable, {unByKey} from '../../../../src/ol/Observable.js'; +import EventTarget from '../../../src/ol/events/Target.js'; +import Observable, {unByKey} from '../../../src/ol/Observable.js'; +import expect from '../expect.js'; +import sinon from 'sinon'; -describe('ol.Observable', function () { +describe('ol/Observable.js', function () { describe('constructor', function () { it('creates a new observable', function () { const observable = new Observable(); diff --git a/test/node/ol/array.test.js b/test/node/ol/array.test.js new file mode 100644 index 0000000000..6f7b07b3d4 --- /dev/null +++ b/test/node/ol/array.test.js @@ -0,0 +1,612 @@ +import expect from '../expect.js'; +import { + binarySearch, + equals, + extend, + find, + findIndex, + isSorted, + linearFindNearest, + numberSafeCompareFunction, + remove, + reverseSubArray, + stableSort, +} from '../../../src/ol/array.js'; + +describe('ol/array.js', function () { + describe('binarySearch', function () { + const insertionPoint = function (position) { + return -(position + 1); + }; + const revNumCompare = function (a, b) { + return b - a; + }; + + describe('default comparison on array of String(s)', function () { + const a = [ + '1000', + '9', + 'AB', + 'ABC', + 'ABCABC', + 'ABD', + 'ABDA', + 'B', + 'B', + 'B', + 'C', + 'CA', + 'CC', + 'ZZZ', + 'ab', + 'abc', + 'abcabc', + 'abd', + 'abda', + 'b', + 'c', + 'ca', + 'cc', + 'zzz', + ]; + + it("should find '1000' at index 0", function () { + expect(binarySearch(a, '1000')).to.be(0); + }); + it("should find 'zzz' at index " + (a.length - 1), function () { + expect(binarySearch(a, 'zzz')).to.be(a.length - 1); + }); + it("should find 'C' at index 10", function () { + expect(binarySearch(a, 'C')).to.be(10); + }); + it("should find 'B' at index 7 || 8 || 9", function () { + const pos = binarySearch(a, 'B'); + expect(pos == 7 || pos == 8 || pos == 9).to.be.ok(); + }); + it("should not find '100'", function () { + const pos = binarySearch(a, '100'); + expect(pos < 0).to.be.ok(); + }); + it("should have an insertion point of 0 for '100'", function () { + const pos = binarySearch(a, '100'); + expect(insertionPoint(pos)).to.be(0); + }); + it("should not find 'zzz0'", function () { + const pos = binarySearch(a, 'zzz0'); + expect(pos < 0).to.be.ok(); + }); + it( + 'should have an insertion point of ' + a.length + " for 'zzz0'", + function () { + const pos = binarySearch(a, 'zzz0'); + expect(insertionPoint(pos)).to.be(a.length); + } + ); + it("should not find 'BA'", function () { + const pos = binarySearch(a, 'zzz0'); + expect(pos < 0).to.be.ok(); + }); + it("should have an insertion point of 10 for 'BA'", function () { + const pos = binarySearch(a, 'BA'); + expect(insertionPoint(pos)).to.be(10); + }); + }); + + describe('0 length array with default comparison', function () { + const b = []; + it("should not find 'a'", function () { + expect(binarySearch(b, 'a') < 0).to.be.ok(); + }); + it("should have an insertion point of 0 for 'a'", function () { + const pos = binarySearch(b, 'a'); + expect(insertionPoint(pos)).to.be(0); + }); + }); + + describe('single element array with default lexiographical comparison', function () { + const c = ['only item']; + it("should find 'only item' at index 0", function () { + expect(binarySearch(c, 'only item')).to.be(0); + }); + it("should not find 'a'", function () { + expect(binarySearch(c, 'a') < 0).to.be.ok(); + }); + it("should have an insertion point of 0 for 'a'", function () { + const pos = binarySearch(c, 'a'); + expect(insertionPoint(pos)).to.be(0); + }); + it("should not find 'z'", function () { + expect(binarySearch(c, 'z') < 0).to.be.ok(); + }); + it("should have an insertion point of 1 for 'z'", function () { + const pos = binarySearch(c, 'z'); + expect(insertionPoint(pos)).to.be(1); + }); + }); + + describe('default comparison on array of Number(s)', function () { + const d = [ + -897123.9, + -321434.58758, + -1321.3124, + -324, + -9, + -3, + 0, + 0, + 0, + 0.31255, + 5, + 142.88888708, + 334, + 342, + 453, + 54254, + ]; + it('should find -897123.9 at index 0', function () { + expect(binarySearch(d, -897123.9)).to.be(0); + }); + it('should find 54254 at index ' + (d.length - 1), function () { + expect(binarySearch(d, 54254)).to.be(d.length - 1); + }); + it('should find -3 at index 5', function () { + expect(binarySearch(d, -3)).to.be(5); + }); + it('should find 0 at index 6 || 7 || 8', function () { + const pos = binarySearch(d, 0); + expect(pos == 6 || pos == 7 || pos == 8).to.be(true); + }); + it('should not find -900000', function () { + const pos = binarySearch(d, -900000); + expect(pos < 0).to.be(true); + }); + it('should have an insertion point of 0 for -900000', function () { + const pos = binarySearch(d, -900000); + expect(insertionPoint(pos)).to.be(0); + }); + it('should not find 54255', function () { + const pos = binarySearch(d, 54255); + expect(pos < 0).to.be(true); + }); + it( + 'should have an insertion point of ' + d.length + ' for 54255', + function () { + const pos = binarySearch(d, 54255); + expect(insertionPoint(pos)).to.be(d.length); + } + ); + it('should not find 1.1', function () { + const pos = binarySearch(d, 1.1); + expect(pos < 0).to.be(true); + }); + it('should have an insertion point of 10 for 1.1', function () { + const pos = binarySearch(d, 1.1); + expect(insertionPoint(pos)).to.be(10); + }); + }); + + describe('custom comparison function, which reverse orders numbers', function () { + const e = [ + 54254, + 453, + 342, + 334, + 142.88888708, + 5, + 0.31255, + 0, + 0, + 0, + -3, + -9, + -324, + -1321.3124, + -321434.58758, + -897123.9, + ]; + it('should find 54254 at index 0', function () { + const pos = binarySearch(e, 54254, revNumCompare); + expect(pos).to.be(0); + }); + it('should find -897123.9 at index ' + (e.length - 1), function () { + const pos = binarySearch(e, -897123.9, revNumCompare); + expect(pos).to.be(e.length - 1); + }); + it('should find -3 at index 10', function () { + const pos = binarySearch(e, -3, revNumCompare); + expect(pos).to.be(10); + }); + it('should find 0 at index 7 || 8 || 9', function () { + const pos = binarySearch(e, 0, revNumCompare); + expect(pos == 7 || pos == 8 || pos == 9).to.be(true); + }); + it('should not find 54254.1', function () { + const pos = binarySearch(e, 54254.1, revNumCompare); + expect(pos < 0).to.be(true); + }); + it('should have an insertion point of 0 for 54254.1', function () { + const pos = binarySearch(e, 54254.1, revNumCompare); + expect(insertionPoint(pos)).to.be(0); + }); + it('should not find -897124', function () { + const pos = binarySearch(e, -897124, revNumCompare); + expect(pos < 0).to.be(true); + }); + it( + 'should have an insertion point of ' + e.length + ' for -897124', + function () { + const pos = binarySearch(e, -897124, revNumCompare); + expect(insertionPoint(pos)).to.be(e.length); + } + ); + it('should not find 1.1', function () { + const pos = binarySearch(e, 1.1, revNumCompare); + expect(pos < 0).to.be(true); + }); + it('should have an insertion point of 0 for 1.1', function () { + const pos = binarySearch(e, 1.1, revNumCompare); + expect(insertionPoint(pos)).to.be(6); + }); + }); + + describe('0 length array with custom comparison function', function () { + const f = []; + it('should not find 0', function () { + const pos = binarySearch(f, 0, revNumCompare); + expect(pos < 0).to.be(true); + }); + it('should have an insertion point of 0 for 0', function () { + const pos = binarySearch(f, 0, revNumCompare); + expect(insertionPoint(pos)).to.be(0); + }); + }); + + describe('single element array with custom comparison function', function () { + const g = [1]; + it('should find 1 at index 0', function () { + const pos = binarySearch(g, 1, revNumCompare); + expect(pos).to.be(0); + }); + it('should not find 2', function () { + const pos = binarySearch(g, 2, revNumCompare); + expect(pos < 0).to.be(true); + }); + it('should have an insertion point of 0 for 2', function () { + const pos = binarySearch(g, 2, revNumCompare); + expect(insertionPoint(pos)).to.be(0); + }); + it('should not find 0', function () { + const pos = binarySearch(g, 0, revNumCompare); + expect(pos < 0).to.be(true); + }); + it('should have an insertion point of 1 for 0', function () { + const pos = binarySearch(g, 0, revNumCompare); + expect(insertionPoint(pos)).to.be(1); + }); + }); + + describe('finding first index when multiple candidates', function () { + it('should find the index of the first 0', function () { + expect(binarySearch([0, 0, 1], 0)).to.be(0); + }); + it('should find the index of the first 1', function () { + expect(binarySearch([0, 1, 1], 1)).to.be(1); + }); + }); + + describe("Don't use Array#slice, Function#apply and Function#call", function () { + const a = [1, 5, 7, 11, 13, 16, 19, 24, 28, 31, 33, 36, 40, 50, 52, 55]; + const calls = { + 'Array#slice': false, + 'Function#apply': false, + 'Function#call': false, + }; + let origArraySlice; + let origFunctionApply; + let origFunctionCall; + + it('does not use potentially slow methods (default & custom compare)', function () { + // Mockup (I failed to use sinon.spy and beforeEach-hooks) + origArraySlice = Array.prototype.slice; + origFunctionApply = Function.prototype.apply; + origFunctionCall = Function.prototype.call; + Array.prototype.slice = function () { + calls['Array#slice'] = true; + }; + Function.prototype.apply = function () { + calls['Function#apply'] = true; + }; + Function.prototype.call = function () { + calls['Function#call'] = true; + }; + + // Now actually call and test the method twice + binarySearch(a, 48); + binarySearch(a, 13, function (a, b) { + return a > b ? 1 : a < b ? -1 : 0; + }); + + // Restore mocked up methods + Array.prototype.slice = origArraySlice; + Function.prototype.apply = origFunctionApply; + Function.prototype.call = origFunctionCall; + + // Expectations + expect(calls['Array#slice']).to.be(false); + expect(calls['Function#apply']).to.be(false); + expect(calls['Function#call']).to.be(false); + }); + }); + + describe('when items are not found', function () { + const arr = [1, 2, 2, 2, 3, 5, 9]; + + it('should return the index of where the item would go plus one, negated, if the item is not found', function () { + expect(binarySearch(arr, 4)).to.equal(-6); + }); + it('should work even on empty arrays', function () { + expect(binarySearch([], 42)).to.equal(-1); + }); + it('should work even on arrays of doubles', function () { + expect(binarySearch([0.0, 0.1, 0.2, 0.3, 0.4], 0.25)).to.equal(-4); + }); + }); + }); + + describe('equals', function () { + it('returns true for [] == []', function () { + expect(equals([], [])).to.be(true); + }); + it('returns true for [1] == [1]', function () { + expect(equals([1], [1])).to.be(true); + }); + it("returns true for ['1'] == ['1']", function () { + expect(equals(['1'], ['1'])).to.be(true); + }); + it("returns false for [1] == ['1']", function () { + expect(equals([1], ['1'])).to.be(false); + }); + it('returns true for [null] == [null]', function () { + expect(equals([null], [null])).to.be(true); + }); + it('returns false for [null] == [undefined]', function () { + expect(equals([null], [undefined])).to.be(false); + }); + it('returns true for [1, 2] == [1, 2]', function () { + expect(equals([1, 2], [1, 2])).to.be(true); + }); + it('returns false for [1, 2] == [2, 1]', function () { + expect(equals([1, 2], [2, 1])).to.be(false); + }); + it('returns false for [1, 2] == [1]', function () { + expect(equals([1, 2], [1])).to.be(false); + }); + it('returns false for [1] == [1, 2]', function () { + expect(equals([1], [1, 2])).to.be(false); + }); + it('returns false for [{}] == [{}]', function () { + expect(equals([{}], [{}])).to.be(false); + }); + }); + describe('extend', function () { + it('extends an array in place with an array', function () { + const a = [0, 1]; + extend(a, [2, 3]); + expect(a).to.eql([0, 1, 2, 3]); + }); + it('extends an array in place with a number', function () { + const a = [0, 1]; + extend(a, 2); + expect(a).to.eql([0, 1, 2]); + }); + it('extends an array in place with a big array', function () { + const a = []; + let i = 250000; // original test has 1.000.000, but that was too slow + const bigArray = Array(i); + while (i--) { + bigArray[i] = i; + } + extend(a, bigArray); + expect(a).to.eql(bigArray); + }); + }); + + describe('find', function () { + it('finds numbers in an array', function () { + const a = [0, 1, 2, 3]; + const b = find(a, function (val, index, a2) { + expect(a).to.equal(a2); + expect(typeof index).to.be('number'); + return val > 1; + }); + expect(b).to.be(2); + }); + + it('returns null when an item in an array is not found', function () { + const a = [0, 1, 2, 3]; + const b = find(a, function (val, index, a2) { + return val > 100; + }); + expect(b).to.be(null); + }); + + it('finds items in an array-like', function () { + const a = 'abCD'; + const b = find(a, function (val, index, a2) { + expect(a).to.equal(a2); + expect(typeof index).to.be('number'); + return val >= 'A' && val <= 'Z'; + }); + expect(b).to.be('C'); + }); + + it('returns null when nothing in an array-like is found', function () { + const a = 'abcd'; + const b = find(a, function (val, index, a2) { + return val >= 'A' && val <= 'Z'; + }); + expect(b).to.be(null); + }); + }); + + describe('findIndex', function () { + it('finds index of numbers in an array', function () { + const a = [0, 1, 2, 3]; + const b = findIndex(a, function (val, index, a2) { + expect(a).to.equal(a2); + expect(typeof index).to.be('number'); + return val > 1; + }); + expect(b).to.be(2); + }); + + it('returns -1 when an item in an array is not found', function () { + const a = [0, 1, 2, 3]; + const b = findIndex(a, function (val, index, a2) { + return val > 100; + }); + expect(b).to.be(-1); + }); + }); + + describe('isSorted', function () { + it('works with just an array as argument', function () { + expect(isSorted([1, 2, 3])).to.be(true); + expect(isSorted([1, 2, 2])).to.be(true); + expect(isSorted([1, 2, 1])).to.be(false); + }); + + it('works with strict comparison without compare function', function () { + expect(isSorted([1, 2, 3], null, true)).to.be(true); + expect(isSorted([1, 2, 2], null, true)).to.be(false); + expect(isSorted([1, 2, 1], null, true)).to.be(false); + }); + + it('works with a compare function', function () { + function compare(a, b) { + return b - a; + } + expect(isSorted([1, 2, 3], compare)).to.be(false); + expect(isSorted([3, 2, 2], compare)).to.be(true); + }); + }); + + describe('linearFindNearest', function () { + it('returns expected value', function () { + const arr = [1000, 500, 100]; + + expect(linearFindNearest(arr, 10000, 0)).to.eql(0); + expect(linearFindNearest(arr, 10000, 1)).to.eql(0); + expect(linearFindNearest(arr, 10000, -1)).to.eql(0); + + expect(linearFindNearest(arr, 1000, 0)).to.eql(0); + expect(linearFindNearest(arr, 1000, 1)).to.eql(0); + expect(linearFindNearest(arr, 1000, -1)).to.eql(0); + + expect(linearFindNearest(arr, 900, 0)).to.eql(0); + expect(linearFindNearest(arr, 900, 1)).to.eql(0); + expect(linearFindNearest(arr, 900, -1)).to.eql(1); + + expect(linearFindNearest(arr, 750, 0)).to.eql(1); + expect(linearFindNearest(arr, 750, 1)).to.eql(0); + expect(linearFindNearest(arr, 750, -1)).to.eql(1); + + expect(linearFindNearest(arr, 550, 0)).to.eql(1); + expect(linearFindNearest(arr, 550, 1)).to.eql(0); + expect(linearFindNearest(arr, 550, -1)).to.eql(1); + + expect(linearFindNearest(arr, 500, 0)).to.eql(1); + expect(linearFindNearest(arr, 500, 1)).to.eql(1); + expect(linearFindNearest(arr, 500, -1)).to.eql(1); + + expect(linearFindNearest(arr, 450, 0)).to.eql(1); + expect(linearFindNearest(arr, 450, 1)).to.eql(1); + expect(linearFindNearest(arr, 450, -1)).to.eql(2); + + expect(linearFindNearest(arr, 300, 0)).to.eql(2); + expect(linearFindNearest(arr, 300, 1)).to.eql(1); + expect(linearFindNearest(arr, 300, -1)).to.eql(2); + + expect(linearFindNearest(arr, 200, 0)).to.eql(2); + expect(linearFindNearest(arr, 200, 1)).to.eql(1); + expect(linearFindNearest(arr, 200, -1)).to.eql(2); + + expect(linearFindNearest(arr, 100, 0)).to.eql(2); + expect(linearFindNearest(arr, 100, 1)).to.eql(2); + expect(linearFindNearest(arr, 100, -1)).to.eql(2); + + expect(linearFindNearest(arr, 50, 0)).to.eql(2); + expect(linearFindNearest(arr, 50, 1)).to.eql(2); + expect(linearFindNearest(arr, 50, -1)).to.eql(2); + }); + }); + + describe('numberSafeCompareFunction', function () { + it('sorts as expected', function () { + const arr = [40, 200, 3000]; + // default sort would yield [200, 3000, 40] + arr.sort(numberSafeCompareFunction); + expect(arr).to.eql(arr); + }); + }); + + describe('remove', function () { + it('removes elements from an array', function () { + const a = ['a', 'b', 'c', 'd']; + remove(a, 'c'); + expect(a).to.eql(['a', 'b', 'd']); + remove(a, 'x'); + expect(a).to.eql(['a', 'b', 'd']); + }); + }); + + describe('reverseSubArray', function () { + it('returns expected value', function () { + let arr; + const expected = [1, 2, 3, 4, 5, 6]; + + arr = [1, 5, 4, 3, 2, 6]; + reverseSubArray(arr, 1, 4); + expect(arr).to.eql(expected); + + arr = [3, 2, 1, 4, 5, 6]; + reverseSubArray(arr, 0, 2); + expect(arr).to.eql(expected); + + arr = [1, 2, 3, 6, 5, 4]; + reverseSubArray(arr, 3, 5); + expect(arr).to.eql(expected); + + arr = [6, 5, 4, 3, 2, 1]; + reverseSubArray(arr, 0, 5); + expect(arr).to.eql(expected); + }); + }); + + describe('stableSort', function () { + let arr, wantedSortedValues; + + beforeEach(function () { + arr = [ + {key: 3, val: 'a'}, + {key: 2, val: 'b'}, + {key: 3, val: 'c'}, + {key: 4, val: 'd'}, + {key: 3, val: 'e'}, + ]; + wantedSortedValues = ['b', 'a', 'c', 'e', 'd']; + }); + + it('works on an array with custom comparison function', function () { + function comparisonFn(obj1, obj2) { + return obj1.key - obj2.key; + } + stableSort(arr, comparisonFn); + const sortedValues = []; + for (let i = 0; i < arr.length; i++) { + sortedValues.push(arr[i].val); + } + expect(wantedSortedValues).to.eql(sortedValues); + }); + }); +}); diff --git a/test/node/ol/asserts.test.js b/test/node/ol/asserts.test.js new file mode 100644 index 0000000000..80bd245952 --- /dev/null +++ b/test/node/ol/asserts.test.js @@ -0,0 +1,12 @@ +import expect from '../expect.js'; +import {assert} from '../../../src/ol/asserts.js'; + +describe('ol/asserts.js', function () { + describe('assert', function () { + it('throws an exception', function () { + expect(function () { + assert(false, 42); + }).to.throwException(); + }); + }); +}); diff --git a/test/browser/spec/ol/coordinate.test.js b/test/node/ol/coordinate.test.js similarity index 97% rename from test/browser/spec/ol/coordinate.test.js rename to test/node/ol/coordinate.test.js index abb4f3b7fe..cf0fac2cab 100644 --- a/test/browser/spec/ol/coordinate.test.js +++ b/test/node/ol/coordinate.test.js @@ -1,5 +1,6 @@ -import Circle from '../../../../src/ol/geom/Circle.js'; -import Projection from '../../../../src/ol/proj/Projection.js'; +import Circle from '../../../src/ol/geom/Circle.js'; +import Projection from '../../../src/ol/proj/Projection.js'; +import expect from '../expect.js'; import { add as addCoordinate, closestOnCircle, @@ -13,8 +14,8 @@ import { toStringHDMS, toStringXY, wrapX, -} from '../../../../src/ol/coordinate.js'; -import {get} from '../../../../src/ol/proj.js'; +} from '../../../src/ol/coordinate.js'; +import {get} from '../../../src/ol/proj.js'; describe('ol.coordinate', function () { describe('#add', function () { diff --git a/test/browser/spec/ol/css.test.js b/test/node/ol/css.test.js similarity index 94% rename from test/browser/spec/ol/css.test.js rename to test/node/ol/css.test.js index c3c2d06c80..90c51d572e 100644 --- a/test/browser/spec/ol/css.test.js +++ b/test/node/ol/css.test.js @@ -1,4 +1,5 @@ -import {getFontParameters} from '../../../../src/ol/css.js'; +import expect from '../expect.js'; +import {getFontParameters} from '../../../src/ol/css.js'; describe('ol.css', function () { describe('getFontParameters()', function () { diff --git a/test/browser/spec/ol/events.test.js b/test/node/ol/events.test.js similarity index 93% rename from test/browser/spec/ol/events.test.js rename to test/node/ol/events.test.js index e11745c546..d3482ac3fa 100644 --- a/test/browser/spec/ol/events.test.js +++ b/test/node/ol/events.test.js @@ -1,7 +1,9 @@ -import EventTarget from '../../../../src/ol/events/Target.js'; -import {listen, listenOnce, unlistenByKey} from '../../../../src/ol/events.js'; +import EventTarget from '../../../src/ol/events/Target.js'; +import expect from '../expect.js'; +import sinon from 'sinon'; +import {listen, listenOnce, unlistenByKey} from '../../../src/ol/events.js'; -describe('ol.events', function () { +describe('ol/events.js', function () { let add, target; beforeEach(function () { diff --git a/test/browser/spec/ol/events/eventtarget.test.js b/test/node/ol/events/Target.test.js similarity index 94% rename from test/browser/spec/ol/events/eventtarget.test.js rename to test/node/ol/events/Target.test.js index 76e92903a2..f8dcdb8575 100644 --- a/test/browser/spec/ol/events/eventtarget.test.js +++ b/test/node/ol/events/Target.test.js @@ -1,9 +1,10 @@ -import Disposable from '../../../../../src/ol/Disposable.js'; -import Event from '../../../../../src/ol/events/Event.js'; -import EventTarget from '../../../../../src/ol/events/Target.js'; -import {listen} from '../../../../../src/ol/events.js'; +import Disposable from '../../../../src/ol/Disposable.js'; +import Event from '../../../../src/ol/events/Event.js'; +import EventTarget from '../../../../src/ol/events/Target.js'; +import expect from '../../expect.js'; +import {listen} from '../../../../src/ol/events.js'; -describe('ol.events.EventTarget', function () { +describe('ol/events/Target.js', function () { let called, events, eventTarget, spy1, spy2, spy3; beforeEach(function () { @@ -166,7 +167,7 @@ describe('ol.events.EventTarget', function () { describe('#dispose()', function () { it('cleans up foreign references', function () { - listen(eventTarget, 'foo', spy1, document); + listen(eventTarget, 'foo', spy1); expect(eventTarget.hasListener('foo')).to.be(true); eventTarget.dispose(); expect(eventTarget.hasListener('foo')).to.be(false); diff --git a/test/browser/spec/ol/events/event.test.js b/test/node/ol/events/event.test.js similarity index 90% rename from test/browser/spec/ol/events/event.test.js rename to test/node/ol/events/event.test.js index fdd74eda01..a2cdc9c45b 100644 --- a/test/browser/spec/ol/events/event.test.js +++ b/test/node/ol/events/event.test.js @@ -1,9 +1,11 @@ import Event, { preventDefault, stopPropagation, -} from '../../../../../src/ol/events/Event.js'; +} from '../../../../src/ol/events/Event.js'; +import expect from '../../expect.js'; +import sinon from 'sinon'; -describe('ol.events.Event', function () { +describe('ol/events/Event.js', function () { describe('constructor', function () { it('takes a type as argument', function () { const event = new Event('foo'); diff --git a/test/browser/spec/ol/extent.test.js b/test/node/ol/extent.test.js similarity index 99% rename from test/browser/spec/ol/extent.test.js rename to test/node/ol/extent.test.js index 639b0604ff..6147492c8c 100644 --- a/test/browser/spec/ol/extent.test.js +++ b/test/node/ol/extent.test.js @@ -1,8 +1,11 @@ -import * as _ol_extent_ from '../../../../src/ol/extent.js'; -import {get, getTransform} from '../../../../src/ol/proj.js'; -import {register} from '../../../../src/ol/proj/proj4.js'; +import * as _ol_extent_ from '../../../src/ol/extent.js'; +import expect from '../expect.js'; +import proj4 from 'proj4'; +import sinon from 'sinon'; +import {get, getTransform} from '../../../src/ol/proj.js'; +import {register} from '../../../src/ol/proj/proj4.js'; -describe('ol.extent', function () { +describe('ol/extent.js', function () { describe('buffer', function () { it('buffers an extent by some value', function () { const extent = [-10, -20, 10, 20]; diff --git a/test/browser/spec/ol/functions.test.js b/test/node/ol/functions.test.js similarity index 92% rename from test/browser/spec/ol/functions.test.js rename to test/node/ol/functions.test.js index 913f575cc0..f3001a3533 100644 --- a/test/browser/spec/ol/functions.test.js +++ b/test/node/ol/functions.test.js @@ -1,6 +1,7 @@ -import {memoizeOne} from '../../../../src/ol/functions.js'; +import expect from '../expect.js'; +import {memoizeOne} from '../../../src/ol/functions.js'; -describe('ol/functions', function () { +describe('ol/functions.js', function () { describe('memoizeOne()', function () { it('returns the result from the first call when called a second time with the same args', function () { const arg1 = {}; diff --git a/test/browser/spec/ol/geom/circle.test.js b/test/node/ol/geom/Circle.test.js similarity index 98% rename from test/browser/spec/ol/geom/circle.test.js rename to test/node/ol/geom/Circle.test.js index b650989741..34b990de49 100644 --- a/test/browser/spec/ol/geom/circle.test.js +++ b/test/node/ol/geom/Circle.test.js @@ -1,6 +1,8 @@ -import Circle from '../../../../../src/ol/geom/Circle.js'; +import Circle from '../../../../src/ol/geom/Circle.js'; +import expect from '../../expect.js'; +import sinon from 'sinon'; -describe('ol.geom.Circle', function () { +describe('ol/geom/Circle.js', function () { describe('with a unit circle', function () { let circle; beforeEach(function () { diff --git a/test/browser/spec/ol/geom/geometrycollection.test.js b/test/node/ol/geom/GeometryCollection.test.js similarity index 94% rename from test/browser/spec/ol/geom/geometrycollection.test.js rename to test/node/ol/geom/GeometryCollection.test.js index 00a496200d..e44ca727b1 100644 --- a/test/browser/spec/ol/geom/geometrycollection.test.js +++ b/test/node/ol/geom/GeometryCollection.test.js @@ -1,10 +1,12 @@ -import Geometry from '../../../../../src/ol/geom/Geometry.js'; -import GeometryCollection from '../../../../../src/ol/geom/GeometryCollection.js'; -import LineString from '../../../../../src/ol/geom/LineString.js'; -import Point from '../../../../../src/ol/geom/Point.js'; -import Polygon from '../../../../../src/ol/geom/Polygon.js'; +import Geometry from '../../../../src/ol/geom/Geometry.js'; +import GeometryCollection from '../../../../src/ol/geom/GeometryCollection.js'; +import LineString from '../../../../src/ol/geom/LineString.js'; +import Point from '../../../../src/ol/geom/Point.js'; +import Polygon from '../../../../src/ol/geom/Polygon.js'; +import expect from '../../expect.js'; +import sinon from 'sinon'; -describe('ol.geom.GeometryCollection', function () { +describe('ol/geom/GeometryCollection.js', function () { const outer = [ [0, 0], [0, 10], diff --git a/test/browser/spec/ol/geom/linestring.test.js b/test/node/ol/geom/LineString.test.js similarity index 98% rename from test/browser/spec/ol/geom/linestring.test.js rename to test/node/ol/geom/LineString.test.js index d18f200a9a..1a51580a3b 100644 --- a/test/browser/spec/ol/geom/linestring.test.js +++ b/test/node/ol/geom/LineString.test.js @@ -1,7 +1,9 @@ -import LineString from '../../../../../src/ol/geom/LineString.js'; -import {isEmpty} from '../../../../../src/ol/extent.js'; +import LineString from '../../../../src/ol/geom/LineString.js'; +import expect from '../../expect.js'; +import sinon from 'sinon'; +import {isEmpty} from '../../../../src/ol/extent.js'; -describe('ol.geom.LineString', function () { +describe('ol/geom/LineString.js', function () { it('cannot be constructed with a null geometry', function () { expect(function () { return new LineString(null); diff --git a/test/browser/spec/ol/geom/multilinestring.test.js b/test/node/ol/geom/MultiLineString.test.js similarity index 98% rename from test/browser/spec/ol/geom/multilinestring.test.js rename to test/node/ol/geom/MultiLineString.test.js index ed7554f0a6..8bf4c2a7ee 100644 --- a/test/browser/spec/ol/geom/multilinestring.test.js +++ b/test/node/ol/geom/MultiLineString.test.js @@ -1,8 +1,9 @@ -import LineString from '../../../../../src/ol/geom/LineString.js'; -import MultiLineString from '../../../../../src/ol/geom/MultiLineString.js'; -import {isEmpty} from '../../../../../src/ol/extent.js'; +import LineString from '../../../../src/ol/geom/LineString.js'; +import MultiLineString from '../../../../src/ol/geom/MultiLineString.js'; +import expect from '../../expect.js'; +import {isEmpty} from '../../../../src/ol/extent.js'; -describe('ol.geom.MultiLineString', function () { +describe('ol/geom/MultiLineString.js', function () { it('cannot be constructed with a null geometry', function () { expect(function () { return new MultiLineString(null); diff --git a/test/browser/spec/ol/geom/multipoint.test.js b/test/node/ol/geom/MultiPoint.test.js similarity index 97% rename from test/browser/spec/ol/geom/multipoint.test.js rename to test/node/ol/geom/MultiPoint.test.js index 03915d8e75..085151c1c1 100644 --- a/test/browser/spec/ol/geom/multipoint.test.js +++ b/test/node/ol/geom/MultiPoint.test.js @@ -1,8 +1,10 @@ -import MultiPoint from '../../../../../src/ol/geom/MultiPoint.js'; -import Point from '../../../../../src/ol/geom/Point.js'; -import {isEmpty} from '../../../../../src/ol/extent.js'; +import MultiPoint from '../../../../src/ol/geom/MultiPoint.js'; +import Point from '../../../../src/ol/geom/Point.js'; +import expect from '../../expect.js'; +import sinon from 'sinon'; +import {isEmpty} from '../../../../src/ol/extent.js'; -describe('ol.geom.MultiPoint', function () { +describe('ol/geom/MultiPoint.js', function () { it('cannot be constructed with a null geometry', function () { expect(function () { return new MultiPoint(null); diff --git a/test/browser/spec/ol/geom/multipolygon.test.js b/test/node/ol/geom/MultiPolygon.test.js similarity index 97% rename from test/browser/spec/ol/geom/multipolygon.test.js rename to test/node/ol/geom/MultiPolygon.test.js index a63e7865a2..722da6c708 100644 --- a/test/browser/spec/ol/geom/multipolygon.test.js +++ b/test/node/ol/geom/MultiPolygon.test.js @@ -1,7 +1,8 @@ -import MultiPolygon from '../../../../../src/ol/geom/MultiPolygon.js'; -import Polygon from '../../../../../src/ol/geom/Polygon.js'; +import MultiPolygon from '../../../../src/ol/geom/MultiPolygon.js'; +import Polygon from '../../../../src/ol/geom/Polygon.js'; +import expect from '../../expect.js'; -describe('ol.geom.MultiPolygon', function () { +describe('ol/geom/MultiPolygon.js', function () { it('cannot be constructed with a null geometry', function () { expect(function () { return new MultiPolygon(null); diff --git a/test/browser/spec/ol/geom/point.test.js b/test/node/ol/geom/Point.test.js similarity index 97% rename from test/browser/spec/ol/geom/point.test.js rename to test/node/ol/geom/Point.test.js index 0d5eb034d6..ee2c05e8ef 100644 --- a/test/browser/spec/ol/geom/point.test.js +++ b/test/node/ol/geom/Point.test.js @@ -1,10 +1,12 @@ -import Point from '../../../../../src/ol/geom/Point.js'; +import Point from '../../../../src/ol/geom/Point.js'; +import expect from '../../expect.js'; +import sinon from 'sinon'; import { get as getProjection, getTransformFromProjections, -} from '../../../../../src/ol/proj.js'; +} from '../../../../src/ol/proj.js'; -describe('ol.geom.Point', function () { +describe('ol/geom/Point.js', function () { it('cannot be constructed with a null geometry', function () { expect(function () { return new Point(null); diff --git a/test/browser/spec/ol/geom/polygon.test.js b/test/node/ol/geom/Polygon.test.js similarity index 98% rename from test/browser/spec/ol/geom/polygon.test.js rename to test/node/ol/geom/Polygon.test.js index 987176051e..b2a9576766 100644 --- a/test/browser/spec/ol/geom/polygon.test.js +++ b/test/node/ol/geom/Polygon.test.js @@ -1,12 +1,13 @@ -import Circle from '../../../../../src/ol/geom/Circle.js'; -import LinearRing from '../../../../../src/ol/geom/LinearRing.js'; +import Circle from '../../../../src/ol/geom/Circle.js'; +import LinearRing from '../../../../src/ol/geom/LinearRing.js'; import Polygon, { fromCircle, fromExtent, -} from '../../../../../src/ol/geom/Polygon.js'; -import {boundingExtent, isEmpty} from '../../../../../src/ol/extent.js'; +} from '../../../../src/ol/geom/Polygon.js'; +import expect from '../../expect.js'; +import {boundingExtent, isEmpty} from '../../../../src/ol/extent.js'; -describe('ol/geom/Polygon', function () { +describe('ol/geom/Polygon.js', function () { it('cannot be constructed with a null geometry', function () { expect(function () { return new Polygon(null); diff --git a/test/browser/spec/ol/geom/flat/area.test.js b/test/node/ol/geom/flat/area.test.js similarity index 69% rename from test/browser/spec/ol/geom/flat/area.test.js rename to test/node/ol/geom/flat/area.test.js index 94c737384b..4ac11bb7d1 100644 --- a/test/browser/spec/ol/geom/flat/area.test.js +++ b/test/node/ol/geom/flat/area.test.js @@ -1,10 +1,8 @@ -import { - linearRing, - linearRings, -} from '../../../../../../src/ol/geom/flat/area.js'; +import expect from '../../../expect.js'; +import {linearRing, linearRings} from '../../../../../src/ol/geom/flat/area.js'; -describe('ol.geom.flat.area', function () { - describe('ol.geom.flat.area.linearRing', function () { +describe('ol/geom/flat/area.js', function () { + describe('linearRing', function () { it('calculates the area of a triangle', function () { const area = linearRing([0, 0, 0.5, 1, 1, 0], 0, 6, 2); expect(area).to.be(0.5); @@ -16,7 +14,7 @@ describe('ol.geom.flat.area', function () { }); }); - describe('ol.geom.flat.area.linearRings', function () { + describe('linearRings', function () { it('calculates the area with holes', function () { const area = linearRings( [0, 0, 0, 3, 3, 3, 3, 0, 1, 1, 2, 1, 2, 2, 1, 2], diff --git a/test/browser/spec/ol/geom/flat/center.test.js b/test/node/ol/geom/flat/center.test.js similarity index 87% rename from test/browser/spec/ol/geom/flat/center.test.js rename to test/node/ol/geom/flat/center.test.js index c0c555ea22..b9d16937a4 100644 --- a/test/browser/spec/ol/geom/flat/center.test.js +++ b/test/node/ol/geom/flat/center.test.js @@ -1,8 +1,9 @@ -import MultiPolygon from '../../../../../../src/ol/geom/MultiPolygon.js'; -import {linearRingss as linearRingssCenter} from '../../../../../../src/ol/geom/flat/center.js'; +import MultiPolygon from '../../../../../src/ol/geom/MultiPolygon.js'; +import expect from '../../../expect.js'; +import {linearRingss as linearRingssCenter} from '../../../../../src/ol/geom/flat/center.js'; -describe('ol.geom.flat.center', function () { - describe('ol.geom.flat.center.linearRingss', function () { +describe('ol/geom/flat/center.js', function () { + describe('linearRingss', function () { it('calculates the center of a square', function () { const squareMultiPoly = new MultiPolygon([ [ diff --git a/test/browser/spec/ol/geom/flat/closest.test.js b/test/node/ol/geom/flat/closest.test.js similarity index 94% rename from test/browser/spec/ol/geom/flat/closest.test.js rename to test/node/ol/geom/flat/closest.test.js index e53a817944..7e37eb8ea2 100644 --- a/test/browser/spec/ol/geom/flat/closest.test.js +++ b/test/node/ol/geom/flat/closest.test.js @@ -1,13 +1,14 @@ +import expect from '../../../expect.js'; import { assignClosestPoint, maxSquaredDelta, -} from '../../../../../../src/ol/geom/flat/closest.js'; +} from '../../../../../src/ol/geom/flat/closest.js'; -describe('ol.geom.flat.closest', function () { +describe('ol/geom/flat/closest.js', function () { describe('with simple data', function () { const flatCoordinates = [0, 0, 1, 0, 3, 0, 5, 0, 6, 0, 8, 0, 11, 0]; - describe('ol.geom.flat.closest.maxSquaredDelta', function () { + describe('maxSquaredDelta', function () { it('returns the expected value in simple cases', function () { expect( maxSquaredDelta(flatCoordinates, 0, flatCoordinates.length, 2, 0) @@ -15,7 +16,7 @@ describe('ol.geom.flat.closest', function () { }); }); - describe('ol.geom.flat.closest.assignClosestPoint', function () { + describe('assignClosestPoint', function () { it('returns the expected value', function () { const maxDelta = Math.sqrt( maxSquaredDelta(flatCoordinates, 0, flatCoordinates.length, 2, 0) @@ -290,7 +291,7 @@ describe('ol.geom.flat.closest', function () { 480.77, ]; - describe('ol.geom.closest.maxSquaredDelta', function () { + describe('maxSquaredDelta', function () { it('returns the expected value', function () { expect( maxSquaredDelta(flatCoordinates, 0, flatCoordinates.length, 2, 0) @@ -298,7 +299,7 @@ describe('ol.geom.flat.closest', function () { }); }); - describe('ol.geom.flat.closest.assignClosestPoint', function () { + describe('assignClosestPoint', function () { it('returns the expected value', function () { const maxDelta = Math.sqrt( maxSquaredDelta(flatCoordinates, 0, flatCoordinates.length, 2, 0) @@ -358,7 +359,7 @@ describe('ol.geom.flat.closest', function () { const flatCoordinates = [0, 0, 10, -10, 2, 2, 30, -20]; const stride = 4; - describe('ol.geom.flat.closest.assignClosestPoint', function () { + describe('assignClosestPoint', function () { it('interpolates M coordinates', function () { const maxDelta = Math.sqrt( maxSquaredDelta(flatCoordinates, 0, flatCoordinates.length, stride, 0) diff --git a/test/browser/spec/ol/geom/flat/contains.test.js b/test/node/ol/geom/flat/contains.test.js similarity index 89% rename from test/browser/spec/ol/geom/flat/contains.test.js rename to test/node/ol/geom/flat/contains.test.js index c3eb6dc178..6fdb20df5c 100644 --- a/test/browser/spec/ol/geom/flat/contains.test.js +++ b/test/node/ol/geom/flat/contains.test.js @@ -1,6 +1,7 @@ -import {linearRingContainsXY} from '../../../../../../src/ol/geom/flat/contains.js'; +import expect from '../../../expect.js'; +import {linearRingContainsXY} from '../../../../../src/ol/geom/flat/contains.js'; -describe('ol.geom.flat.contains', function () { +describe('ol/geom/flat/contains.js', function () { describe('with simple data', function () { const flatCoordinatesSimple = [0, 0, 1, 0, 1, 1, 0, 1]; const flatCoordinatesNonSimple = [ @@ -26,7 +27,7 @@ describe('ol.geom.flat.contains', function () { 4, ]; - describe('ol.geom.flat.contains.linearRingContainsXY', function () { + describe('linearRingContainsXY', function () { it('returns true for point inside a simple polygon', function () { expect( linearRingContainsXY( diff --git a/test/browser/spec/ol/geom/flat/deflate.test.js b/test/node/ol/geom/flat/deflate.test.js similarity index 79% rename from test/browser/spec/ol/geom/flat/deflate.test.js rename to test/node/ol/geom/flat/deflate.test.js index 63893368e1..b4d6ea2228 100644 --- a/test/browser/spec/ol/geom/flat/deflate.test.js +++ b/test/node/ol/geom/flat/deflate.test.js @@ -1,10 +1,11 @@ +import expect from '../../../expect.js'; import { deflateCoordinates, deflateCoordinatesArray, -} from '../../../../../../src/ol/geom/flat/deflate.js'; +} from '../../../../../src/ol/geom/flat/deflate.js'; -describe('ol.geom.flat.deflate', function () { - describe('ol.geom.flat.deflate.deflateCoordinates', function () { +describe('ol/geom/flat/deflate.js', function () { + describe('deflateCoordinates', function () { let flatCoordinates; beforeEach(function () { flatCoordinates = []; @@ -25,7 +26,7 @@ describe('ol.geom.flat.deflate', function () { }); }); - describe('ol.geom.flat.deflate.deflateCoordinatesArray', function () { + describe('deflateCoordinatesArray', function () { let flatCoordinates; beforeEach(function () { flatCoordinates = []; diff --git a/test/browser/spec/ol/geom/flat/flip.test.js b/test/node/ol/geom/flat/flip.test.js similarity index 84% rename from test/browser/spec/ol/geom/flat/flip.test.js rename to test/node/ol/geom/flat/flip.test.js index 877734555c..7ad964c17f 100644 --- a/test/browser/spec/ol/geom/flat/flip.test.js +++ b/test/node/ol/geom/flat/flip.test.js @@ -1,7 +1,8 @@ -import {flipXY} from '../../../../../../src/ol/geom/flat/flip.js'; +import expect from '../../../expect.js'; +import {flipXY} from '../../../../../src/ol/geom/flat/flip.js'; -describe('ol.geom.flat.flip', function () { - describe('ol.geom.flat.flip.flipXY', function () { +describe('ol/geom/flat/flip.js', function () { + describe('flipXY', function () { it('can flip XY coordinates', function () { const flatCoordinates = flipXY([1, 2, 3, 4], 0, 4, 2); expect(flatCoordinates).to.eql([2, 1, 4, 3]); diff --git a/test/browser/spec/ol/geom/flat/inflate.test.js b/test/node/ol/geom/flat/inflate.test.js similarity index 72% rename from test/browser/spec/ol/geom/flat/inflate.test.js rename to test/node/ol/geom/flat/inflate.test.js index 051349074e..6bb9a860b6 100644 --- a/test/browser/spec/ol/geom/flat/inflate.test.js +++ b/test/node/ol/geom/flat/inflate.test.js @@ -1,10 +1,11 @@ +import expect from '../../../expect.js'; import { inflateCoordinates, inflateCoordinatesArray, -} from '../../../../../../src/ol/geom/flat/inflate.js'; +} from '../../../../../src/ol/geom/flat/inflate.js'; -describe('ol.geom.flat.inflate', function () { - describe('ol.geom.flat.inflate.inflateCoordinates', function () { +describe('ol/geom/flat/inflate.js', function () { + describe('inflateCoordinates', function () { it('inflates coordinates', function () { const coordinates = inflateCoordinates([1, 2, 3, 4], 0, 4, 2); expect(coordinates).to.eql([ @@ -14,7 +15,7 @@ describe('ol.geom.flat.inflate', function () { }); }); - describe('ol.geom.flat.inflate.inflateCoordinatesArray', function () { + describe('inflateCoordinatesArray', function () { it('inflates arrays of coordinates', function () { const coordinatess = inflateCoordinatesArray( [1, 2, 3, 4, 5, 6, 7, 8], diff --git a/test/browser/spec/ol/geom/flat/interpolate.test.js b/test/node/ol/geom/flat/interpolate.test.js similarity index 91% rename from test/browser/spec/ol/geom/flat/interpolate.test.js rename to test/node/ol/geom/flat/interpolate.test.js index 3a6ac862d2..1cee87c978 100644 --- a/test/browser/spec/ol/geom/flat/interpolate.test.js +++ b/test/node/ol/geom/flat/interpolate.test.js @@ -1,7 +1,8 @@ -import {interpolatePoint} from '../../../../../../src/ol/geom/flat/interpolate.js'; +import expect from '../../../expect.js'; +import {interpolatePoint} from '../../../../../src/ol/geom/flat/interpolate.js'; -describe('ol.geom.flat.interpolate', function () { - describe('ol.geom.flat.interpolate.interpolatePoint', function () { +describe('ol/geom/flat/interpolate.js', function () { + describe('interpolatePoint', function () { it('returns the expected value for single points', function () { const flatCoordinates = [0, 1]; const point = interpolatePoint(flatCoordinates, 0, 2, 2, 0.5); diff --git a/test/browser/spec/ol/geom/flat/intersectsextent.test.js b/test/node/ol/geom/flat/intersectsextent.test.js similarity index 92% rename from test/browser/spec/ol/geom/flat/intersectsextent.test.js rename to test/node/ol/geom/flat/intersectsextent.test.js index f9d26d0d4d..a149cbcffe 100644 --- a/test/browser/spec/ol/geom/flat/intersectsextent.test.js +++ b/test/node/ol/geom/flat/intersectsextent.test.js @@ -1,11 +1,12 @@ +import expect from '../../../expect.js'; import { intersectsLineString, intersectsLinearRing, intersectsLinearRingArray, -} from '../../../../../../src/ol/geom/flat/intersectsextent.js'; +} from '../../../../../src/ol/geom/flat/intersectsextent.js'; -describe('ol.geom.flat.intersectsextent', function () { - describe('ol.geom.flat.intersectsextent.intersectsLineString', function () { +describe('ol/geom/flat/intersectsextent.js', function () { + describe('intersectsLineString', function () { let flatCoordinates; beforeEach(function () { flatCoordinates = [0, 0, 1, 1, 2, 2]; @@ -88,7 +89,7 @@ describe('ol.geom.flat.intersectsextent', function () { }); }); - describe('ol.geom.flat.intersectsextent.intersectsLinearRing', function () { + describe('intersectsLinearRing', function () { let flatCoordinates; beforeEach(function () { flatCoordinates = [0, 0, 1, 1, 2, 0, 1, -1, 0, 0]; @@ -138,7 +139,7 @@ describe('ol.geom.flat.intersectsextent', function () { }); }); - describe('ol.geom.flat.intersectsextent.intersectsLinearRingArray', function () { + describe('intersectsLinearRingArray', function () { let flatCoordinates; let ends; beforeEach(function () { diff --git a/test/browser/spec/ol/geom/flat/length.test.js b/test/node/ol/geom/flat/length.test.js similarity index 91% rename from test/browser/spec/ol/geom/flat/length.test.js rename to test/node/ol/geom/flat/length.test.js index b2d81c7183..9a9bcb6bdb 100644 --- a/test/browser/spec/ol/geom/flat/length.test.js +++ b/test/node/ol/geom/flat/length.test.js @@ -1,10 +1,11 @@ +import expect from '../../../expect.js'; import { lineStringLength, linearRingLength, -} from '../../../../../../src/ol/geom/flat/length.js'; +} from '../../../../../src/ol/geom/flat/length.js'; -describe('ol.geom.flat.length', function () { - describe('ol.geom.flat.length.lineStringLength', function () { +describe('ol/geom/flat/length.js', function () { + describe('lineStringLength', function () { describe('stride = 2', function () { const flatCoords = [0, 0, 1, 0, 1, 1, 0, 1]; const stride = 2; @@ -64,7 +65,7 @@ describe('ol.geom.flat.length', function () { }); }); - describe('ol.geom.flat.length.linearRingLength', function () { + describe('linearRingLength', function () { it('calculates the total length of a simple linearRing', function () { const flatCoords = [0, 0, 1, 0, 1, 1, 0, 1]; const stride = 2; diff --git a/test/browser/spec/ol/geom/flat/orient.test.js b/test/node/ol/geom/flat/orient.test.js similarity index 94% rename from test/browser/spec/ol/geom/flat/orient.test.js rename to test/node/ol/geom/flat/orient.test.js index 2a639a0b58..f93949ac9e 100644 --- a/test/browser/spec/ol/geom/flat/orient.test.js +++ b/test/node/ol/geom/flat/orient.test.js @@ -1,13 +1,14 @@ +import expect from '../../../expect.js'; import { linearRingIsClockwise, linearRingsAreOriented, linearRingssAreOriented, orientLinearRings, orientLinearRingsArray, -} from '../../../../../../src/ol/geom/flat/orient.js'; +} from '../../../../../src/ol/geom/flat/orient.js'; -describe('ol.geom.flat.orient', function () { - describe('ol.geom.flat.orient.linearRingIsClockwise', function () { +describe('ol/geom/flat/orient.js', function () { + describe('linearRingIsClockwise', function () { it('identifies clockwise rings', function () { const flatCoordinates = [0, 1, 1, 4, 4, 3, 3, 0]; const isClockwise = linearRingIsClockwise( @@ -86,7 +87,7 @@ describe('ol.geom.flat.orient', function () { }); }); - describe('ol.geom.flat.orient.linearRingsAreOriented', function () { + describe('linearRingsAreOriented', function () { const oriented = linearRingsAreOriented; const rightCoords = [ @@ -148,7 +149,7 @@ describe('ol.geom.flat.orient', function () { }); }); - describe('ol.geom.flat.orient.linearRingssAreOriented', function () { + describe('linearRingssAreOriented', function () { const oriented = linearRingssAreOriented; const rightCoords = [ @@ -253,7 +254,7 @@ describe('ol.geom.flat.orient', function () { }); }); - describe('ol.geom.flat.orient.orientLinearRings', function () { + describe('orientLinearRings', function () { const orient = orientLinearRings; const rightCoords = [ @@ -325,7 +326,7 @@ describe('ol.geom.flat.orient', function () { }); }); - describe('ol.geom.flat.orient.orientLinearRingsArray', function () { + describe('orientLinearRingsArray', function () { const orient = orientLinearRingsArray; const rightCoords = [ diff --git a/test/browser/spec/ol/geom/flat/reverse.test.js b/test/node/ol/geom/flat/reverse.test.js similarity index 96% rename from test/browser/spec/ol/geom/flat/reverse.test.js rename to test/node/ol/geom/flat/reverse.test.js index 71d8aa3e43..ed35229753 100644 --- a/test/browser/spec/ol/geom/flat/reverse.test.js +++ b/test/node/ol/geom/flat/reverse.test.js @@ -1,7 +1,8 @@ -import {coordinates as reverseCoordinates} from '../../../../../../src/ol/geom/flat/reverse.js'; +import expect from '../../../expect.js'; +import {coordinates as reverseCoordinates} from '../../../../../src/ol/geom/flat/reverse.js'; -describe('ol.geom.flat.reverse', function () { - describe('ol.geom.flat.reverse.coordinates', function () { +describe('ol/geom/flat/reverse.js', function () { + describe('coordinates', function () { describe('with a stride of 2', function () { it('can reverse empty flat coordinates', function () { const flatCoordinates = []; diff --git a/test/browser/spec/ol/geom/flat/segments.test.js b/test/node/ol/geom/flat/segments.test.js similarity index 87% rename from test/browser/spec/ol/geom/flat/segments.test.js rename to test/node/ol/geom/flat/segments.test.js index 85f10330bd..0789199080 100644 --- a/test/browser/spec/ol/geom/flat/segments.test.js +++ b/test/node/ol/geom/flat/segments.test.js @@ -1,7 +1,9 @@ -import {forEach as forEachSegment} from '../../../../../../src/ol/geom/flat/segments.js'; +import expect from '../../../expect.js'; +import sinon from 'sinon'; +import {forEach as forEachSegment} from '../../../../../src/ol/geom/flat/segments.js'; -describe('ol.geom.flat.segments', function () { - describe('ol.geom.flat.segments.forEach', function () { +describe('ol/geom/flat/segments.js', function () { + describe('forEach', function () { let flatCoordinates, offset, end, stride; beforeEach(function () { flatCoordinates = [0, 0, 1, 1, 2, 2, 3, 3]; diff --git a/test/browser/spec/ol/geom/flat/simplify.test.js b/test/node/ol/geom/flat/simplify.test.js similarity index 97% rename from test/browser/spec/ol/geom/flat/simplify.test.js rename to test/node/ol/geom/flat/simplify.test.js index 74d5bbdce8..0648610c83 100644 --- a/test/browser/spec/ol/geom/flat/simplify.test.js +++ b/test/node/ol/geom/flat/simplify.test.js @@ -1,11 +1,12 @@ +import expect from '../../../expect.js'; import { douglasPeucker, quantize, radialDistance, simplifyLineString, -} from '../../../../../../src/ol/geom/flat/simplify.js'; +} from '../../../../../src/ol/geom/flat/simplify.js'; -describe('ol.geom.flat.simplify', function () { +describe('ol/geom/flat/simplify.js', function () { const flatCoordinates = [ 224.55, 250.15, @@ -532,7 +533,7 @@ describe('ol.geom.flat.simplify', function () { 480.77, ]; - describe('ol.geom.flat.simplify.simplifyLineString', function () { + describe('simplifyLineString', function () { it('works with empty line strings', function () { expect(simplifyLineString([], 0, 0, 2, 1, true)).to.eql([]); expect(simplifyLineString([], 0, 0, 2, 1, false)).to.eql([]); @@ -570,7 +571,7 @@ describe('ol.geom.flat.simplify', function () { }); }); - describe('ol.geom.flat.simplify.radialDistance', function () { + describe('radialDistance', function () { let dest; beforeEach(function () { dest = []; @@ -673,7 +674,7 @@ describe('ol.geom.flat.simplify', function () { }); }); - describe('ol.geom.flat.simplify.douglasPeucker', function () { + describe('douglasPeucker', function () { let dest; beforeEach(function () { dest = []; @@ -809,7 +810,7 @@ describe('ol.geom.flat.simplify', function () { }); }); - describe('ol.geom.flat.simplify.quantize', function () { + describe('quantize', function () { it('handles empty coordinates', function () { const simplifiedFlatCoordinates = []; expect(quantize([], 0, 0, 2, 2, simplifiedFlatCoordinates, 0)).to.be(0); diff --git a/test/browser/spec/ol/geom/flat/straightchunk.test.js b/test/node/ol/geom/flat/straightchunk.test.js similarity index 88% rename from test/browser/spec/ol/geom/flat/straightchunk.test.js rename to test/node/ol/geom/flat/straightchunk.test.js index cb2a3bef6f..e1f6efa2e1 100644 --- a/test/browser/spec/ol/geom/flat/straightchunk.test.js +++ b/test/node/ol/geom/flat/straightchunk.test.js @@ -1,7 +1,8 @@ -import {matchingChunk} from '../../../../../../src/ol/geom/flat/straightchunk.js'; +import expect from '../../../expect.js'; +import {matchingChunk} from '../../../../../src/ol/geom/flat/straightchunk.js'; -describe('ol.geom.flat.straightchunk', function () { - describe('ol.geom.flat.straightchunk.matchingChunk', function () { +describe('ol/geom/flat/straightchunk.js', function () { + describe('matchingChunk', function () { describe('single segment with stride == 3', function () { const flatCoords = [0, 0, 42, 1, 1, 42]; const stride = 3; diff --git a/test/browser/spec/ol/geom/flat/textpath.test.js b/test/node/ol/geom/flat/textpath.test.js similarity index 95% rename from test/browser/spec/ol/geom/flat/textpath.test.js rename to test/node/ol/geom/flat/textpath.test.js index a12ce86f71..af5b0da8bb 100644 --- a/test/browser/spec/ol/geom/flat/textpath.test.js +++ b/test/node/ol/geom/flat/textpath.test.js @@ -1,7 +1,8 @@ -import {drawTextOnPath} from '../../../../../../src/ol/geom/flat/textpath.js'; -import {lineStringLength} from '../../../../../../src/ol/geom/flat/length.js'; +import expect from '../../../expect.js'; +import {drawTextOnPath} from '../../../../../src/ol/geom/flat/textpath.js'; +import {lineStringLength} from '../../../../../src/ol/geom/flat/length.js'; -describe('ol.geom.flat.drawTextOnPath', function () { +describe('ol/geom/flat/drawTextOnPath.js', function () { const horizontal = [0, 0, 100, 0]; const vertical = [0, 0, 0, 100]; const diagonal = [0, 0, 100, 100]; diff --git a/test/browser/spec/ol/geom/flat/topologyflatgeom.test.js b/test/node/ol/geom/flat/topologyflatgeom.test.js similarity index 83% rename from test/browser/spec/ol/geom/flat/topologyflatgeom.test.js rename to test/node/ol/geom/flat/topologyflatgeom.test.js index 42c1750d5c..104f0470d0 100644 --- a/test/browser/spec/ol/geom/flat/topologyflatgeom.test.js +++ b/test/node/ol/geom/flat/topologyflatgeom.test.js @@ -1,7 +1,8 @@ -import {lineStringIsClosed} from '../../../../../../src/ol/geom/flat/topology.js'; +import expect from '../../../expect.js'; +import {lineStringIsClosed} from '../../../../../src/ol/geom/flat/topology.js'; -describe('ol.geom.flat.topology', function () { - describe('ol.geom.flat.topology.lineStringIsClosed', function () { +describe('ol/geom/flat/topology.js', function () { + describe('lineStringIsClosed', function () { it('identifies closed lines aka boundaries', function () { const flatCoordinates = [0, 0, 3, 0, 0, 3, 0, 0]; const isClosed = lineStringIsClosed( diff --git a/test/browser/spec/ol/geom/flat/transform.test.js b/test/node/ol/geom/flat/transform.test.js similarity index 93% rename from test/browser/spec/ol/geom/flat/transform.test.js rename to test/node/ol/geom/flat/transform.test.js index 5832c970ef..15a2471956 100644 --- a/test/browser/spec/ol/geom/flat/transform.test.js +++ b/test/node/ol/geom/flat/transform.test.js @@ -1,12 +1,10 @@ -import MultiPolygon from '../../../../../../src/ol/geom/MultiPolygon.js'; -import { - rotate, - translate, -} from '../../../../../../src/ol/geom/flat/transform.js'; -import {transformGeom2D} from '../../../../../../src/ol/geom/SimpleGeometry.js'; +import MultiPolygon from '../../../../../src/ol/geom/MultiPolygon.js'; +import expect from '../../../expect.js'; +import {rotate, translate} from '../../../../../src/ol/geom/flat/transform.js'; +import {transformGeom2D} from '../../../../../src/ol/geom/SimpleGeometry.js'; -describe('ol.geom.flat.transform', function () { - describe('ol.geom.flat.transform.transform2D', function () { +describe('ol/geom/flat/transform.js', function () { + describe('transform2D', function () { it('transforms a Simple Geometry to 2D', function () { const multiPolygonGeometry = new MultiPolygon([ [ @@ -79,7 +77,7 @@ describe('ol.geom.flat.transform', function () { }); }); - describe('ol.geom.flat.transform.translate', function () { + describe('translate', function () { it('translates the coordinates array', function () { const multiPolygon = new MultiPolygon([ [ @@ -148,7 +146,7 @@ describe('ol.geom.flat.transform', function () { }); }); - describe('ol.geom.flat.transform.rotate', function () { + describe('rotate', function () { it('rotates the coordinates array', function () { const multiPolygon = new MultiPolygon([ [ diff --git a/test/node/ol/math.test.js b/test/node/ol/math.test.js new file mode 100644 index 0000000000..0bf3838f9b --- /dev/null +++ b/test/node/ol/math.test.js @@ -0,0 +1,165 @@ +import expect from '../expect.js'; +import { + clamp, + cosh, + lerp, + log2, + modulo, + solveLinearSystem, + toDegrees, + toRadians, +} from '../../../src/ol/math.js'; + +describe('ol/math.js', () => { + describe('clamp', function () { + it('returns the correct value at -Infinity', function () { + expect(clamp(-Infinity, 10, 20)).to.eql(10); + }); + + it('returns the correct value at min', function () { + expect(clamp(10, 10, 20)).to.eql(10); + }); + + it('returns the correct value at mid point', function () { + expect(clamp(15, 10, 20)).to.eql(15); + }); + + it('returns the correct value at max', function () { + expect(clamp(20, 10, 20)).to.eql(20); + }); + + it('returns the correct value at Infinity', function () { + expect(clamp(Infinity, 10, 20)).to.eql(20); + }); + }); + + describe('cosh', function () { + it('returns the correct value at -Infinity', function () { + expect(cosh(-Infinity)).to.eql(Infinity); + }); + + it('returns the correct value at -1', function () { + expect(cosh(-1)).to.roughlyEqual(1.5430806348152437, 1e-9); + }); + + it('returns the correct value at 0', function () { + expect(cosh(0)).to.eql(1); + }); + + it('returns the correct value at 1', function () { + expect(cosh(1)).to.roughlyEqual(1.5430806348152437, 1e-9); + }); + + it('returns the correct value at Infinity', function () { + expect(cosh(Infinity)).to.eql(Infinity); + }); + }); + + describe('log2', function () { + it('returns the correct value at Infinity', function () { + expect(log2(Infinity)).to.eql(Infinity); + }); + + it('returns the correct value at 3', function () { + expect(log2(3)).to.roughlyEqual(1.584962500721156, 1e-9); + }); + + it('returns the correct value at 2', function () { + expect(log2(2)).to.eql(1); + }); + + it('returns the correct value at 1', function () { + expect(log2(1)).to.eql(0); + }); + + it('returns the correct value at 0', function () { + expect(log2(0)).to.eql(-Infinity); + }); + + it('returns the correct value at -1', function () { + expect(log2(-1).toString()).to.eql('NaN'); + }); + }); + + describe('solveLinearSystem', function () { + it('calculates correctly', function () { + const result = solveLinearSystem([ + [2, 1, 3, 1], + [2, 6, 8, 3], + [6, 8, 18, 5], + ]); + expect(result[0]).to.roughlyEqual(0.3, 1e-9); + expect(result[1]).to.roughlyEqual(0.4, 1e-9); + expect(result[2]).to.roughlyEqual(0, 1e-9); + }); + + it('can handle singular matrix', function () { + const result = solveLinearSystem([ + [2, 1, 3, 1], + [2, 6, 8, 3], + [2, 1, 3, 1], + ]); + expect(result).to.be(null); + }); + }); + + describe('toDegrees', function () { + it('returns the correct value at -π', function () { + expect(toDegrees(-Math.PI)).to.be(-180); + }); + it('returns the correct value at 0', function () { + expect(toDegrees(0)).to.be(0); + }); + it('returns the correct value at π', function () { + expect(toDegrees(Math.PI)).to.be(180); + }); + }); + + describe('toRadians', function () { + it('returns the correct value at -180', function () { + expect(toRadians(-180)).to.be(-Math.PI); + }); + it('returns the correct value at 0', function () { + expect(toRadians(0)).to.be(0); + }); + it('returns the correct value at 180', function () { + expect(toRadians(180)).to.be(Math.PI); + }); + }); + + describe('modulo', function () { + it('256 / 8 returns 0', function () { + expect(modulo(256, 8)).to.be(0); + }); + it('positive and positive returns a positive ', function () { + expect(modulo(7, 8)).to.be(7); + }); + it('same Dividend and Divisor returns 0', function () { + expect(modulo(4, 4)).to.be(0); + }); + it('negative and positive returns positive', function () { + expect(modulo(-3, 4)).to.be(1); + }); + it('negative and negative returns negative', function () { + expect(modulo(-4, -5)).to.be(-4); + expect(modulo(-3, -4)).to.be(-3); + }); + it('positive and negative returns negative', function () { + expect(modulo(3, -4)).to.be(-1); + expect(modulo(1, -5)).to.be(-4); + expect(modulo(6, -5)).to.be(-4); + }); + }); + + describe('lerp', function () { + it('correctly interpolated numbers', function () { + expect(lerp(0, 0, 0)).to.be(0); + expect(lerp(0, 1, 0)).to.be(0); + expect(lerp(1, 11, 5)).to.be(51); + }); + it('correctly interpolates floats', function () { + expect(lerp(0, 1, 0.5)).to.be(0.5); + expect(lerp(0.25, 0.75, 0.5)).to.be(0.5); + }); + }); +}); diff --git a/test/node/ol/obj.test.js b/test/node/ol/obj.test.js new file mode 100644 index 0000000000..4cc1975011 --- /dev/null +++ b/test/node/ol/obj.test.js @@ -0,0 +1,67 @@ +import expect from '../expect.js'; +import {assign, clear, getValues, isEmpty} from '../../../src/ol/obj.js'; + +describe('ol/obj.js', () => { + describe('assign()', function () { + it('is an alias for Object.assign() where available', function () { + if (typeof Object.assign === 'function') { + expect(assign).to.be(Object.assign); + } + }); + + it('assigns properties from a source object to a target object', function () { + const source = { + sourceProp1: 'sourceValue1', + sourceProp2: 'sourceValue2', + }; + + const target = { + sourceProp1: 'overridden', + targetProp1: 'targetValue1', + }; + + const assigned = assign(target, source); + expect(assigned).to.be(target); + expect(assigned.sourceProp1).to.be('sourceValue1'); + expect(assigned.sourceProp2).to.be('sourceValue2'); + expect(assigned.targetProp1).to.be('targetValue1'); + }); + + it('throws a TypeError with `undefined` as target', function () { + expect(() => assign()).to.throwException( + /Cannot convert undefined or null to object/ + ); + }); + + it('throws a TypeError with `null` as target', function () { + expect(() => assign(null)).to.throwException( + /Cannot convert undefined or null to object/ + ); + }); + }); + + describe('clear()', function () { + it('removes all properties from an object', function () { + expect(isEmpty(clear({foo: 'bar'}))).to.be(true); + expect(isEmpty(clear({foo: 'bar', num: 42}))).to.be(true); + expect(isEmpty(clear({}))).to.be(true); + expect(isEmpty(clear(null))).to.be(true); + }); + }); + + describe('getValues()', function () { + it('gets a list of property values from an object', function () { + expect(getValues({foo: 'bar', num: 42}).sort()).to.eql([42, 'bar']); + expect(getValues([])).to.eql([]); + }); + }); + + describe('isEmpty()', function () { + it('checks if an object has any properties', function () { + expect(isEmpty({})).to.be(true); + expect(isEmpty(null)).to.be(true); + expect(isEmpty({foo: 'bar'})).to.be(false); + expect(isEmpty({foo: false})).to.be(false); + }); + }); +}); diff --git a/test/browser/spec/ol/proj.test.js b/test/node/ol/proj.test.js similarity index 98% rename from test/browser/spec/ol/proj.test.js rename to test/node/ol/proj.test.js index b279845c1c..68def7cdf3 100644 --- a/test/browser/spec/ol/proj.test.js +++ b/test/node/ol/proj.test.js @@ -1,6 +1,8 @@ -import Projection from '../../../../src/ol/proj/Projection.js'; -import Units from '../../../../src/ol/proj/Units.js'; -import {HALF_SIZE} from '../../../../src/ol/proj/epsg3857.js'; +import Projection from '../../../src/ol/proj/Projection.js'; +import Units from '../../../src/ol/proj/Units.js'; +import expect from '../expect.js'; +import proj4 from 'proj4'; +import {HALF_SIZE} from '../../../src/ol/proj/epsg3857.js'; import { METERS_PER_UNIT, addCommon, @@ -22,11 +24,11 @@ import { transform, transformExtent, useGeographic, -} from '../../../../src/ol/proj.js'; -import {METERS_PER_UNIT as metersPerDegree} from '../../../../src/ol/proj/epsg4326.js'; -import {register} from '../../../../src/ol/proj/proj4.js'; +} from '../../../src/ol/proj.js'; +import {METERS_PER_UNIT as metersPerDegree} from '../../../src/ol/proj/epsg4326.js'; +import {register} from '../../../src/ol/proj/proj4.js'; -describe('ol.proj', function () { +describe('ol/proj.js', function () { afterEach(function () { clearAllProjections(); clearUserProjection(); diff --git a/test/browser/spec/ol/structs/linkedlist.test.js b/test/node/ol/structs/linkedlist.test.js similarity index 97% rename from test/browser/spec/ol/structs/linkedlist.test.js rename to test/node/ol/structs/linkedlist.test.js index aece930ac5..957475f98f 100644 --- a/test/browser/spec/ol/structs/linkedlist.test.js +++ b/test/node/ol/structs/linkedlist.test.js @@ -1,6 +1,7 @@ -import LinkedList from '../../../../../src/ol/structs/LinkedList.js'; +import LinkedList from '../../../../src/ol/structs/LinkedList.js'; +import expect from '../../expect.js'; -describe('ol.structs.LinkedList', function () { +describe('ol/structs/LinkedList.js', function () { let ll; const item = {}; const item2 = {}; diff --git a/test/browser/spec/ol/structs/lrucache.test.js b/test/node/ol/structs/lrucache.test.js similarity index 98% rename from test/browser/spec/ol/structs/lrucache.test.js rename to test/node/ol/structs/lrucache.test.js index 1ee5373780..3b1a9daa5c 100644 --- a/test/browser/spec/ol/structs/lrucache.test.js +++ b/test/node/ol/structs/lrucache.test.js @@ -1,6 +1,7 @@ -import LRUCache from '../../../../../src/ol/structs/LRUCache.js'; +import LRUCache from '../../../../src/ol/structs/LRUCache.js'; +import expect from '../../expect.js'; -describe('ol.structs.LRUCache', function () { +describe('ol/structs/LRUCache.js', function () { let lruCache; function fillLRUCache(lruCache) { diff --git a/test/browser/spec/ol/structs/priorityqueue.test.js b/test/node/ol/structs/priorityqueue.test.js similarity index 96% rename from test/browser/spec/ol/structs/priorityqueue.test.js rename to test/node/ol/structs/priorityqueue.test.js index 295561ee06..e452ead249 100644 --- a/test/browser/spec/ol/structs/priorityqueue.test.js +++ b/test/node/ol/structs/priorityqueue.test.js @@ -1,8 +1,7 @@ -import PriorityQueue, { - DROP, -} from '../../../../../src/ol/structs/PriorityQueue.js'; +import PriorityQueue, {DROP} from '../../../../src/ol/structs/PriorityQueue.js'; +import expect from '../../expect.js'; -describe('ol.structs.PriorityQueue', function () { +describe('ol/structs/PriorityQueue.js', function () { const identity = function (a) { return a; }; diff --git a/test/browser/spec/ol/structs/rbush.test.js b/test/node/ol/structs/rbush.test.js similarity index 98% rename from test/browser/spec/ol/structs/rbush.test.js rename to test/node/ol/structs/rbush.test.js index 48444ceff7..f35f6f1e65 100644 --- a/test/browser/spec/ol/structs/rbush.test.js +++ b/test/node/ol/structs/rbush.test.js @@ -1,6 +1,7 @@ -import RBush from '../../../../../src/ol/structs/RBush.js'; +import RBush from '../../../../src/ol/structs/RBush.js'; +import expect from '../../expect.js'; -describe('ol.structs.RBush', function () { +describe('ol/structs/RBush.js', function () { let rBush; beforeEach(function () { rBush = new RBush(); diff --git a/test/browser/spec/ol/tilegrid/tilegrid.test.js b/test/node/ol/tilegrid/TileGrid.test.js similarity index 98% rename from test/browser/spec/ol/tilegrid/tilegrid.test.js rename to test/node/ol/tilegrid/TileGrid.test.js index 236f34e1d4..4353b1ed1f 100644 --- a/test/browser/spec/ol/tilegrid/tilegrid.test.js +++ b/test/node/ol/tilegrid/TileGrid.test.js @@ -1,24 +1,25 @@ -import Projection from '../../../../../src/ol/proj/Projection.js'; -import TileGrid from '../../../../../src/ol/tilegrid/TileGrid.js'; -import TileRange from '../../../../../src/ol/TileRange.js'; +import Projection from '../../../../src/ol/proj/Projection.js'; +import TileGrid from '../../../../src/ol/tilegrid/TileGrid.js'; +import TileRange from '../../../../src/ol/TileRange.js'; +import expect from '../../expect.js'; import { DEFAULT_MAX_ZOOM, DEFAULT_TILE_SIZE, -} from '../../../../../src/ol/tilegrid/common.js'; -import {HALF_SIZE} from '../../../../../src/ol/proj/epsg3857.js'; +} from '../../../../src/ol/tilegrid/common.js'; +import {HALF_SIZE} from '../../../../src/ol/proj/epsg3857.js'; import { METERS_PER_UNIT, get as getProjection, -} from '../../../../../src/ol/proj.js'; +} from '../../../../src/ol/proj.js'; import { createForExtent, createForProjection, createXYZ, getForProjection as getTileGridForProjection, -} from '../../../../../src/ol/tilegrid.js'; -import {createOrUpdate} from '../../../../../src/ol/extent.js'; +} from '../../../../src/ol/tilegrid.js'; +import {createOrUpdate} from '../../../../src/ol/extent.js'; -describe('ol.tilegrid.TileGrid', function () { +describe('ol/tilegrid/TileGrid.js', function () { let resolutions; let origin; let tileSize; diff --git a/test/node/ol/util.test.js b/test/node/ol/util.test.js new file mode 100644 index 0000000000..7d24c43a74 --- /dev/null +++ b/test/node/ol/util.test.js @@ -0,0 +1,25 @@ +import expect from '../expect.js'; +import {getUid} from '../../../src/ol/util.js'; + +describe('ol/util.js', () => { + describe('getUid()', function () { + it('is constant once generated', function () { + const a = {}; + expect(getUid(a)).to.be(getUid(a)); + }); + + it('generates a strictly increasing sequence', function () { + const a = {}; + const b = {}; + const c = {}; + getUid(a); + getUid(c); + getUid(b); + + // uid order should be a < c < b + expect(getUid(a)).to.be.lessThan(getUid(c)); + expect(getUid(c)).to.be.lessThan(getUid(b)); + expect(getUid(a)).to.be.lessThan(getUid(b)); + }); + }); +}); diff --git a/test/browser/spec/ol/vec/mat4.test.js b/test/node/ol/vec/mat4.test.js similarity index 73% rename from test/browser/spec/ol/vec/mat4.test.js rename to test/node/ol/vec/mat4.test.js index 61fd700218..66a8264804 100644 --- a/test/browser/spec/ol/vec/mat4.test.js +++ b/test/node/ol/vec/mat4.test.js @@ -1,13 +1,14 @@ -import {create, fromTransform} from '../../../../../src/ol/vec/mat4.js'; +import expect from '../../expect.js'; +import {create, fromTransform} from '../../../../src/ol/vec/mat4.js'; -describe('mat4', function () { - describe('mat4.create()', function () { +describe('ol/vec/mat4.js', function () { + describe('create()', function () { it('returns the expected matrix', function () { expect(create()).to.eql([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]); }); }); - describe('mat4.fromTransform()', function () { + describe('fromTransform()', function () { it('sets the expected transform on the matrix', function () { const transform = [1, 2, 3, 4, 5, 6]; const result = create(); diff --git a/test/node/readme.md b/test/node/readme.md new file mode 100644 index 0000000000..2702096c91 --- /dev/null +++ b/test/node/readme.md @@ -0,0 +1,11 @@ +# Node.js Based Tests + +The tests in this directory are run in Node.js. To run the tests: + + npm run test-node + +To attach a debugger to the tests, add a `debugger` statement in the module that you want to debug and run the tests with the `--inspect-brk` flag: + + npm run test-node -- --inspect-brk + +Then open chrome://inspect/ and attach to the remote target (or see https://nodejs.org/en/docs/guides/debugging-getting-started/ for other options).