Merge pull request #15530 from backstage/blam/add-mocks-test-backend
Add all `coreServices` to `startTestBackend`
This commit is contained in:
@@ -56,7 +56,6 @@
|
||||
"@backstage/cli": "workspace:^",
|
||||
"@backstage/types": "workspace:^",
|
||||
"@types/supertest": "^2.0.8",
|
||||
"get-port": "^6.1.2",
|
||||
"mock-fs": "^5.1.0",
|
||||
"msw": "^0.49.0",
|
||||
"node-fetch": "^2.6.7",
|
||||
|
||||
@@ -17,18 +17,14 @@
|
||||
import mockFs from 'mock-fs';
|
||||
import { resolve as resolvePath } from 'path';
|
||||
import fetch from 'node-fetch';
|
||||
import { coreServices } from '@backstage/backend-plugin-api';
|
||||
import { startTestBackend } from '@backstage/backend-test-utils';
|
||||
import { appPlugin } from './appPlugin';
|
||||
import {
|
||||
databaseFactory,
|
||||
httpRouterFactory,
|
||||
rootHttpRouterFactory,
|
||||
loggerFactory,
|
||||
rootLoggerFactory,
|
||||
} from '@backstage/backend-app-api';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import getPort from 'get-port';
|
||||
|
||||
describe('appPlugin', () => {
|
||||
beforeEach(() => {
|
||||
@@ -48,23 +44,12 @@ describe('appPlugin', () => {
|
||||
});
|
||||
|
||||
it('boots', async () => {
|
||||
const port = await getPort();
|
||||
await startTestBackend({
|
||||
const { server } = await startTestBackend({
|
||||
services: [
|
||||
[
|
||||
coreServices.config,
|
||||
new ConfigReader({
|
||||
backend: {
|
||||
listen: { port },
|
||||
database: { client: 'better-sqlite3', connection: ':memory:' },
|
||||
},
|
||||
}),
|
||||
],
|
||||
loggerFactory(),
|
||||
rootLoggerFactory(),
|
||||
databaseFactory(),
|
||||
httpRouterFactory(),
|
||||
rootHttpRouterFactory(),
|
||||
],
|
||||
features: [
|
||||
appPlugin({
|
||||
@@ -75,12 +60,12 @@ describe('appPlugin', () => {
|
||||
});
|
||||
|
||||
await expect(
|
||||
fetch(`http://localhost:${port}/api/app/derp.html`).then(res =>
|
||||
fetch(`http://localhost:${server.port()}/api/app/derp.html`).then(res =>
|
||||
res.text(),
|
||||
),
|
||||
).resolves.toBe('winning');
|
||||
await expect(
|
||||
fetch(`http://localhost:${port}`).then(res => res.text()),
|
||||
fetch(`http://localhost:${server.port()}`).then(res => res.text()),
|
||||
).resolves.toBe('winning');
|
||||
});
|
||||
});
|
||||
|
||||
+19
-27
@@ -14,18 +14,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import {
|
||||
getVoidLogger,
|
||||
PluginEndpointDiscovery,
|
||||
TokenManager,
|
||||
} from '@backstage/backend-common';
|
||||
import { coreServices } from '@backstage/backend-plugin-api';
|
||||
import {
|
||||
PluginTaskScheduler,
|
||||
TaskScheduleDefinition,
|
||||
} from '@backstage/backend-tasks';
|
||||
import { startTestBackend } from '@backstage/backend-test-utils';
|
||||
import {
|
||||
startTestBackend,
|
||||
mockConfigFactory,
|
||||
} from '@backstage/backend-test-utils';
|
||||
import { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node';
|
||||
import { eventsExtensionPoint } from '@backstage/plugin-events-node';
|
||||
import { Duration } from 'luxon';
|
||||
@@ -55,22 +52,6 @@ describe('bitbucketCloudEntityProviderCatalogModule', () => {
|
||||
return runner;
|
||||
},
|
||||
} as unknown as PluginTaskScheduler;
|
||||
const discovery = jest.fn() as any as PluginEndpointDiscovery;
|
||||
const tokenManager = jest.fn() as any as TokenManager;
|
||||
|
||||
const config = new ConfigReader({
|
||||
catalog: {
|
||||
providers: {
|
||||
bitbucketCloud: {
|
||||
schedule: {
|
||||
frequency: 'P1M',
|
||||
timeout: 'PT3M',
|
||||
},
|
||||
workspace: 'test-ws',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await startTestBackend({
|
||||
extensionPoints: [
|
||||
@@ -78,11 +59,22 @@ describe('bitbucketCloudEntityProviderCatalogModule', () => {
|
||||
[eventsExtensionPoint, eventsExtensionPointImpl],
|
||||
],
|
||||
services: [
|
||||
[coreServices.config, config],
|
||||
[coreServices.discovery, discovery],
|
||||
[coreServices.logger, getVoidLogger()],
|
||||
mockConfigFactory({
|
||||
data: {
|
||||
catalog: {
|
||||
providers: {
|
||||
bitbucketCloud: {
|
||||
schedule: {
|
||||
frequency: 'P1M',
|
||||
timeout: 'PT3M',
|
||||
},
|
||||
workspace: 'test-ws',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
[coreServices.scheduler, scheduler],
|
||||
[coreServices.tokenManager, tokenManager],
|
||||
],
|
||||
features: [bitbucketCloudEntityProviderCatalogModule()],
|
||||
});
|
||||
|
||||
@@ -56,8 +56,7 @@
|
||||
"devDependencies": {
|
||||
"@backstage/backend-app-api": "workspace:^",
|
||||
"@backstage/cli": "workspace:^",
|
||||
"@backstage/plugin-catalog-backend": "workspace:^",
|
||||
"get-port": "^6.1.2"
|
||||
"@backstage/plugin-catalog-backend": "workspace:^"
|
||||
},
|
||||
"files": [
|
||||
"alpha",
|
||||
|
||||
@@ -14,11 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { PluginEndpointDiscovery } from '@backstage/backend-common';
|
||||
import {
|
||||
createBackendModule,
|
||||
coreServices,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { createBackendModule } from '@backstage/backend-plugin-api';
|
||||
import { startTestBackend } from '@backstage/backend-test-utils';
|
||||
import { CatalogClient } from '@backstage/catalog-client';
|
||||
import { catalogServiceRef } from './catalogService';
|
||||
@@ -42,9 +38,6 @@ describe('catalogServiceRef', () => {
|
||||
});
|
||||
|
||||
await startTestBackend({
|
||||
services: [
|
||||
[coreServices.discovery, {} as unknown as PluginEndpointDiscovery],
|
||||
],
|
||||
features: [testModule()],
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user