All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
v0.15.0 - 2024-08-21
- [BREAKING] This release updates the version of
fake-permissions
used for permissions handling tov0.14.x
, which includes breaking changes. See the[email protected]
release notes for details and updated usage examples.
v0.14.0 - 2024-08-19
- [BREAKING] This release updates the version of
fake-permissions
used for permissions handling tov0.13.x
, which includes breaking changes. See the[email protected]
release notes for details and updated usage examples.
v0.13.2 - 2024-08-09
- Fixed an issue that prevented
observer.waitForCoordinates()
from working with coordinates that have aNaN
value for theheading
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 - 2024-08-08
- Fixed a memory leak in the Geolocation API implementation.
v0.13.0 - 2024-08-08
- [BREAKING] This release includes an update to the version of
fake-permissions
used for permissions handling, which includes many breaking changes. See thefake-permissions
releases for details. - [BREAKING] The
createGeolocation()
function no longer takes auser
option. Access requests are now handled by thepermissionStore
object.
v0.12.0 - 2024-08-08
- [BREAKING] Removed the
waitForCoordinates()
function - use geolocation observers instead. - [BREAKING] Removed the
waitForPositionError()
function - use geolocation observers instead. - [BREAKING] Removed the
compareCoordinates()
function.
- [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 usingfake-geolocation
in tests.
- Added geolocation observers.
- The
createAPIs()
andcreateWrappedAPIs()
functions now return a geolocation observer in theobserver
property. - Added the
createGeolocationObserver()
function, which creates a new geolocation observer. - The
createAPIs()
andcreateWrappedAPIs()
functions now accept anacquireDelay
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
, andTIMEOUT
as exported constants. These are useful when waiting for specific errors withobserver.waitForPositionError()
.
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.grantAccess({ 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.blockAccess({ name: "geolocation" });
});
// Outputs "true"
console.log(error?.code === PERMISSION_DENIED);
// You can also wait for geolocation permission states
await observer.waitForPermissionState("granted", async () => {
user.grantAccess({ name: "geolocation" });
});
// Outputs "true"
console.log(status.state === "granted");
- Errors that are thrown asynchronously now use
queueMicrotask()
instead ofsetTimeout()
.
v0.11.1 - 2024-08-06
- Updated version constraint for
fake-permissions
.
v0.11.0 - 2024-08-04
- [BREAKING] This release includes an update to the version of
fake-permissions
used for permissions handling, which includes many breaking changes. See the[email protected]
release notes for details and updated usage examples. - [BREAKING] The
handlePermissionRequest
option forcreateAPIs()
,createWrappedAPIs()
, andcreateUser()
has been renamed tohandleAccessRequest
in line with the changes tofake-permissions
. - [BREAKING] The
createGeolocation()
function now has apermissionStore
option that takes aPermissionsStore
object instead of apermissions
option that takes aPermissions
object. - [BREAKING] The
createGeolocation()
function now has auser
option that takes aUser
object instead of arequestPermission
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 - 2024-07-10
- Fixed an issue where calling
watchPosition()
with amaximumAge
ofInfinity
would cause thesuccessCallback
to be called with the first cached position indefinitely, even when setting new coordinates via location services.
v0.10.0 - 2024-07-05
- Added the
GeolocationPositionParameters
type, which can be used for typing simple objects that have the same properties asGeolocationPosition
, but don't implement the full interface.
v0.9.0 - 2024-07-04
- Added
toJSON()
methods toGeolocationCoordinates
andGeolocationPosition
. - Added the
GeolocationCoordinatesParameters
type, which can be used for typing simple objects that have the same properties asGeolocationCoordinates
, but don't implement the full interface.
- Errors thrown from
successCallback
anderrorCallback
arguments togetCurrentPosition()
andwatchPosition()
are now thrown asynchronously, instead of being discarded. - Errors thrown from subscriber functions used in geolocation delegates and location services are now thrown asynchronously, instead of being discarded.
v0.8.1 - 2024-06-21
- Fixed an issue where passing explicit
undefined
values tocreateCoordinates()
orcreatePosition()
could produce aGeolocationCoordinates
object withundefined
properties.
v0.8.0 - 2024-06-21
- The
createCoordinates()
andcreatePosition()
functions now have optional arguments, making them more useful for creating test data. TheisHighAccuracy
argument now defaults totrue
, and other omitted arguments or properties will be filled with "empty" values:0
forlatitude
,longitude
,accuracy
, andtimestamp
.null
foraltitude
,altitudeAccuracy
,heading
, andspeed
.
- Added
Symbol.toStringTag
methods to allGeolocation
,GeolocationPosition
,GeolocationCoordinates
, andGeolocationPositionError
objects.
v0.7.0 - 2023-12-05
- Watched positions now receive updates when location services are disabled, and also when they are re-enabled.
- Watched positions now receive updates when the
geolocation
permission is re-granted after being revoked.
v0.6.2 - 2023-11-28
- Fixed a race condition that could occur when permission state changes from
granted
while waiting to acquire coordinates from location services.
v0.6.1 - 2023-11-28
- Fixed a linting error in the changelog.
v0.6.0 - 2023-11-28
- Changing the
geolocation
permission fromgranted
while watching a position will now cause an immediate call to the error callback with aPERMISSION_DENIED
error. This should be ergonomic for testing, as previously you'd have to change the permission and jump to a new location to trigger an error.
v0.5.2 - 2023-11-28
- Fixed potential race condition that may have been possible to create when
watchPosition()
is used with anerrorCallback
, and an error occurs afterclearWatch()
is called.
v0.5.1 - 2023-11-27
- Fixed a race condition that could occur with
watchPosition()
where the success callback could be called afterclearWatch()
was called.
v0.5.0 - 2023-11-27
- Add waitForPositionError()
v0.4.0 - 2023-11-23
- [BREAKING]
createDelegatedGeolocation()
now requires apermissionsDelegates
argument, which is aMap
ofGeolocation
delegates to their relatedPermissions
delegates.
- Added
waitForCoordinates()
andcompareCoordinates()
- Changing delegates while watching the position no longer causes permission
prompts when the selected delegate's
geolocation
permission is in theprompt
state. Instead, the error callback will be called with aPERMISSION_DENIED
error. If the selected delegate'sgeolocation
permission subsequently changes togranted
ordenied
, the watch will resume.
v0.3.1 - 2023-09-10
- Fixed a code style issue in a test file.
v0.3.0 - 2023-09-10
- Delegate selection can now be queried with
isDelegateSelected()
. - Wrapped APIs can now be queried with
isUsingSuppliedAPIs()
.
v0.2.0 - 2023-09-10
- Finalized initial features.
v0.1.0 - 2023-07-29
- Initial release.