npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jest-geojson

v1.6.0

Published

Additional Jest matchers for GeoJSON

Downloads

48

Readme


NPM Version Completed and deployed matchers Proposed new matchers

Powered by Jest License

This project has reached initial release!


Tests Build codecov Dependency status Vulnerabilities Open Issues

Maintained contributions welcome


Purpose

Jest-GeoJSON extends the Jest unit testing framework with a comprehensive set of matchers tailored to checking GeoJSON object validity and other geodesy attributes. For example:

const testPoint = {
    type: 'Point',
    coordinates: [25, 10.2]
}

test('Object is valid GeoJSON Point Geometry', () => {
    expect(testPoint).toBePointGeometry()
})

This library DOES NOT create or manipulate GeoJSON. Other tools have done that (and better), such as the venerable Turf.js.

This project complements, not competes with, those tools.

Getting Started

Install as a Dependency

After installing Jest, run:

npm install --save-dev jest-geojson

Configure Jest

Jest will run custom scripts after its environment loads. You can take advantage of that to load all Jest-GeoJSON matchers automatically.

To do so, either create a jest.config.js file:

module.exports = {
    setupFilesAfterEnv: ['jest-geojson/setup/all']
}

or add a key to your package.json:

{
    "name": "myPackageName",
    ...
    "jest": {
        "setupFilesAfterEnv": ["jest-geojson/setup/all"]
    }
}

Configure Typescript

If your editor does not recognize the custom Jest-GeoJSON matchers, add a global.d.ts file to your project with:

import 'jest-geojson'

Then add a files key in your tsconfig.json:

{
  "compilerOptions": {
    ...
  },
  ...
  "files": ["global.d.ts"]
}

Matchers

Jest-GeoJSON organizes matchers by categories. Most correspond to the expected input type passed to expect(). For example, the Coordinates matchers expect a coordinate array, and geometry matchers expect a GeoJSON geometry object.

Functional matchers assess more generic attributes and qualities and many accept multiple input types.

Coordiantes

Bounding Boxes

Geometries

Features


Future

  • [ ] toHaveProperties (array of [property, optional values])

Feature Collections


Future

  • [ ] toContainFeatureTypes (array of feature type strings, optional min count, optional max count)
  • [ ] toContainIDs ([optional unordered array of IDs])
  • [ ] toContainStringIDs
  • [ ] toContainNumericIDs
  • [ ] toContainUniqueIDs
  • [ ] toContainAnyIDs
  • [ ] toContainOnlyIDs ([unordered array of IDs])

Functional


Future

  • [ ] toHave2DBoundingBox
  • [ ] toHave3DBoundingBox
  • [ ] toHaveBoundingBox
  • [ ] toCrossAntimeridian
  • [ ] toIncludePole (Optional 'North' or 'South')
  • [ ] isInHemisphere('North', 'South', 'East', 'West')
  • [ ] toHaveMinPointCount
  • [ ] toHaveMaxPointCount
  • [ ] toHavePointCount (equal/min, optional max)
  • [ ] toHaveMaxPrecision (num decimal places)
  • [ ] toHaveMinPrecision (num decimal places)
  • [ ] toHavePrecision (equal to/min decimal places, optional max decimal places)
  • [ ] toIncludeGeometryTypes (optional array of [Geometry type strings, optional min count, optional max count])
  • [ ] toIncludeForeignMembers (optional array of [members, optional values])
  • [ ] toIncludeAnyCoordinates ([unordered array of points])
  • [ ] toIncludeAllCoordinates ([unordered array of points])
  • [ ] toIncludeOnlyCoordinates
  • [ ] toIncludeOrderedCoordinates (array of [ordered points])
  • [ ] toContain (array of geometry: [single or multi point/line/polygon whose boundaries are all within argument polygon/multipolygon])
  • [ ] isCounterClockwiseWound
  • [ ] isClockwiseWound
  • [ ] isKinked
  • [ ] toBeContainedWithinBBox
  • [ ] toBeContainedWithinPolygon

Advanced Configuration

Load Matchers by Category

You can load matcher subsets if you only need a limited set. Available scipts are:

  • jest-geojson/setup/all
  • jest-geojson/setup/boundingBoxes
  • jest-geojson/setup/coordinates
  • jest-geojson/setup/featureCollections
  • jest-geojson/setup/features
  • jest-geojson/setup/geometries

For example:

module.exports = {
    setupFilesAfterEnv: ['jest-geojson/setup/coordinates']
}

To load more than one matcher set, pass a comma separated list to the setupFilesAfterEnv array:

module.exports = {
    setupFilesAfterEnv: [
        'jest-geojson/setup/featureCollections',
        'jest-geojson/setup/geometries',
        'jest-geojson/setup/features'
    ]
}

Load Specific Matchers

To load only specific matchers, create a new script and import them either one by one or by group. The matcher object contains each matcher grouped by category.

// ./my-custom-load-script.js

const matchers = require('jest-geojson')

expect.extend({ matchers.coordinates.isValidCoordinate }) // Loads single matcher
expect.extend({ matchers.boundingBoxes.isValidBoundingBox }) // Loads single matcher
expect.extend(matchers.geometries) // Loads all matchers in the geometries category

For another example, see the setup script.

Import the Core Engine

The core object contains the functions grouped by category. You can then use these functions elsewhere in your code, or even port Jest-GeoJSON into another testing framework. To import the functions that drive the test matchers:

const core = require('jest-geojson/core')

Support Policy

Minimum Supported Jest Version

This project requires Jest v24.0.0 or newer.

Node and Operating System

The test suite has successfully run on all combinations of:

  • Node Versions Supported
  • Windows Supported Mac Supported Linux Supported

This project supports Long-Term Support, Current, and Maintenance versions of node. Once a version reaches end of life, the CI scripts will no longer support them. Odd Node versions will only receive support while in a current status.

Other Node versions and operating systems might support the library, but the tests have not verified other combinations.

License and Development

Jest-GeoJSON and all other files in this repository are distributed as free and open-source software under the MIT License, © 2022.

Both contributions and bug reports welcome.

Leave a :star2: if you find this project useful!

Contact

Maintained by M. Scott Lassiter.

GitHub Badge Profile Twitter Badge Profile LinkedIn Badge Profile Stackoverflow Badge Profile