diff --git a/tests/fastify-plugins/blobs.js b/tests/fastify-plugins/blobs.js index 42d5985b2..d14587b6b 100644 --- a/tests/fastify-plugins/blobs.js +++ b/tests/fastify-plugins/blobs.js @@ -1,6 +1,7 @@ // @ts-check import { randomBytes } from 'node:crypto' -import test from 'brittle' +import test from 'node:test' +import assert from 'node:assert/strict' import { readdirSync } from 'fs' import { readFile } from 'fs/promises' import path from 'path' @@ -11,12 +12,14 @@ import { projectKeyToPublicId } from '../../src/utils.js' import { createBlobStore } from '../helpers/blob-store.js' import { waitForCores, replicate } from '../helpers/core-manager.js' -test('Plugin throws error if missing getBlobStore option', async (t) => { +test('Plugin throws error if missing getBlobStore option', async () => { const server = fastify() - await t.exception(() => server.register(BlobServerPlugin)) + await assert.rejects(async () => { + await server.register(BlobServerPlugin) + }) }) -test('Plugin handles prefix option properly', async (t) => { +test('Plugin handles prefix option properly', async () => { const prefix = '/blobs' const { data, server, projectPublicId } = await setup({ prefix }) @@ -30,11 +33,11 @@ test('Plugin handles prefix option properly', async (t) => { }), }) - t.is(res.statusCode, 200, 'request successful') + assert.equal(res.statusCode, 200, 'request successful') } }) -test('Unsupported blob type and variant params are handled properly', async (t) => { +test('Unsupported blob type and variant params are handled properly', async () => { const { data, server, projectPublicId } = await setup() for (const { blobId } of data) { @@ -47,8 +50,8 @@ test('Unsupported blob type and variant params are handled properly', async (t) }), }) - t.is(unsupportedVariantRes.statusCode, 400) - t.is(unsupportedVariantRes.json().code, 'FST_ERR_VALIDATION') + assert.equal(unsupportedVariantRes.statusCode, 400) + assert.equal(unsupportedVariantRes.json().code, 'FST_ERR_VALIDATION') const unsupportedTypeRes = await server.inject({ method: 'GET', @@ -59,12 +62,12 @@ test('Unsupported blob type and variant params are handled properly', async (t) }), }) - t.is(unsupportedTypeRes.statusCode, 400) - t.is(unsupportedTypeRes.json().code, 'FST_ERR_VALIDATION') + assert.equal(unsupportedTypeRes.statusCode, 400) + assert.equal(unsupportedTypeRes.json().code, 'FST_ERR_VALIDATION') } }) -test('Invalid variant-type combination returns error', async (t) => { +test('Invalid variant-type combination returns error', async () => { const { server, projectPublicId } = await setup() const url = buildRouteUrl({ @@ -77,11 +80,11 @@ test('Invalid variant-type combination returns error', async (t) => { const response = await server.inject({ method: 'GET', url }) - t.is(response.statusCode, 400) - t.ok(response.json().message.startsWith('Unsupported variant')) + assert.equal(response.statusCode, 400) + assert(response.json().message.startsWith('Unsupported variant')) }) -test('Incorrect project public id returns 404', async (t) => { +test('Incorrect project public id returns 404', async () => { const { data, server } = await setup() const incorrectProjectPublicId = projectKeyToPublicId(randomBytes(32)) @@ -95,11 +98,11 @@ test('Incorrect project public id returns 404', async (t) => { }), }) - t.is(incorrectProjectPublicIdRes.statusCode, 404) + assert.equal(incorrectProjectPublicIdRes.statusCode, 404) } }) -test('Incorrectly formatted project public id returns 400', async (t) => { +test('Incorrectly formatted project public id returns 400', async () => { const { data, server } = await setup() const hexString = randomBytes(32).toString('hex') @@ -113,11 +116,11 @@ test('Incorrectly formatted project public id returns 400', async (t) => { }), }) - t.is(incorrectProjectPublicIdRes.statusCode, 400) + assert.equal(incorrectProjectPublicIdRes.statusCode, 400) } }) -test('Missing blob name or variant returns 404', async (t) => { +test('Missing blob name or variant returns 404', async () => { const { data, server, projectPublicId } = await setup() for (const { blobId } of data) { @@ -130,7 +133,7 @@ test('Missing blob name or variant returns 404', async (t) => { }), }) - t.is(nameMismatchRes.statusCode, 404) + assert.equal(nameMismatchRes.statusCode, 404) const variantMismatchRes = await server.inject({ method: 'GET', @@ -141,11 +144,11 @@ test('Missing blob name or variant returns 404', async (t) => { }), }) - t.is(variantMismatchRes.statusCode, 404) + assert.equal(variantMismatchRes.statusCode, 404) } }) -test('GET photo returns correct blob payload', async (t) => { +test('GET photo returns correct blob payload', async () => { const { data, server, projectPublicId } = await setup() for (const { blobId, image } of data) { @@ -157,11 +160,11 @@ test('GET photo returns correct blob payload', async (t) => { }), }) - t.alike(res.rawPayload, image.data, 'should be equal') + assert.deepEqual(res.rawPayload, image.data, 'should be equal') } }) -test('GET photo returns inferred content header if metadata is not found', async (t) => { +test('GET photo returns inferred content header if metadata is not found', async () => { const { data, server, projectPublicId } = await setup() for (const { blobId, image } of data) { @@ -176,11 +179,15 @@ test('GET photo returns inferred content header if metadata is not found', async const expectedContentHeader = getImageMimeType(image.ext) || 'application/octet-stream' - t.is(res.headers['content-type'], expectedContentHeader, 'should be equal') + assert.equal( + res.headers['content-type'], + expectedContentHeader, + 'should be equal' + ) } }) -test('GET photo uses mime type from metadata if found', async (t) => { +test('GET photo uses mime type from metadata if found', async () => { const { data, server, projectPublicId, blobStore } = await setup() for (const { blobId, image } of data) { @@ -204,11 +211,15 @@ test('GET photo uses mime type from metadata if found', async (t) => { ? metadata.mimeType : 'application/octet-stream' - t.is(res.headers['content-type'], expectedContentHeader, 'should be equal') + assert.equal( + res.headers['content-type'], + expectedContentHeader, + 'should be equal' + ) } }) -test('GET photo returns 404 when trying to get non-replicated blob', async (t) => { +test('GET photo returns 404 when trying to get non-replicated blob', async () => { const projectKey = randomBytes(32) const { @@ -242,10 +253,10 @@ test('GET photo returns 404 when trying to get non-replicated blob', async (t) = url: buildRouteUrl({ ...blobId, projectPublicId }), }) - t.is(res.statusCode, 404) + assert.equal(res.statusCode, 404) }) -test('GET photo returns 404 when trying to get non-existent blob', async (t) => { +test('GET photo returns 404 when trying to get non-existent blob', async () => { const projectKey = randomBytes(32) const { projectPublicId, blobStore } = await setup({ projectKey }) @@ -271,7 +282,7 @@ test('GET photo returns 404 when trying to get non-existent blob', async (t) => }), }) - t.is(res.statusCode, 404) + assert.equal(res.statusCode, 404) } const driveId = await blobStore.put(blobId, expected) @@ -284,7 +295,7 @@ test('GET photo returns 404 when trying to get non-existent blob', async (t) => url: buildRouteUrl({ ...blobId, projectPublicId, driveId }), }) - t.is(res.statusCode, 404) + assert.equal(res.statusCode, 404) } }) diff --git a/tests/fastify-plugins/icons.js b/tests/fastify-plugins/icons.js index af68ed02f..08a2d29e6 100644 --- a/tests/fastify-plugins/icons.js +++ b/tests/fastify-plugins/icons.js @@ -1,17 +1,20 @@ // @ts-check -import { test } from 'brittle' +import test from 'node:test' +import assert from 'node:assert/strict' import { randomBytes } from 'crypto' import fastify from 'fastify' import IconServerPlugin from '../../src/fastify-plugins/icons.js' import { projectKeyToPublicId } from '../../src/utils.js' -test('Plugin throws error if missing getProject option', async (t) => { +test('Plugin throws error if missing getProject option', async () => { const server = fastify() - await t.exception(() => server.register(IconServerPlugin)) + await assert.rejects(async () => { + await server.register(IconServerPlugin) + }) }) -test('Plugin handles prefix option properly', async (t) => { +test('Plugin handles prefix option properly', async () => { const prefix = 'icons' const server = fastify() @@ -33,10 +36,10 @@ test('Plugin handles prefix option properly', async (t) => { })}`, }) - t.not(response.statusCode, 404, 'returns non-404 status code') + assert.notEqual(response.statusCode, 404, 'returns non-404 status code') }) -test('url param validation', async (t) => { +test('url param validation', async () => { const server = fastify() server.register(IconServerPlugin, { @@ -99,16 +102,14 @@ test('url param validation', async (t) => { ] await Promise.all( - fixtures.map(async ([name, input]) => { + fixtures.map(async ([_, input]) => { const response = await server.inject({ method: 'GET', url: buildIconUrl(input), }) - t.comment(name) - - t.is(response.statusCode, 400, 'returns expected status code') - t.is( + assert.equal(response.statusCode, 400, 'returns expected status code') + assert.equal( response.json().code, 'FST_ERR_VALIDATION', 'error is validation error' diff --git a/tests/fastify-plugins/maps.js b/tests/fastify-plugins/maps.js index 93a8fe86d..6bce9d810 100644 --- a/tests/fastify-plugins/maps.js +++ b/tests/fastify-plugins/maps.js @@ -1,4 +1,5 @@ -import { test } from 'brittle' +import test from 'node:test' +import assert from 'node:assert/strict' import path from 'node:path' import Fastify from 'fastify' import { MockAgent, setGlobalDispatcher } from 'undici' @@ -28,7 +29,7 @@ setupFetchMock() test('fails to register when dependent plugins are not registered', async (t) => { const server = setup(t) - await t.exception(async () => { + await assert.rejects(async () => { await server.register(MapServerPlugin) }, 'fails to register if dependencies are not registered') }) @@ -56,12 +57,12 @@ test('prefix opt is handled correctly', async (t) => { url: '/style.json', }) - t.is(response.statusCode, 404, 'endpoint missing at root prefix') + assert.equal(response.statusCode, 404, 'endpoint missing at root prefix') } { // TODO: Use inject approach when necessary fixtures are set up - t.ok( + assert( server.hasRoute({ method: 'GET', url: '/maps/style.json', @@ -89,11 +90,11 @@ test('mapeoMaps decorator context', async (t) => { const address = await server.listen() - t.ok(server.hasDecorator('mapeoMaps'), 'decorator added') + assert(server.hasDecorator('mapeoMaps'), 'decorator added') - t.test('mapeoMaps.getStyleJsonUrl()', async (st) => { + t.test('mapeoMaps.getStyleJsonUrl()', async () => { const styleJsonUrl = await server.mapeoMaps.getStyleJsonUrl() - st.is(styleJsonUrl, new URL('/maps/style.json', address).href) + assert.equal(styleJsonUrl, new URL('/maps/style.json', address).href) }) }) @@ -118,7 +119,7 @@ test('/style.json resolves style.json of local "default" static map when availab url: '/style.json', }) - t.is(response.statusCode, 200) + assert.equal(response.statusCode, 200) }) test('/style.json resolves online style.json when local static is not available', async (t) => { @@ -145,9 +146,9 @@ test('/style.json resolves online style.json when local static is not available' query: `?key=pk.abc-123`, }) - t.is(response.statusCode, 200) + assert.equal(response.statusCode, 200) - t.is( + assert.equal( response.json().name, // Based on the mapbox-outdoors-v12.json fixture 'Mapbox Outdoors', @@ -182,8 +183,8 @@ test('defaultOnlineStyleUrl opt works', async (t) => { query: `?key=abc-123`, }) - t.is(response.statusCode, 200) - t.is( + assert.equal(response.statusCode, 200) + assert.equal( response.json().name, // Based on the protomaps-dark.v2.json fixture 'style@2.0.0-alpha.4 theme@dark', @@ -214,17 +215,17 @@ test('/style.json resolves style.json of offline fallback map when static and on // Omitting the `key` query param here to simulate not being able to get the online style.json }) - t.is(response.json().id, 'blank', 'gets fallback style.json') - t.is(response.statusCode, 200) + assert.equal(response.json().id, 'blank', 'gets fallback style.json') + assert.equal(response.statusCode, 200) }) /** - * @param {import('brittle').TestInstance} t + * @param {import('node:test').TestContext} t */ function setup(t) { const server = Fastify({ logger: false, forceCloseConnections: true }) - t.teardown(async () => { + t.after(async () => { await server.close() }) diff --git a/tests/fastify-plugins/offline-fallback-map.js b/tests/fastify-plugins/offline-fallback-map.js index 24f5c96de..4599e870c 100644 --- a/tests/fastify-plugins/offline-fallback-map.js +++ b/tests/fastify-plugins/offline-fallback-map.js @@ -1,5 +1,6 @@ import path from 'node:path' -import { test } from 'brittle' +import test from 'node:test' +import assert from 'node:assert/strict' import Fastify from 'fastify' import { plugin as OfflineFallbackMapPlugin } from '../../src/fastify-plugins/maps/offline-fallback-map.js' @@ -12,7 +13,7 @@ const MAPEO_FALLBACK_MAP_PATH = new URL( test('decorator', async (t) => { const server = setup(t) await server.ready() - t.ok(server.hasDecorator('mapeoFallbackMap'), 'decorator is set up') + assert(server.hasDecorator('mapeoFallbackMap'), 'decorator is set up') }) test('/style.json', async (t) => { @@ -24,11 +25,11 @@ test('/style.json', async (t) => { url: '/style.json', }) - t.is(response.statusCode, 200) + assert.equal(response.statusCode, 200) const styleJson = response.json() - t.alike( + assert.deepEqual( styleJson.sources, { 'boundaries-source': { @@ -61,12 +62,12 @@ test('/style.json', async (t) => { url: data, }) - t.is(response.statusCode, 200, `can reach ${sourceName}`) + assert.equal(response.statusCode, 200, `can reach ${sourceName}`) } }) /** - * @param {import('brittle').TestInstance} t + * @param {import('node:test').TestContext} t */ function setup(t) { const server = Fastify({ logger: false, forceCloseConnections: true }) @@ -76,7 +77,7 @@ function setup(t) { sourcesDir: path.join(MAPEO_FALLBACK_MAP_PATH, 'dist'), }) - t.teardown(async () => { + t.after(async () => { await server.close() }) diff --git a/tests/fastify-plugins/static-maps.js b/tests/fastify-plugins/static-maps.js index dfafac731..3eb230e62 100644 --- a/tests/fastify-plugins/static-maps.js +++ b/tests/fastify-plugins/static-maps.js @@ -1,6 +1,7 @@ import fs from 'node:fs' import path from 'node:path' -import { test } from 'brittle' +import test from 'node:test' +import assert from 'node:assert/strict' import Fastify from 'fastify' import { plugin } from '../../src/fastify-plugins/maps/static-maps.js' @@ -10,7 +11,7 @@ const MAP_FIXTURES_PATH = new URL('../fixtures/maps', import.meta.url).pathname test('decorator', async (t) => { const server = setup(t) await server.ready() - t.ok(server.hasDecorator('mapeoStaticMaps'), 'decorator is set up') + assert(server.hasDecorator('mapeoStaticMaps'), 'decorator is set up') }) test('list map styles', async (t) => { @@ -22,11 +23,11 @@ test('list map styles', async (t) => { url: '/', }) - t.is(response.statusCode, 200) + assert.equal(response.statusCode, 200) const data = response.json() - t.alike( + assert.deepEqual( data, [ { @@ -61,11 +62,11 @@ test('get style.json', async (t) => { url: `/${styleId}/style.json`, }) - t.is(response.statusCode, 200) + assert.equal(response.statusCode, 200) const data = response.json() - t.alike( + assert.deepEqual( data, JSON.parse(rawStyleJson.replace(/\{host\}/gm, `${address}/${styleId}`)), 'response data is correct' @@ -94,8 +95,8 @@ test('get sprite.json', async (t) => { url: `/${styleId}/sprites/sprite.json`, }) - t.is(response.statusCode, 200) - t.alike(response.json(), expectedJson) + assert.equal(response.statusCode, 200) + assert.deepEqual(response.json(), expectedJson) }) ) }) @@ -107,7 +108,7 @@ test('get tile (image)', async (t) => { const styleIds = fs.readdirSync(MAP_FIXTURES_PATH) for (const styleId of styleIds) { - t.test('non-existing tile', async (st) => { + await t.test('non-existing tile', async () => { // With extension { const response = await server.inject({ @@ -115,7 +116,7 @@ test('get tile (image)', async (t) => { url: `/${styleId}/tiles/mapbox.satellite/0/0/0.png`, }) - st.is(response.statusCode, 404) + assert.equal(response.statusCode, 404) } // Without extension @@ -125,22 +126,22 @@ test('get tile (image)', async (t) => { url: `/${styleId}/tiles/mapbox.satellite/0/0/0`, }) - st.is(response.statusCode, 404) + assert.equal(response.statusCode, 404) } }) - t.test('non-existing tile id', async (st) => { + await t.test('non-existing tile id', async () => { { const response = await server.inject({ method: 'GET', url: `/${styleId}/tiles/foo.bar/6/10/24.png`, }) - st.is(response.statusCode, 404) + assert.equal(response.statusCode, 404) } }) - t.test('existing tile', async (st) => { + await t.test('existing tile', async () => { // With extension { const response = await server.inject({ @@ -148,13 +149,13 @@ test('get tile (image)', async (t) => { url: `/${styleId}/tiles/mapbox.satellite/6/10/24.png`, }) - st.is(response.statusCode, 200) - st.is( + assert.equal(response.statusCode, 200) + assert.equal( response.headers['content-type'], 'image/png', 'content type correct' ) - st.is( + assert.equal( getContentLength(response.headers), 21014, 'correct content length' @@ -168,13 +169,13 @@ test('get tile (image)', async (t) => { url: `/${styleId}/tiles/mapbox.satellite/6/10/24`, }) - st.is(response.statusCode, 200) - st.is( + assert.equal(response.statusCode, 200) + assert.equal( response.headers['content-type'], 'image/png', 'content type correct' ) - st.is( + assert.equal( getContentLength(response.headers), 21014, 'correct content length' @@ -193,15 +194,15 @@ test('get tile (pbf)', async (t) => { url: '/streets-sat-style/tiles/mapbox.mapbox-streets-v7/12/656/1582.vector.pbf', }) - t.is(response.statusCode, 200) + assert.equal(response.statusCode, 200) - t.is( + assert.equal( response.headers['content-type'], 'application/x-protobuf', 'content type correct' ) - t.is(getContentLength(response.headers), 49229, 'correct file length') + assert.equal(getContentLength(response.headers), 49229, 'correct file length') }) test('get font pbf', async (t) => { @@ -213,26 +214,26 @@ test('get font pbf', async (t) => { url: '/streets-sat-style/fonts/DIN Offc Pro Bold,Arial Unicode MS Bold/0-255.pbf', }) - t.is(response.statusCode, 200) + assert.equal(response.statusCode, 200) - t.is( + assert.equal( response.headers['content-type'], 'application/x-protobuf', 'content type correct' ) - t.is(getContentLength(response.headers), 75287, 'correct file length') + assert.equal(getContentLength(response.headers), 75287, 'correct file length') }) /** - * @param {import('brittle').TestInstance} t + * @param {import('node:test').TestContext} t */ function setup(t) { const server = Fastify({ logger: false, forceCloseConnections: true }) server.register(plugin, { staticRootDir: MAP_FIXTURES_PATH }) - t.teardown(async () => { + t.after(async () => { await server.close() })