Skip to content

Releases: ezzatron/fake-geolocation

v0.15.0

21 Aug 13:12
v0.15.0
3adc76f
Compare
Choose a tag to compare
v0.15.0 Pre-release
Pre-release

Changed

  • [BREAKING] This release updates the version of fake-permissions used for permissions handling to v0.14.x, which includes breaking changes. See the fake-permissions@v0.14.0 release notes for details and updated usage examples.

v0.14.0

19 Aug 11:03
v0.14.0
6717b5a
Compare
Choose a tag to compare
v0.14.0 Pre-release
Pre-release

Changed

  • [BREAKING] This release updates the version of fake-permissions used for permissions handling to v0.13.x, which includes breaking changes. See the fake-permissions@v0.13.0 release notes for details and updated usage examples.

v0.13.2

08 Aug 15:07
v0.13.2
5023fe7
Compare
Choose a tag to compare
v0.13.2 Pre-release
Pre-release

Fixed

  • Fixed an issue that prevented observer.waitForCoordinates() from working with coordinates that have a NaN value for the heading property.
  • Fixed a race condition that could prevent geolocation positions from being dispatched to a position watch before an associated observer.waitForCoordinates() call resolved.

v0.13.1

08 Aug 13:53
v0.13.1
60815b4
Compare
Choose a tag to compare
v0.13.1 Pre-release
Pre-release

Fixed

  • Fixed a memory leak in the Geolocation API implementation.

v0.13.0

08 Aug 13:09
v0.13.0
701e374
Compare
Choose a tag to compare
v0.13.0 Pre-release
Pre-release

Changed

  • [BREAKING] This release includes an update to the version of fake-permissions used for permissions handling, which includes many breaking changes. See the fake-permissions releases for details.
  • [BREAKING] The createGeolocation() function no longer takes a user option. Access requests are now handled by the permissionStore object.

v0.12.0

08 Aug 01:23
v0.12.0
582c636
Compare
Choose a tag to compare
v0.12.0 Pre-release
Pre-release

Removed

  • [BREAKING] Removed the waitForCoordinates() function - use geolocation observers instead.
  • [BREAKING] Removed the waitForPositionError() function - use geolocation observers instead.
  • [BREAKING] Removed the compareCoordinates() function.

Changed

  • [BREAKING] Location services will no longer delay acquisition of coordinates unless the acquireDelay option is explicitly set to an amount of milliseconds. This makes coordinate jumps more predictable when using fake-geolocation in tests.

Added

  • Added geolocation observers.
  • The createAPIs() and createWrappedAPIs() functions now return a geolocation observer in the observer property.
  • Added the createGeolocationObserver() function, which creates a new geolocation observer.
  • The createAPIs() and createWrappedAPIs() functions now accept an acquireDelay option, which is passed along to the location services.
  • Added the GeolocationObserver type.
  • Added the GeolocationPositionErrorCode type, which is an enum of all the possible error codes that can be thrown by the Geolocation API.
  • Added PERMISSION_DENIED, POSITION_UNAVAILABLE, and TIMEOUT as exported constants. These are useful when waiting for specific errors with observer.waitForPositionError().

Geolocation observers

This release adds geolocation observers, which can be used to wait for specific changes to the coordinates or errors produced by a Geolocation API. This can be useful for testing scenarios where you want to wait for a specific state to be reached before continuing.

Observers are created for you when you call createAPIs() or createWrappedAPIs(). You can wait for specific sets of coordinates by calling observer.waitForCoordinates(), wait for specific geolocation errors by calling observer.waitForPositionError(), or wait for specific geolocation permission states by calling observer.waitForPermissionState().

import {
  createAPIs,
  createCoordinates,
  PERMISSION_DENIED,
  POSITION_UNAVAILABLE,
} from "fake-geolocation";

const { geolocation, observer, permissions, user } = createAPIs();

// We need some coords to start with
const coordsA = createCoordinates({ latitude: 1, longitude: 2 });
const coordsB = createCoordinates({ latitude: 3, longitude: 4 });

// Jump to some coords and grant permission
user.jumpToCoordinates(coordsA);
user.grantPermission({ name: "geolocation" });

// Start watching the position
let position: GeolocationPosition | undefined;
let error: GeolocationPositionError | undefined;
geolocation.watchPosition(
  (p) => {
    position = p;
  },
  (e) => {
    error = e;
  },
);

// Start a Permissions API query
const status = await permissions.query({ name: "geolocation" });

// Wait for the position to be at coordsA
await observer.waitForCoordinates(coordsA);
// Outputs "true"
console.log(position?.coords.latitude === coordsA.latitude);

// Wait for the position to be at coordsA OR coordsB
await observer.waitForCoordinates([coordsA, coordsB]);
// Outputs "true"
console.log(position?.coords.latitude === coordsA.latitude);

// Wait for the position to have a latitude of 1
await observer.waitForCoordinates({ latitude: 1 });
// Outputs "true"
console.log(position?.coords.latitude === 1);

// Wait for the position to be at coordsB, while running a task
await observer.waitForCoordinates(coordsB, async () => {
  user.jumpToCoordinates(coordsB);
});
// Outputs "true"
console.log(position?.coords.latitude === coordsB.latitude);

// Wait for the position to be at coordsB, using high accuracy
await observer.waitForCoordinates(coordsB, undefined, {
  enableHighAccuracy: true,
});
// Outputs "true"
console.log(position?.coords.latitude === coordsB.latitude);

user.disableLocationServices();

// Wait for a POSITION_UNAVAILABLE error
await observer.waitForPositionError(POSITION_UNAVAILABLE);
// Outputs "true"
console.log(error?.code === POSITION_UNAVAILABLE);

// Wait for a POSITION_UNAVAILABLE OR PERMISSION_DENIED error
await observer.waitForPositionError([POSITION_UNAVAILABLE, PERMISSION_DENIED]);
// Outputs "true"
console.log(error?.code === POSITION_UNAVAILABLE);

// Wait for a PERMISSION_DENIED error, while running a task
await observer.waitForPositionError(PERMISSION_DENIED, async () => {
  user.denyPermission({ name: "geolocation" });
});
// Outputs "true"
console.log(error?.code === PERMISSION_DENIED);

// You can also wait for geolocation permission states
await observer.waitForPermissionState("granted", async () => {
  user.grantPermission({ name: "geolocation" });
});
// Outputs "true"
console.log(status.state === "granted");

Fixed

  • Errors that are thrown asynchronously now use queueMicrotask() instead of setTimeout().

v0.11.1

06 Aug 00:25
v0.11.1
3d6deaa
Compare
Choose a tag to compare
v0.11.1 Pre-release
Pre-release

Fixed

  • Updated version constraint for fake-permissions.

v0.11.0

04 Aug 13:22
v0.11.0
33249e6
Compare
Choose a tag to compare
v0.11.0 Pre-release
Pre-release

Changed

  • [BREAKING] This release includes an update to the version of fake-permissions used for permissions handling, which includes many breaking changes. See the fake-permissions@v0.7.0 release notes for details and updated usage examples.
  • [BREAKING] The handlePermissionRequest option for createAPIs(), createWrappedAPIs(), and createUser() has been renamed to handleAccessRequest in line with the changes to fake-permissions.
  • [BREAKING] The createGeolocation() function now has a permissionStore option that takes a PermissionsStore object instead of a permissions option that takes a Permissions object.
  • [BREAKING] The createGeolocation() function now has a user option that takes a User object instead of a requestPermission option that takes a callback.
  • [BREAKING] The LocationServices type is now a type, instead of an interface.
  • [BREAKING] The MutableLocationServices type is now a type, instead of an interface.
  • [BREAKING] The User type is now a type, instead of an interface.

v0.10.1

09 Jul 23:29
v0.10.1
f623c83
Compare
Choose a tag to compare
v0.10.1 Pre-release
Pre-release

Fixed

  • Fixed an issue where calling watchPosition() with a maximumAge of Infinity would cause the successCallback to be called with the first cached position indefinitely, even when setting new coordinates via location services.

v0.10.0

04 Jul 23:55
v0.10.0
980391a
Compare
Choose a tag to compare
v0.10.0 Pre-release
Pre-release

Added

  • Added the GeolocationPositionParameters type, which can be used for typing simple objects that have the same properties as GeolocationPosition, but don't implement the full interface.