@backstage/backend-test-utils 0.4.4-next.1 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/dist/index.cjs.js +72 -42
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +49 -33
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @backstage/backend-test-utils
|
|
2
2
|
|
|
3
|
+
## 0.4.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2f99178: The `ServiceFactoryTest.get` method was deprecated and the `ServiceFactoryTest.getSubject` should be used instead. The `getSubject` method has the same behavior, but has a better method name to indicate that the service instance returned is the subject currently being tested.
|
|
8
|
+
- edf5cc3: The function `isDockerDisabledForTests` is deprecated and will no longer be exported in the near future as it should only be used internally.
|
|
9
|
+
- b05e1e1: Service factories exported by this package have been updated to use the new service factory format that doesn't use a callback.
|
|
10
|
+
- fce7887: Added mock for the Root Health Service in `mockServices`.
|
|
11
|
+
- 906c817: Updated `startTestBackend` and `ServiceFactoryTester` to only accept plain service factory or backend feature objects, no longer supporting the callback form. This lines up with the changes to `@backstage/backend-plugin-api` and should not require any code changes.
|
|
12
|
+
- 95a3a0b: Rename frontend and backend `setupRequestMockHandlers` methods to `registerMswTestHooks`.
|
|
13
|
+
- b9ed1bb: bumped better-sqlite3 from ^9.0.0 to ^11.0.0
|
|
14
|
+
- 98ccf00: Internal refactor of `mockServices.httpAuth.factory` to allow it to still be constructed with options, but without declaring options via `createServiceFactory`.
|
|
15
|
+
- Updated dependencies
|
|
16
|
+
- @backstage/backend-plugin-api@0.7.0
|
|
17
|
+
- @backstage/backend-defaults@0.4.0
|
|
18
|
+
- @backstage/backend-app-api@0.8.0
|
|
19
|
+
- @backstage/plugin-events-node@0.3.8
|
|
20
|
+
- @backstage/plugin-auth-node@0.4.17
|
|
21
|
+
- @backstage/config@1.2.0
|
|
22
|
+
- @backstage/errors@1.2.4
|
|
23
|
+
- @backstage/types@1.1.1
|
|
24
|
+
|
|
3
25
|
## 0.4.4-next.1
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
package/dist/index.cjs.js
CHANGED
|
@@ -44,10 +44,23 @@ var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
|
44
44
|
var textextensions__default = /*#__PURE__*/_interopDefaultCompat(textextensions);
|
|
45
45
|
var express__default = /*#__PURE__*/_interopDefaultCompat(express);
|
|
46
46
|
|
|
47
|
-
function
|
|
47
|
+
function registerMswTestHooks(worker) {
|
|
48
|
+
beforeAll(() => worker.listen({ onUnhandledRequest: "error" }));
|
|
49
|
+
afterAll(() => worker.close());
|
|
50
|
+
afterEach(() => worker.resetHandlers());
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function isDockerDisabledForTests$1() {
|
|
48
54
|
return Boolean(process.env.BACKSTAGE_TEST_DISABLE_DOCKER) || !Boolean(process.env.CI);
|
|
49
55
|
}
|
|
50
56
|
|
|
57
|
+
function setupRequestMockHandlers(worker) {
|
|
58
|
+
registerMswTestHooks(worker);
|
|
59
|
+
}
|
|
60
|
+
function isDockerDisabledForTests() {
|
|
61
|
+
return isDockerDisabledForTests$1();
|
|
62
|
+
}
|
|
63
|
+
|
|
51
64
|
async function attemptMemcachedConnection(connection) {
|
|
52
65
|
const startTime = Date.now();
|
|
53
66
|
for (; ; ) {
|
|
@@ -183,7 +196,7 @@ class TestCaches {
|
|
|
183
196
|
*/
|
|
184
197
|
static create(options) {
|
|
185
198
|
const ids = options?.ids;
|
|
186
|
-
const disableDocker = options?.disableDocker ?? isDockerDisabledForTests();
|
|
199
|
+
const disableDocker = options?.disableDocker ?? isDockerDisabledForTests$1();
|
|
187
200
|
let testCacheIds;
|
|
188
201
|
if (ids) {
|
|
189
202
|
testCacheIds = ids;
|
|
@@ -720,7 +733,7 @@ class TestDatabases {
|
|
|
720
733
|
*/
|
|
721
734
|
static create(options) {
|
|
722
735
|
const ids = options?.ids;
|
|
723
|
-
const disableDocker = options?.disableDocker ?? isDockerDisabledForTests();
|
|
736
|
+
const disableDocker = options?.disableDocker ?? isDockerDisabledForTests$1();
|
|
724
737
|
let testDatabaseIds;
|
|
725
738
|
if (ids) {
|
|
726
739
|
testDatabaseIds = ids;
|
|
@@ -814,12 +827,6 @@ class TestDatabases {
|
|
|
814
827
|
}
|
|
815
828
|
}
|
|
816
829
|
|
|
817
|
-
function setupRequestMockHandlers(worker) {
|
|
818
|
-
beforeAll(() => worker.listen({ onUnhandledRequest: "error" }));
|
|
819
|
-
afterAll(() => worker.close());
|
|
820
|
-
afterEach(() => worker.resetHandlers());
|
|
821
|
-
}
|
|
822
|
-
|
|
823
830
|
const tmpdirMarker = Symbol("os-tmpdir-mock");
|
|
824
831
|
class MockDirectoryImpl {
|
|
825
832
|
#root;
|
|
@@ -1358,14 +1365,18 @@ function createLoggerMock() {
|
|
|
1358
1365
|
warn: jest.fn()
|
|
1359
1366
|
};
|
|
1360
1367
|
}
|
|
1361
|
-
function
|
|
1362
|
-
|
|
1368
|
+
function simpleFactoryWithOptions(ref, factory) {
|
|
1369
|
+
const factoryWithOptions = (...options) => backendPluginApi.createServiceFactory({
|
|
1363
1370
|
service: ref,
|
|
1364
1371
|
deps: {},
|
|
1365
1372
|
async factory() {
|
|
1366
|
-
return factory(options);
|
|
1373
|
+
return factory(...options);
|
|
1367
1374
|
}
|
|
1368
|
-
}));
|
|
1375
|
+
})();
|
|
1376
|
+
return Object.assign(
|
|
1377
|
+
factoryWithOptions,
|
|
1378
|
+
factoryWithOptions(...[void 0])
|
|
1379
|
+
);
|
|
1369
1380
|
}
|
|
1370
1381
|
function simpleMock(ref, mockFactory) {
|
|
1371
1382
|
return (partialImpl) => {
|
|
@@ -1395,14 +1406,20 @@ exports.mockServices = void 0;
|
|
|
1395
1406
|
}
|
|
1396
1407
|
mockServices2.rootConfig = rootConfig;
|
|
1397
1408
|
((rootConfig2) => {
|
|
1398
|
-
rootConfig2.factory =
|
|
1409
|
+
rootConfig2.factory = simpleFactoryWithOptions(
|
|
1410
|
+
backendPluginApi.coreServices.rootConfig,
|
|
1411
|
+
rootConfig2
|
|
1412
|
+
);
|
|
1399
1413
|
})(rootConfig = mockServices2.rootConfig || (mockServices2.rootConfig = {}));
|
|
1400
1414
|
function rootLogger(options) {
|
|
1401
1415
|
return MockRootLoggerService.create(options);
|
|
1402
1416
|
}
|
|
1403
1417
|
mockServices2.rootLogger = rootLogger;
|
|
1404
1418
|
((rootLogger2) => {
|
|
1405
|
-
rootLogger2.factory =
|
|
1419
|
+
rootLogger2.factory = simpleFactoryWithOptions(
|
|
1420
|
+
backendPluginApi.coreServices.rootLogger,
|
|
1421
|
+
rootLogger2
|
|
1422
|
+
);
|
|
1406
1423
|
rootLogger2.mock = simpleMock(backendPluginApi.coreServices.rootLogger, () => ({
|
|
1407
1424
|
child: jest.fn(),
|
|
1408
1425
|
debug: jest.fn(),
|
|
@@ -1425,10 +1442,11 @@ exports.mockServices = void 0;
|
|
|
1425
1442
|
}
|
|
1426
1443
|
mockServices2.tokenManager = tokenManager;
|
|
1427
1444
|
((tokenManager2) => {
|
|
1428
|
-
tokenManager2.factory =
|
|
1429
|
-
backendPluginApi.coreServices.tokenManager,
|
|
1430
|
-
|
|
1431
|
-
|
|
1445
|
+
tokenManager2.factory = backendPluginApi.createServiceFactory({
|
|
1446
|
+
service: backendPluginApi.coreServices.tokenManager,
|
|
1447
|
+
deps: {},
|
|
1448
|
+
factory: () => tokenManager2()
|
|
1449
|
+
});
|
|
1432
1450
|
tokenManager2.mock = simpleMock(backendPluginApi.coreServices.tokenManager, () => ({
|
|
1433
1451
|
authenticate: jest.fn(),
|
|
1434
1452
|
getToken: jest.fn()
|
|
@@ -1439,7 +1457,11 @@ exports.mockServices = void 0;
|
|
|
1439
1457
|
}
|
|
1440
1458
|
mockServices2.identity = identity;
|
|
1441
1459
|
((identity2) => {
|
|
1442
|
-
identity2.factory =
|
|
1460
|
+
identity2.factory = backendPluginApi.createServiceFactory({
|
|
1461
|
+
service: backendPluginApi.coreServices.identity,
|
|
1462
|
+
deps: {},
|
|
1463
|
+
factory: () => identity2()
|
|
1464
|
+
});
|
|
1443
1465
|
identity2.mock = simpleMock(backendPluginApi.coreServices.identity, () => ({
|
|
1444
1466
|
getIdentity: jest.fn()
|
|
1445
1467
|
}));
|
|
@@ -1507,15 +1529,17 @@ exports.mockServices = void 0;
|
|
|
1507
1529
|
}
|
|
1508
1530
|
mockServices2.httpAuth = httpAuth;
|
|
1509
1531
|
((httpAuth2) => {
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1532
|
+
const factoryWithOptions = (options) => backendPluginApi.createServiceFactory({
|
|
1533
|
+
service: backendPluginApi.coreServices.httpAuth,
|
|
1534
|
+
deps: { plugin: backendPluginApi.coreServices.pluginMetadata },
|
|
1535
|
+
factory: ({ plugin }) => new MockHttpAuthService(
|
|
1536
|
+
plugin.getId(),
|
|
1537
|
+
options?.defaultCredentials ?? exports.mockCredentials.user()
|
|
1538
|
+
)
|
|
1539
|
+
})();
|
|
1540
|
+
httpAuth2.factory = Object.assign(
|
|
1541
|
+
factoryWithOptions,
|
|
1542
|
+
factoryWithOptions()
|
|
1519
1543
|
);
|
|
1520
1544
|
httpAuth2.mock = simpleMock(backendPluginApi.coreServices.httpAuth, () => ({
|
|
1521
1545
|
credentials: jest.fn(),
|
|
@@ -2047,13 +2071,13 @@ function toInternalServiceFactory(factory) {
|
|
|
2047
2071
|
}
|
|
2048
2072
|
return f;
|
|
2049
2073
|
}
|
|
2050
|
-
|
|
2051
|
-
|
|
2074
|
+
function createPluginMetadataServiceFactory(pluginId) {
|
|
2075
|
+
return backendPluginApi.createServiceFactory({
|
|
2052
2076
|
service: backendPluginApi.coreServices.pluginMetadata,
|
|
2053
2077
|
deps: {},
|
|
2054
|
-
factory: async () => ({ getId: () =>
|
|
2055
|
-
})
|
|
2056
|
-
|
|
2078
|
+
factory: async () => ({ getId: () => pluginId })
|
|
2079
|
+
});
|
|
2080
|
+
}
|
|
2057
2081
|
class ServiceRegistry {
|
|
2058
2082
|
static create(factories) {
|
|
2059
2083
|
const registry = new ServiceRegistry(factories);
|
|
@@ -2076,7 +2100,7 @@ class ServiceRegistry {
|
|
|
2076
2100
|
#resolveFactory(ref, pluginId) {
|
|
2077
2101
|
if (ref.id === backendPluginApi.coreServices.pluginMetadata.id) {
|
|
2078
2102
|
return Promise.resolve(
|
|
2079
|
-
toInternalServiceFactory(
|
|
2103
|
+
toInternalServiceFactory(createPluginMetadataServiceFactory(pluginId))
|
|
2080
2104
|
);
|
|
2081
2105
|
}
|
|
2082
2106
|
let resolvedFactory = this.#providedFactories.get(ref.id);
|
|
@@ -2249,20 +2273,25 @@ class ServiceFactoryTester {
|
|
|
2249
2273
|
* @returns A new tester instance for the provided subject.
|
|
2250
2274
|
*/
|
|
2251
2275
|
static from(subject, options) {
|
|
2252
|
-
const subjectFactory = typeof subject === "function" ? subject() : subject;
|
|
2253
2276
|
const registry = ServiceRegistry.create([
|
|
2254
2277
|
...defaultServiceFactories,
|
|
2255
|
-
...options?.dependencies
|
|
2256
|
-
|
|
2257
|
-
) ?? [],
|
|
2258
|
-
subjectFactory
|
|
2278
|
+
...options?.dependencies ?? [],
|
|
2279
|
+
subject
|
|
2259
2280
|
]);
|
|
2260
|
-
return new ServiceFactoryTester(
|
|
2281
|
+
return new ServiceFactoryTester(subject.service, registry);
|
|
2261
2282
|
}
|
|
2262
2283
|
constructor(subject, registry) {
|
|
2263
2284
|
this.#subject = subject;
|
|
2264
2285
|
this.#registry = registry;
|
|
2265
2286
|
}
|
|
2287
|
+
/**
|
|
2288
|
+
* Returns the service instance for the subject.
|
|
2289
|
+
*
|
|
2290
|
+
* @deprecated Use `getSubject` instead.
|
|
2291
|
+
*/
|
|
2292
|
+
async get(...args) {
|
|
2293
|
+
return this.getSubject(...args);
|
|
2294
|
+
}
|
|
2266
2295
|
/**
|
|
2267
2296
|
* Returns the service instance for the subject.
|
|
2268
2297
|
*
|
|
@@ -2273,7 +2302,7 @@ class ServiceFactoryTester {
|
|
|
2273
2302
|
*
|
|
2274
2303
|
* By default the plugin ID 'test' is used.
|
|
2275
2304
|
*/
|
|
2276
|
-
async
|
|
2305
|
+
async getSubject(...args) {
|
|
2277
2306
|
const [pluginId] = args;
|
|
2278
2307
|
return this.#registry.get(this.#subject, pluginId ?? "test");
|
|
2279
2308
|
}
|
|
@@ -2299,6 +2328,7 @@ exports.TestCaches = TestCaches;
|
|
|
2299
2328
|
exports.TestDatabases = TestDatabases;
|
|
2300
2329
|
exports.createMockDirectory = createMockDirectory;
|
|
2301
2330
|
exports.isDockerDisabledForTests = isDockerDisabledForTests;
|
|
2331
|
+
exports.registerMswTestHooks = registerMswTestHooks;
|
|
2302
2332
|
exports.setupRequestMockHandlers = setupRequestMockHandlers;
|
|
2303
2333
|
exports.startTestBackend = startTestBackend;
|
|
2304
2334
|
//# sourceMappingURL=index.cjs.js.map
|