Package detail

@mapbox/mvt-fixtures

mapbox16.3kISC3.10.0

A require-able test fixture suite of valid and invalid Mapbox Vector Tiles

readme

mvt-fixtures crew

Build Status

A require()able suite of valid and invalid vector tile fixtures for testing Mapbox Vector Tile encoders and decoders. You can view a list of all fixtures at FIXTURES.md.

Usage

mvt-fixtures can be used in two distinct ways

  1. javascript interface: use the javascript interface to generate fixtures on the fly
  2. raw fixtures use the raw fixtures directly via the /fixtures directory.

The Javascript API is recommended if you are working in Javascript or Node.js. The raw fixtures are provided for those using this outside of a Javascript application. The recommended workflow is to have your encoder or decoder loop through every fixture and either expect to successfully decode/encode valid fixtures, or fail to decode/encode invalid fixtures. When new fixtures are added to this repository, you simply need to update the version of the module (or your submodule) to get the new fixtures and re-run tests.

Validity: each fixture includes information about whether they are valid according to the specification versions and possible error outcomes if they are invalid. If any of the fixtures are invalid, they must include an error field describing how to recover (or not) from the error. These can be found in the validity field of the fixture and info.json files. The following checks:

  • v1 (Boolean): is this fixture valid according to Version 1.x of the Mapbox Vector Tile spec
  • v2 (Boolean): is this fixture valid according to Version 2.x of the Mapbox Vector Tile spec
  • error (String): describes if the encoder/decoder should recover from this error or stop completely. THis is only present if the fixture is invalid according to one or more spec revisions. Values are
    • recoverable: should the encoder/decoder continue move on and continue its work? For instance, if invalid geometry is found, can the encoder safely move to the next feature?
    • fatal: the encoder should completely stop its process

Javascript usage

Check out the full Javascript interface over at API.md

npm install @mapbox/mvt-fixtures --save-dev
const mvtf = require('@mapbox/mvt-fixtures');
const decoder = require('your-mvt-decoder');

// assert on every single buffer
mvtf.each(function(fixture) {
  let output = decoder(fixture.buffer);
  assert.equal(output.layers.length, fixture.json.layers.length, 'expected number of layers');
  // ... more tests
});

// or you can get individual fixtures
const output = decoder(mvtf.get('043').buffer);

// or you can build a fixture inline
const { buffer } = mvtf.create({
  layers: [
    {
      version: 2,
      name: 'parks',
      features: [
        {
          id: 10,
          tags: [ 0, 0 ], // name: Stanley Park
          type: 1, // point
          geometry: [ 9, 54, 38 ]
        },
        {
          id: 10,
          tags: [ 0, 0 ], // name: Olympic
          type: 1, // point
          geometry: [ 9, 2, 5 ]
        }
      ],
      keys: [ 'name' ],
      values: [
        { string_value: 'Stanley Park' },
        { string_value: 'Olympic' }
      ],
      extent: 4096
    }
  ]
}); // ==> Buffer()

Non-JS interface

You can access all of the fixtures and their metadata in the /fixtures directory. You can download this repository and get them manually, or use this repository as a submodule. Each fixture is named by the directory /fixtures/{name} and has the following files:

  1. tile.mvt - the protocol buffer that represents (or intentionally breaks) the Mapbox Vector Tile specification
  2. tile.json - a JSON representation of the tile and its properties
  3. info.json - information about the fixture including name, description, and specification_reference.

Defaults and validity

Validity can be messy. In the case of the validity property for the fixtures, they refer to the Mapbox Vector Tile Specification but depending on the protocol buffer specification we are decoding with, fields that may be required by the spec and are missing can be interpreted as default values. For example: in fixture 003 where the "GeomType" tag is completely missing, any vector tile decoder using the proto2 syntax will interpret this by the default value UNKNOWN instead of a missing tag, so the fixture itself is interpreted as "valid".

Real-world fixtures

While the bulk of mvt-fixtures is focused on minimal unit tests with very specific features, it also includes a set of real-world tiles that are useful for benchmarking and running your decoder through more realistic tiles. Learn more about each real world extent in REAL-WORLD.md.

Develop

Setup

git clone git@github.com:mapbox/mvt-fixtures.git
cd mvt-fixtures
git submodule update --init
npm install
npm install -g documentation

Adding a new fixture

All fixtures have a source file in the /src directory. This file is a module that exports an object with the following parameters:

module.exports = {
  description: 'DESCRIPTION',
  specification_reference: 'SPECIFICATION_URL',
  validity: {
    v1: false,
    v2: false,
    error: 'ERROR_TYPE'
  },
  json: {...},
  proto: '2.1'
};

A new fixture can be created by running the command, which will auto-increment the ID:

npm run new
# New file created: /src/003.js.

Building fixtures

To rebuild all of the raw fixtures (including the tile.mvt, tile.json, and info.json files) in /fixtures you can run:

npm run build

Debugging fixtures

There are couple scripts included for debugging the fixtures as you create them.

protoc specification dump allows you to dump mvt fixtures to the text-based representation supported by the google protoc tool. This can be very useful for debugging fixtures to ensure you've created what you expected (particularly for tiles designed to be invalid to parse).

$ ./scripts/dump fixtures/002/tile.mvt
layers {
  name: "hello"
  features {
    type: POINT
    geometry: 9
    geometry: 50
    geometry: 34
  }
  extent: 4096
  version: 2
}

raw protoc dump allows you to dump the raw contents of a buffer. This particularly useful for tiles that don't match the vector_tile.proto format and you want to view which tags are generated

$ ./scripts/dump fixtures/002/tile.mvt --raw
3 {
  15: 2
  1: "hello"
  2 {
    2: ""
    3: 1
    4: "\t2\""
  }
  5: 4096
}

vtvalidate is a node C++ addon that can be installed via npm separately. This uses vtzero to parse a vector tile buffer and has a CLI available for quick use.

$ vtvalidate fixtures/003/tile.mvt
unknown geometry type

Building docs

Documentation takes two forms...

  1. Javascript API docs in API.md
  2. Fixture reference in FIXTURES.md

These can be generated by running:

npm run docs

Running tests

All tests can be run with:

npm test

changelog

3.10.0

  • Add new worldview/class fixtures:
    • add new fixtures 073 Class: _mbx_worldview "all", _mbx_class "sea"
    • add new fixtures 074 Class: _mbx_worldview "US,CN", _mbx_class "sea"
    • add new fixtures 075 Class: _mbx_worldview "US", _mbx_class "sea"
    • add new fixtures 076 Class: _mbx_worldview "US", _mbx_class not a string

3.9.0

  • Add create method to module, allowing inline fixtures to be created for faster iteration in downstream libraries.

3.8.0

  • Add new worldview fixtures:
    • add new fixtures 064 Point features with added language & worldview properties prefixed with "_mbx_xxx".
    • add new fixtures 065 Worldviews: all legacy values
    • add new fixtures 066 Worldviews: all legacy and new values
    • add new fixtures 067 Worldviews: "all" values
    • add new fixtures 068 Worldviews: mixture of features
    • add new fixtures 069 Worldviews: _mbx_worldview is not a string
    • add new fixtures 070 Worldviews: _mbx_worldview and worldview properties in same feature with conflicting values
    • add new fixtures 071 Worldviews: all worldviews as separate features
    • add new fixtures 072 Worldviews: comma-separated list of non ISO 3166-1 alpha-2 codes

3.7.0

  • Add new fixture 063 which has a set of features with different language values, which is helpful for testing internationalization functionality downstream #103
  • Test on Node.js v16 + v14, remove testing for Node.js v8

3.6.0

  • Add new fixture 062 which has a set of features with different property values, which is helpful for testing filtering functionality downstream #102
  • Test on Node.js v10 + v8, remove testing for Node.js v4 + v6
  • Use Buffer.from() instead of Buffer()

3.5.1

  • Remove mason_packages from NPM publish - remove .npmignore all together and use .gitignore

3.5.0

  • Update fixture 011 to use a larger, less-likely-to-come-into-future-conflict number for the custom value type #99
  • Add a new fixture 061 with with a linestring geometry that contains a ClosePath command #94

3.4.0

  • Add two new fixtures used for layer compositing tests #97

3.3.1

  • Fix 056 coordinates #89
  • Fix 058 MoveTo command #90

3.3.0

  • add broken geometry fixtures #86
  • clipped square fixtures #87
  • large MoveTo and LineTo command fixtures #88

3.2.0

  • Update fixture 002 to include a set of tags. This makes it more "testable" since the ID does not exist. #85
  • Mark fixture 009 as valid #64

3.1.1

3.1.0

  • Add OSM QA tiles for more diverse real-world examples #76
  • Update fixture 015 (duplicate layers) to include unique tags, which simplifies asserting on expected features #78

3.0.1

  • Fix San Francisco real-world fixtures to z15 so we include buildings. Also reduces the number of fixtures dramatically to save on size. #72

3.0.0

Complete restructure of mvt-fixtures using pbf and protocol-buffers-schema, focused on maintainability and tools for quickly generating new fixtures. :tada: Major improvements:

  • All fixtures have their own source file (by ID) that contains information including a description, validity specs, and a JSON representation of the fixture used to generate a protocol buffer. All fixtures are described in FIXTURES.md
  • Include a javascript API with get and each methods, described in API.md
  • Add real-world fixtures from mapbox-streets and mapbox-terrain tilesets. All real world fixtures are described in REAL-WORLD.md
  • Add protoc scripts to dump raw text form of buffers to stdout for debugging
  • Automated API and fixture documentation

3.0.0-beta7

  • Fix some invalid fixtures #69

3.0.0-beta6

  • gunzip and null encode all of the real-world fixtures, plus include some fixtures that are gzipped. #67

3.0.0-beta5

  • Add real-world fixtures from mapbox-streets and mapbox-terrain tilesets #49
  • Another path fix #65

3.0.0-beta4

  • Revert 3.0.0-beta3 removal of submodule, fix paths instead

3.0.0-beta3

  • Vendorize vector-tile-spec repository so it packages with npm publishes #61

3.0.0-beta2

  • Recreate all fixtures that previously existed in 2.x
  • Add protoc scripts to dump raw text form of buffers to stdout for debugging
  • Update generateBuffer to run specific versions of the Mapbox Vector Tile Specification, or custom proto files
  • Generate with proto2 syntax by default instead of proto3 syntax to avoid situations where default values confusion

3.0.0-beta1

  • Create source files for all fixtures in the src/ directory - these are node modules which include information about the fixture, including a description, validity specs, and a JSON representation of the fixture.
  • Rely on pbf and protocol-buffers-schema modules to generate fixtures based on the Mapbox Vector Tile Specification, which is now a submodule to this repository.
  • All fixtures are generated into the fixtures/ directory programmatically using npm run build
  • Include a javascript API with get, create, and each methods, described in API.md
  • Automatically generate fixture documentation from the source files, located in FIXTURES.md

2.1.0

  • Rename project to mvt-fixtures
  • Break fixtures into valid and invalid directories
  • Match version with that of the Mapbox Vector Tile Specification (no longer true as of version 3.x)

1.0.0

  • First official set of .mvt fixtures for usage within tests. All scripts used for create are currently within _reserve so we can ponder how to use these in the future.

0.0.1

  • first