From 541cb4e219be3a61adccedf824d1ca5f481f8935 Mon Sep 17 00:00:00 2001 From: Vincenzo Scamporlino Date: Tue, 21 Jan 2025 20:05:04 +0100 Subject: [PATCH 1/9] openapi-utils: move tests utils to separate entrypoint Signed-off-by: Vincenzo Scamporlino --- packages/backend-openapi-utils/package.json | 14 ++++++++++++++ packages/backend-openapi-utils/src/index.ts | 1 - 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/backend-openapi-utils/package.json b/packages/backend-openapi-utils/package.json index 4453d4338a..2b4ab36158 100644 --- a/packages/backend-openapi-utils/package.json +++ b/packages/backend-openapi-utils/package.json @@ -18,8 +18,22 @@ "directory": "packages/backend-openapi-utils" }, "license": "Apache-2.0", + "exports": { + ".": "./src/index.ts", + "./tests": "./src/testUtils.ts" + }, "main": "src/index.ts", "types": "src/index.ts", + "typesVersions": { + "*": { + "tests": [ + "src/testUtils.ts" + ], + "package.json": [ + "package.json" + ] + } + }, "files": [ "dist" ], diff --git a/packages/backend-openapi-utils/src/index.ts b/packages/backend-openapi-utils/src/index.ts index 9389fe3be6..849cc72daf 100644 --- a/packages/backend-openapi-utils/src/index.ts +++ b/packages/backend-openapi-utils/src/index.ts @@ -32,7 +32,6 @@ export type { } from './utility'; export type { ApiRouter, TypedRouter } from './router'; export type { PathTemplate } from './types/common'; -export { wrapInOpenApiTestServer, wrapServer } from './testUtils'; export { createValidatedOpenApiRouter, getOpenApiSpecRoute, From 700d32b351c404bd041031c7385f0ceaff72b33e Mon Sep 17 00:00:00 2001 From: Vincenzo Scamporlino Date: Tue, 21 Jan 2025 20:09:48 +0100 Subject: [PATCH 2/9] openapi-utils: changeset Signed-off-by: Vincenzo Scamporlino --- .changeset/thirty-dancers-cheat.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .changeset/thirty-dancers-cheat.md diff --git a/.changeset/thirty-dancers-cheat.md b/.changeset/thirty-dancers-cheat.md new file mode 100644 index 0000000000..4dc4a97aad --- /dev/null +++ b/.changeset/thirty-dancers-cheat.md @@ -0,0 +1,17 @@ +--- +'@backstage/backend-openapi-utils': minor +--- + +_BREAKING_: The `wrapInOpenApiTestServer` and `wrapServer` functions are now exported via `/tests` subpath. If you were importing these functions directly from the root of the package, you will need to update your imports to use the `/tests` subpath: + +```diff +- import { wrapInOpenApiTestServer } from '@backstage/backend-openapi-utils'; ++ import { wrapInOpenApiTestServer } from '@backstage/backend-openapi-utils/tests'; +``` + +or + +```diff +- import { wrapServer } from '@backstage/backend-openapi-utils'; ++ import { wrapServer } from '@backstage/backend-openapi-utils/tests'; +``` From e7c2d9a3efce39faa0f258789a9507a49dac9edd Mon Sep 17 00:00:00 2001 From: Vincenzo Scamporlino Date: Tue, 21 Jan 2025 20:10:20 +0100 Subject: [PATCH 3/9] openapi-utils: update imports Signed-off-by: Vincenzo Scamporlino --- plugins/catalog-backend/src/service/createRouter.test.ts | 2 +- plugins/search-backend/src/service/router.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/catalog-backend/src/service/createRouter.test.ts b/plugins/catalog-backend/src/service/createRouter.test.ts index 16970ce7a6..06a6e86bce 100644 --- a/plugins/catalog-backend/src/service/createRouter.test.ts +++ b/plugins/catalog-backend/src/service/createRouter.test.ts @@ -15,7 +15,7 @@ */ import { MiddlewareFactory } from '@backstage/backend-defaults/rootHttpRouter'; -import { wrapServer } from '@backstage/backend-openapi-utils'; +import { wrapServer } from '@backstage/backend-openapi-utils/tests'; import { mockCredentials, mockServices } from '@backstage/backend-test-utils'; import type { Location } from '@backstage/catalog-client'; import { diff --git a/plugins/search-backend/src/service/router.test.ts b/plugins/search-backend/src/service/router.test.ts index 5b6900ede1..a596017767 100644 --- a/plugins/search-backend/src/service/router.test.ts +++ b/plugins/search-backend/src/service/router.test.ts @@ -23,7 +23,7 @@ import { import express from 'express'; import request from 'supertest'; import { createRouter } from './router'; -import { wrapServer } from '@backstage/backend-openapi-utils'; +import { wrapServer } from '@backstage/backend-openapi-utils/tests'; import { Server } from 'http'; import { mockCredentials, From 58e64d92a4c127e79e6503dc4d722022305f1922 Mon Sep 17 00:00:00 2001 From: Vincenzo Scamporlino Date: Tue, 21 Jan 2025 20:12:35 +0100 Subject: [PATCH 4/9] more changesets Signed-off-by: Vincenzo Scamporlino --- .changeset/three-swans-hide.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/three-swans-hide.md diff --git a/.changeset/three-swans-hide.md b/.changeset/three-swans-hide.md new file mode 100644 index 0000000000..03e4fd49f9 --- /dev/null +++ b/.changeset/three-swans-hide.md @@ -0,0 +1,6 @@ +--- +'@backstage/plugin-catalog-backend': patch +'@backstage/plugin-search-backend': patch +--- + +Fixed a `Hooks cannot be defined inside tests` error that was occurring when using the plugin in a jest test. From fc682e89981610c9279f17991a5acebb48276dd4 Mon Sep 17 00:00:00 2001 From: Vincenzo Scamporlino Date: Tue, 21 Jan 2025 20:12:54 +0100 Subject: [PATCH 5/9] openapi: update docs Signed-off-by: Vincenzo Scamporlino --- docs/openapi/01-getting-started.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/openapi/01-getting-started.md b/docs/openapi/01-getting-started.md index ce14cf6a7f..729472da71 100644 --- a/docs/openapi/01-getting-started.md +++ b/docs/openapi/01-getting-started.md @@ -97,7 +97,7 @@ For more information, see [the docs](./generate-client.md). Add the following lines to your `createRouter.test.ts` or `router.test.ts` file, ```diff -+ import { wrapInOpenApiTestServer } from '@backstage/backend-openapi-utils'; ++ import { wrapInOpenApiTestServer } from '@backstage/backend-openapi-utils/tests'; + import { Server } from 'http'; ... From 270b0fcc0f761657c8547d1037f7736618505f9a Mon Sep 17 00:00:00 2001 From: Vincenzo Scamporlino Date: Tue, 21 Jan 2025 20:22:34 +0100 Subject: [PATCH 6/9] remove unnecessary changeset Signed-off-by: Vincenzo Scamporlino --- .changeset/three-swans-hide.md | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 .changeset/three-swans-hide.md diff --git a/.changeset/three-swans-hide.md b/.changeset/three-swans-hide.md deleted file mode 100644 index 03e4fd49f9..0000000000 --- a/.changeset/three-swans-hide.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -'@backstage/plugin-catalog-backend': patch -'@backstage/plugin-search-backend': patch ---- - -Fixed a `Hooks cannot be defined inside tests` error that was occurring when using the plugin in a jest test. From 4b196c4d4db9f548eac52a9123671382a266ca6f Mon Sep 17 00:00:00 2001 From: Vincenzo Scamporlino Date: Tue, 21 Jan 2025 20:30:53 +0100 Subject: [PATCH 7/9] openapi-utils: fix publishing Signed-off-by: Vincenzo Scamporlino --- packages/backend-openapi-utils/package.json | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/backend-openapi-utils/package.json b/packages/backend-openapi-utils/package.json index 2b4ab36158..58c3932c1e 100644 --- a/packages/backend-openapi-utils/package.json +++ b/packages/backend-openapi-utils/package.json @@ -6,10 +6,7 @@ "role": "node-library" }, "publishConfig": { - "access": "public", - "main": "dist/index.cjs.js", - "module": "dist/index.esm.js", - "types": "dist/index.d.ts" + "access": "public" }, "homepage": "https://backstage.io", "repository": { @@ -20,7 +17,8 @@ "license": "Apache-2.0", "exports": { ".": "./src/index.ts", - "./tests": "./src/testUtils.ts" + "./tests": "./src/testUtils.ts", + "./package.json": "./package.json" }, "main": "src/index.ts", "types": "src/index.ts", From df43519ede5a2aa856abdfebf5b32fb8af05a15c Mon Sep 17 00:00:00 2001 From: Vincenzo Scamporlino Date: Tue, 21 Jan 2025 22:22:40 +0100 Subject: [PATCH 8/9] openapi-utils: api-reports for tests subpath Signed-off-by: Vincenzo Scamporlino --- .../backend-openapi-utils/report-tests.api.md | 18 ++++++++++++++++++ packages/backend-openapi-utils/report.api.md | 10 ---------- 2 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 packages/backend-openapi-utils/report-tests.api.md diff --git a/packages/backend-openapi-utils/report-tests.api.md b/packages/backend-openapi-utils/report-tests.api.md new file mode 100644 index 0000000000..471ff5a3c1 --- /dev/null +++ b/packages/backend-openapi-utils/report-tests.api.md @@ -0,0 +1,18 @@ +## API Report File for "@backstage/backend-openapi-utils" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts +/// + +import { Express as Express_2 } from 'express'; +import { Server } from 'http'; + +// @public +export const wrapInOpenApiTestServer: (app: Express_2) => Server | Express_2; + +// @public +export function wrapServer(app: Express_2): Promise; + +// (No @packageDocumentation comment for this package) +``` diff --git a/packages/backend-openapi-utils/report.api.md b/packages/backend-openapi-utils/report.api.md index 22913eb321..9d8b8e975e 100644 --- a/packages/backend-openapi-utils/report.api.md +++ b/packages/backend-openapi-utils/report.api.md @@ -3,11 +3,8 @@ > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). ```ts -/// - import type { ContentObject } from 'openapi3-ts'; import type core from 'express-serve-static-core'; -import { Express as Express_2 } from 'express'; import { FromSchema } from 'json-schema-to-ts'; import { JSONSchema } from 'json-schema-to-ts'; import { middleware } from 'express-openapi-validator'; @@ -19,7 +16,6 @@ import { RequestHandler } from 'express'; import type { ResponseObject } from 'openapi3-ts'; import { Router } from 'express'; import type { SchemaObject } from 'openapi3-ts'; -import { Server } from 'http'; // @public export interface ApiRouter extends Router { @@ -925,10 +921,4 @@ type UnknownIfNever

= [P] extends [never] ? unknown : P; // @public type ValueOf = T[keyof T]; - -// @public -export const wrapInOpenApiTestServer: (app: Express_2) => Server | Express_2; - -// @public -export function wrapServer(app: Express_2): Promise; ``` From 25350e9e5dc8607fc8566c0a2eb6f2ecf2a9078e Mon Sep 17 00:00:00 2001 From: Vincenzo Scamporlino Date: Thu, 23 Jan 2025 13:39:34 +0100 Subject: [PATCH 9/9] openapi-utils: rename export Signed-off-by: Vincenzo Scamporlino --- .changeset/thirty-dancers-cheat.md | 6 +++--- docs/openapi/01-getting-started.md | 2 +- packages/backend-openapi-utils/package.json | 4 ++-- .../{report-tests.api.md => report-testUtils.api.md} | 0 plugins/catalog-backend/src/service/createRouter.test.ts | 2 +- plugins/search-backend/src/service/router.test.ts | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) rename packages/backend-openapi-utils/{report-tests.api.md => report-testUtils.api.md} (100%) diff --git a/.changeset/thirty-dancers-cheat.md b/.changeset/thirty-dancers-cheat.md index 4dc4a97aad..083b3febbb 100644 --- a/.changeset/thirty-dancers-cheat.md +++ b/.changeset/thirty-dancers-cheat.md @@ -2,16 +2,16 @@ '@backstage/backend-openapi-utils': minor --- -_BREAKING_: The `wrapInOpenApiTestServer` and `wrapServer` functions are now exported via `/tests` subpath. If you were importing these functions directly from the root of the package, you will need to update your imports to use the `/tests` subpath: +**BREAKING**: The `wrapInOpenApiTestServer` and `wrapServer` functions are now exported via `/testUtils` subpath. If you were importing these functions directly from the root of the package, you will need to update your imports to use the `/testUtils` subpath: ```diff - import { wrapInOpenApiTestServer } from '@backstage/backend-openapi-utils'; -+ import { wrapInOpenApiTestServer } from '@backstage/backend-openapi-utils/tests'; ++ import { wrapInOpenApiTestServer } from '@backstage/backend-openapi-utils/testUtils'; ``` or ```diff - import { wrapServer } from '@backstage/backend-openapi-utils'; -+ import { wrapServer } from '@backstage/backend-openapi-utils/tests'; ++ import { wrapServer } from '@backstage/backend-openapi-utils/testUtils'; ``` diff --git a/docs/openapi/01-getting-started.md b/docs/openapi/01-getting-started.md index 729472da71..875a369dbf 100644 --- a/docs/openapi/01-getting-started.md +++ b/docs/openapi/01-getting-started.md @@ -97,7 +97,7 @@ For more information, see [the docs](./generate-client.md). Add the following lines to your `createRouter.test.ts` or `router.test.ts` file, ```diff -+ import { wrapInOpenApiTestServer } from '@backstage/backend-openapi-utils/tests'; ++ import { wrapInOpenApiTestServer } from '@backstage/backend-openapi-utils/testUtils'; + import { Server } from 'http'; ... diff --git a/packages/backend-openapi-utils/package.json b/packages/backend-openapi-utils/package.json index 58c3932c1e..eff12e46f6 100644 --- a/packages/backend-openapi-utils/package.json +++ b/packages/backend-openapi-utils/package.json @@ -17,14 +17,14 @@ "license": "Apache-2.0", "exports": { ".": "./src/index.ts", - "./tests": "./src/testUtils.ts", + "./testUtils": "./src/testUtils.ts", "./package.json": "./package.json" }, "main": "src/index.ts", "types": "src/index.ts", "typesVersions": { "*": { - "tests": [ + "testUtils": [ "src/testUtils.ts" ], "package.json": [ diff --git a/packages/backend-openapi-utils/report-tests.api.md b/packages/backend-openapi-utils/report-testUtils.api.md similarity index 100% rename from packages/backend-openapi-utils/report-tests.api.md rename to packages/backend-openapi-utils/report-testUtils.api.md diff --git a/plugins/catalog-backend/src/service/createRouter.test.ts b/plugins/catalog-backend/src/service/createRouter.test.ts index 06a6e86bce..b0dddbdef0 100644 --- a/plugins/catalog-backend/src/service/createRouter.test.ts +++ b/plugins/catalog-backend/src/service/createRouter.test.ts @@ -15,7 +15,7 @@ */ import { MiddlewareFactory } from '@backstage/backend-defaults/rootHttpRouter'; -import { wrapServer } from '@backstage/backend-openapi-utils/tests'; +import { wrapServer } from '@backstage/backend-openapi-utils/testUtils'; import { mockCredentials, mockServices } from '@backstage/backend-test-utils'; import type { Location } from '@backstage/catalog-client'; import { diff --git a/plugins/search-backend/src/service/router.test.ts b/plugins/search-backend/src/service/router.test.ts index a596017767..c348302045 100644 --- a/plugins/search-backend/src/service/router.test.ts +++ b/plugins/search-backend/src/service/router.test.ts @@ -23,7 +23,7 @@ import { import express from 'express'; import request from 'supertest'; import { createRouter } from './router'; -import { wrapServer } from '@backstage/backend-openapi-utils/tests'; +import { wrapServer } from '@backstage/backend-openapi-utils/testUtils'; import { Server } from 'http'; import { mockCredentials,