make the backend plugin ts files consistent

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2022-03-13 17:32:13 +01:00
parent 86de5e8d61
commit 89c7e47967
54 changed files with 507 additions and 486 deletions
+7 -2
View File
@@ -76,9 +76,12 @@ following to it
```ts
import { createRouter } from '@internal/plugin-carmen-backend';
import { Router } from 'express';
import { PluginEnvironment } from '../types';
export default async function createPlugin(env: PluginEnvironment) {
export default async function createPlugin(
env: PluginEnvironment,
): Promise<Router> {
// Here is where you will add all of the required initialization code that
// your backend plugin needs to be able to start!
@@ -124,7 +127,9 @@ function, there is a `database` field. You can use that to get a
```ts
// in packages/backend/src/plugins/carmen.ts
export default async function createPlugin(env: PluginEnvironment) {
export default async function createPlugin(
env: PluginEnvironment,
): Promise<Router> {
const db: Knex<any, unknown[]> = await env.database.getClient();
// You will then pass this client into your actual plugin implementation
+7 -7
View File
@@ -192,7 +192,7 @@ returns a result or displays an error or console message, like so:
**`StringUtil ellipsis`**
```js
```ts
export function ellipsis(text, maxLength, midCharIx = 0, ellipsis = '...') {
// Do something blackbox. We should not care about the internals,
// only inputs and outputs.
@@ -210,7 +210,7 @@ There are four things to test for in a utility function:
> Handle Invalid Input (handle thrown errors):
```js
```ts
it('Throws an error on improper arguments', () => {
expect(() => {
ellipsis();
@@ -220,7 +220,7 @@ it('Throws an error on improper arguments', () => {
> Verify default input arguments:
```js
```ts
it('Works with defaults', () => {
expect(ellipsis('Hello world', 3)).toBe('Hel...');
expect(ellipsis('', 3)).toBe('');
@@ -233,7 +233,7 @@ it('Works with defaults', () => {
This is especially true for edge cases!
```js
```ts
it('Works with midCharIx', () => {
expect(ellipsis('Hello world', 3, 6)).toBe('...o w...');
expect(ellipsis('', 3, 6)).toBe('');
@@ -265,7 +265,7 @@ For example:
**`./MyApi.js`**
```js
```ts
export {
fetchSomethingFromServer: () => {
// Live production call to a URI. Must be avoided during testing!
@@ -276,7 +276,7 @@ export {
**`./__mocks__/MyApi.js`**
```js
```ts
export {
fetchSomethingFromServer: () => {
// Simulate a production call, but avoid jest and just use a promise
@@ -287,7 +287,7 @@ export {
**`./MyApi.test.js`**
```js
```ts
/* eslint-disable import/first */
jest.mock('./MyApi'); // Instruct Jest to swap all future imports of './MyApi.js' to './__mocks__/MyApi.js'
+1 -1
View File
@@ -44,7 +44,7 @@ import { URLReaders } from '@backstage/backend-common';
function makeCreateEnv(config: Config) {
// ....
const reader = UrlReaders.default({ logger, config });
const reader = UrlReaders.default({ logger: root, config });
//
}
```