From 709a7352b21da89f0b0a654ea38ceb1043517b3d Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 22 Jul 2020 14:51:15 +0200 Subject: [PATCH 01/25] chore(cli): create backend plugin start --- .../default-backend-plugin/.eslintrc.js | 3 + .../default-backend-plugin/README.md.hbs | 13 +++ .../default-backend-plugin/dev/index.tsx | 20 ++++ .../default-backend-plugin/package.json.hbs | 46 ++++++++ .../ExampleComponent.test.tsx.hbs | 34 ++++++ .../ExampleComponent/ExampleComponent.tsx.hbs | 57 +++++++++ .../src/components/ExampleComponent/index.ts | 17 +++ .../ExampleFetchComponent.test.tsx.hbs | 28 +++++ .../ExampleFetchComponent.tsx.hbs | 108 ++++++++++++++++++ .../components/ExampleFetchComponent/index.ts | 17 +++ .../default-backend-plugin/src/index.ts | 17 +++ .../src/plugin.test.ts.hbs | 23 ++++ .../default-backend-plugin/src/plugin.ts.hbs | 30 +++++ .../default-backend-plugin/src/setupTests.ts | 19 +++ 14 files changed, 432 insertions(+) create mode 100644 packages/cli/templates/default-backend-plugin/.eslintrc.js create mode 100644 packages/cli/templates/default-backend-plugin/README.md.hbs create mode 100644 packages/cli/templates/default-backend-plugin/dev/index.tsx create mode 100644 packages/cli/templates/default-backend-plugin/package.json.hbs create mode 100644 packages/cli/templates/default-backend-plugin/src/components/ExampleComponent/ExampleComponent.test.tsx.hbs create mode 100644 packages/cli/templates/default-backend-plugin/src/components/ExampleComponent/ExampleComponent.tsx.hbs create mode 100644 packages/cli/templates/default-backend-plugin/src/components/ExampleComponent/index.ts create mode 100644 packages/cli/templates/default-backend-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs create mode 100644 packages/cli/templates/default-backend-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.tsx.hbs create mode 100644 packages/cli/templates/default-backend-plugin/src/components/ExampleFetchComponent/index.ts create mode 100644 packages/cli/templates/default-backend-plugin/src/index.ts create mode 100644 packages/cli/templates/default-backend-plugin/src/plugin.test.ts.hbs create mode 100644 packages/cli/templates/default-backend-plugin/src/plugin.ts.hbs create mode 100644 packages/cli/templates/default-backend-plugin/src/setupTests.ts diff --git a/packages/cli/templates/default-backend-plugin/.eslintrc.js b/packages/cli/templates/default-backend-plugin/.eslintrc.js new file mode 100644 index 0000000000..13573efa9c --- /dev/null +++ b/packages/cli/templates/default-backend-plugin/.eslintrc.js @@ -0,0 +1,3 @@ +module.exports = { + extends: [require.resolve('@backstage/cli/config/eslint')], +}; diff --git a/packages/cli/templates/default-backend-plugin/README.md.hbs b/packages/cli/templates/default-backend-plugin/README.md.hbs new file mode 100644 index 0000000000..d6f2d65134 --- /dev/null +++ b/packages/cli/templates/default-backend-plugin/README.md.hbs @@ -0,0 +1,13 @@ +# {{id}} + +Welcome to the {{id}} plugin! + +_This plugin was created through the Backstage CLI_ + +## Getting started + +Your plugin has been added to the example app in this repository, meaning you'll be able to access it by running `yarn start` in the root directory, and then navigating to [/{{id}}](http://localhost:3000/{{id}}). + +You can also serve the plugin in isolation by running `yarn start` in the plugin directory. +This method of serving the plugin provides quicker iteration speed and a faster startup and hot reloads. +It is only meant for local development, and the setup for it can be found inside the [/dev](/dev) directory. diff --git a/packages/cli/templates/default-backend-plugin/dev/index.tsx b/packages/cli/templates/default-backend-plugin/dev/index.tsx new file mode 100644 index 0000000000..812a5585d4 --- /dev/null +++ b/packages/cli/templates/default-backend-plugin/dev/index.tsx @@ -0,0 +1,20 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { createDevApp } from '@backstage/dev-utils'; +import { plugin } from '../src/plugin'; + +createDevApp().registerPlugin(plugin).render(); diff --git a/packages/cli/templates/default-backend-plugin/package.json.hbs b/packages/cli/templates/default-backend-plugin/package.json.hbs new file mode 100644 index 0000000000..c0ba6676c5 --- /dev/null +++ b/packages/cli/templates/default-backend-plugin/package.json.hbs @@ -0,0 +1,46 @@ +{ +"name": "@backstage/plugin-{{id}}", +"version": "{{version}}", +"main": "src/index.ts", +"types": "src/index.ts", +"license": "Apache-2.0", +"private": true, +"publishConfig": { +"access": "public", +"main": "dist/index.esm.js", +"types": "dist/index.d.ts" +}, +"scripts": { +"build": "backstage-cli backend:build", +"start": "backstage-cli plugin:serve", +"lint": "backstage-cli lint", +"test": "backstage-cli test", +"diff": "backstage-cli plugin:diff", +"prepack": "backstage-cli prepack", +"postpack": "backstage-cli postpack", +"clean": "backstage-cli clean" +}, +"dependencies": { +"@backstage/core": "^{{version}}", +"@backstage/theme": "^{{version}}", +"@material-ui/core": "^4.9.1", +"@material-ui/icons": "^4.9.1", +"@material-ui/lab": "4.0.0-alpha.45", +"react": "^16.13.1", +"react-dom": "^16.13.1", +"react-use": "^14.2.0" +}, +"devDependencies": { +"@backstage/cli": "^{{version}}", +"@backstage/dev-utils": "^{{version}}", +"@testing-library/jest-dom": "^5.10.1", +"@testing-library/react": "^10.4.1", +"@testing-library/user-event": "^12.0.7", +"@types/jest": "^25.2.2", +"@types/node": "^12.0.0", +"jest-fetch-mock": "^3.0.3" +}, +"files": [ +"dist" +] +} diff --git a/packages/cli/templates/default-backend-plugin/src/components/ExampleComponent/ExampleComponent.test.tsx.hbs b/packages/cli/templates/default-backend-plugin/src/components/ExampleComponent/ExampleComponent.test.tsx.hbs new file mode 100644 index 0000000000..dff57e66a4 --- /dev/null +++ b/packages/cli/templates/default-backend-plugin/src/components/ExampleComponent/ExampleComponent.test.tsx.hbs @@ -0,0 +1,34 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import React from 'react'; +import { render } from '@testing-library/react'; +import mockFetch from 'jest-fetch-mock'; +import ExampleComponent from './ExampleComponent'; +import { ThemeProvider } from '@material-ui/core'; +import { lightTheme } from '@backstage/theme'; + +describe('ExampleComponent', () => { + it('should render', () => { + mockFetch.mockResponse(() => new Promise(() => {})); + const rendered = render( + + + , + ); + expect(rendered.getByText('Welcome to {{ id }}!')).toBeInTheDocument(); + }); +}); diff --git a/packages/cli/templates/default-backend-plugin/src/components/ExampleComponent/ExampleComponent.tsx.hbs b/packages/cli/templates/default-backend-plugin/src/components/ExampleComponent/ExampleComponent.tsx.hbs new file mode 100644 index 0000000000..34e37f3e7b --- /dev/null +++ b/packages/cli/templates/default-backend-plugin/src/components/ExampleComponent/ExampleComponent.tsx.hbs @@ -0,0 +1,57 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import React, { FC } from 'react'; +import { Typography, Grid } from '@material-ui/core'; +import { + InfoCard, + Header, + Page, + pageTheme, + Content, + ContentHeader, + HeaderLabel, + SupportButton, +} from '@backstage/core'; +import ExampleFetchComponent from '../ExampleFetchComponent'; + +const ExampleComponent: FC<{}> = () => ( + +
+ + +
+ + + A description of your plugin goes here. + + + + + + All content should be wrapped in a card like this. + + + + + + + + +
+); + +export default ExampleComponent; diff --git a/packages/cli/templates/default-backend-plugin/src/components/ExampleComponent/index.ts b/packages/cli/templates/default-backend-plugin/src/components/ExampleComponent/index.ts new file mode 100644 index 0000000000..e785d45082 --- /dev/null +++ b/packages/cli/templates/default-backend-plugin/src/components/ExampleComponent/index.ts @@ -0,0 +1,17 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export { default } from './ExampleComponent'; diff --git a/packages/cli/templates/default-backend-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs b/packages/cli/templates/default-backend-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs new file mode 100644 index 0000000000..7fecdc6f11 --- /dev/null +++ b/packages/cli/templates/default-backend-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs @@ -0,0 +1,28 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import React from 'react'; +import { render } from '@testing-library/react'; +import mockFetch from 'jest-fetch-mock'; +import ExampleFetchComponent from './ExampleFetchComponent'; + +describe('ExampleFetchComponent', () => { + it('should render', async () => { + mockFetch.mockResponse(() => new Promise(() => {})); + const rendered = render(); + expect(await rendered.findByTestId('progress')).toBeInTheDocument(); + }); +}); diff --git a/packages/cli/templates/default-backend-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.tsx.hbs b/packages/cli/templates/default-backend-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.tsx.hbs new file mode 100644 index 0000000000..2dd54f726e --- /dev/null +++ b/packages/cli/templates/default-backend-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.tsx.hbs @@ -0,0 +1,108 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import React, { FC } from 'react'; +import { makeStyles } from '@material-ui/core/styles'; +import { Table, TableColumn, Progress } from '@backstage/core'; +import Alert from '@material-ui/lab/Alert'; +import { useAsync } from 'react-use'; + +const useStyles = makeStyles({ + avatar: { + height: 32, + width: 32, + borderRadius: '50%', + }, +}); + +type User = { + gender: string; // "male" + name: { + title: string; // "Mr", + first: string; // "Duane", + last: string; // "Reed" + }; + location: object; // {street: {number: 5060, name: "Hickory Creek Dr"}, city: "Albany", state: "New South Wales",…} + email: string; // "duane.reed@example.com" + login: object; // {uuid: "4b785022-9a23-4ab9-8a23-cb3fb43969a9", username: "blackdog796", password: "patch",…} + dob: object; // {date: "1983-06-22T12:30:23.016Z", age: 37} + registered: object; // {date: "2006-06-13T18:48:28.037Z", age: 14} + phone: string; // "07-2154-5651" + cell: string; // "0405-592-879" + id: { + name: string; // "TFN", + value: string; // "796260432" + }; + picture: { medium: string }; // {medium: "https://randomuser.me/api/portraits/men/95.jpg",…} + nat: string; // "AU" +}; + +type DenseTableProps = { + users: User[]; +}; + +export const DenseTable: FC = ({ users }) => { + const classes = useStyles(); + + const columns: TableColumn[] = [ + { title: 'Avatar', field: 'avatar' }, + { title: 'Name', field: 'name' }, + { title: 'Email', field: 'email' }, + { title: 'Nationality', field: 'nationality' }, + ]; + + const data = users.map((user) => { + return { + avatar: ( + {user.name.first} + ), + name: `${user.name.first} ${user.name.last}`, + email: user.email, + nationality: user.nat, + }; + }); + + return ( + + ); +}; + +const ExampleFetchComponent: FC<{}> = () => { + const { value, loading, error } = useAsync(async (): Promise => { + const response = await fetch('https://randomuser.me/api/?results=20'); + const data = await response.json(); + return data.results; + }, []); + + if (loading) { + return ; + } else if (error) { + return {error.message}; + } + + return ; +}; + +export default ExampleFetchComponent; diff --git a/packages/cli/templates/default-backend-plugin/src/components/ExampleFetchComponent/index.ts b/packages/cli/templates/default-backend-plugin/src/components/ExampleFetchComponent/index.ts new file mode 100644 index 0000000000..28482f9fe1 --- /dev/null +++ b/packages/cli/templates/default-backend-plugin/src/components/ExampleFetchComponent/index.ts @@ -0,0 +1,17 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export { default } from './ExampleFetchComponent'; diff --git a/packages/cli/templates/default-backend-plugin/src/index.ts b/packages/cli/templates/default-backend-plugin/src/index.ts new file mode 100644 index 0000000000..3a0a0fe2d3 --- /dev/null +++ b/packages/cli/templates/default-backend-plugin/src/index.ts @@ -0,0 +1,17 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export { plugin } from './plugin'; diff --git a/packages/cli/templates/default-backend-plugin/src/plugin.test.ts.hbs b/packages/cli/templates/default-backend-plugin/src/plugin.test.ts.hbs new file mode 100644 index 0000000000..e34204c9ae --- /dev/null +++ b/packages/cli/templates/default-backend-plugin/src/plugin.test.ts.hbs @@ -0,0 +1,23 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { plugin } from './plugin'; + +describe('{{ id }}', () => { + it('should export plugin', () => { + expect(plugin).toBeDefined(); + }); +}); diff --git a/packages/cli/templates/default-backend-plugin/src/plugin.ts.hbs b/packages/cli/templates/default-backend-plugin/src/plugin.ts.hbs new file mode 100644 index 0000000000..ad5db2e711 --- /dev/null +++ b/packages/cli/templates/default-backend-plugin/src/plugin.ts.hbs @@ -0,0 +1,30 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { createPlugin, createRouteRef } from '@backstage/core'; +import ExampleComponent from './components/ExampleComponent'; + +export const rootRouteRef = createRouteRef({ +path: '/{{ id }}', +title: '{{ id }}', +}); + +export const plugin = createPlugin({ +id: '{{ id }}', +register({ router }) { +router.addRoute(rootRouteRef, ExampleComponent); +}, +}); diff --git a/packages/cli/templates/default-backend-plugin/src/setupTests.ts b/packages/cli/templates/default-backend-plugin/src/setupTests.ts new file mode 100644 index 0000000000..8553642152 --- /dev/null +++ b/packages/cli/templates/default-backend-plugin/src/setupTests.ts @@ -0,0 +1,19 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import '@testing-library/jest-dom'; + +require('jest-fetch-mock').enableMocks(); From b468631bc2c2b99d177c8697c988e055c1650b8c Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 22 Jul 2020 15:00:46 +0200 Subject: [PATCH 02/25] chore(cli): starting to move some more boilerplate over --- .../default-backend-plugin/dev/index.tsx | 20 ----- .../default-backend-plugin/package.json.hbs | 79 ++++++++----------- .../scripts/mock-data.sh | 2 + .../templates/default-plugin/package.json.hbs | 2 +- 4 files changed, 38 insertions(+), 65 deletions(-) delete mode 100644 packages/cli/templates/default-backend-plugin/dev/index.tsx create mode 100755 packages/cli/templates/default-backend-plugin/scripts/mock-data.sh diff --git a/packages/cli/templates/default-backend-plugin/dev/index.tsx b/packages/cli/templates/default-backend-plugin/dev/index.tsx deleted file mode 100644 index 812a5585d4..0000000000 --- a/packages/cli/templates/default-backend-plugin/dev/index.tsx +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2020 Spotify AB - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { createDevApp } from '@backstage/dev-utils'; -import { plugin } from '../src/plugin'; - -createDevApp().registerPlugin(plugin).render(); diff --git a/packages/cli/templates/default-backend-plugin/package.json.hbs b/packages/cli/templates/default-backend-plugin/package.json.hbs index c0ba6676c5..51be95a3ba 100644 --- a/packages/cli/templates/default-backend-plugin/package.json.hbs +++ b/packages/cli/templates/default-backend-plugin/package.json.hbs @@ -1,46 +1,37 @@ { -"name": "@backstage/plugin-{{id}}", -"version": "{{version}}", -"main": "src/index.ts", -"types": "src/index.ts", -"license": "Apache-2.0", -"private": true, -"publishConfig": { -"access": "public", -"main": "dist/index.esm.js", -"types": "dist/index.d.ts" -}, -"scripts": { -"build": "backstage-cli backend:build", -"start": "backstage-cli plugin:serve", -"lint": "backstage-cli lint", -"test": "backstage-cli test", -"diff": "backstage-cli plugin:diff", -"prepack": "backstage-cli prepack", -"postpack": "backstage-cli postpack", -"clean": "backstage-cli clean" -}, -"dependencies": { -"@backstage/core": "^{{version}}", -"@backstage/theme": "^{{version}}", -"@material-ui/core": "^4.9.1", -"@material-ui/icons": "^4.9.1", -"@material-ui/lab": "4.0.0-alpha.45", -"react": "^16.13.1", -"react-dom": "^16.13.1", -"react-use": "^14.2.0" -}, -"devDependencies": { -"@backstage/cli": "^{{version}}", -"@backstage/dev-utils": "^{{version}}", -"@testing-library/jest-dom": "^5.10.1", -"@testing-library/react": "^10.4.1", -"@testing-library/user-event": "^12.0.7", -"@types/jest": "^25.2.2", -"@types/node": "^12.0.0", -"jest-fetch-mock": "^3.0.3" -}, -"files": [ -"dist" -] + "name": "@backstage/plugin-{{id}}-backend", + "version": "{{version}}", + "main": "src/index.ts", + "types": "src/index.ts", + "license": "Apache-2.0", + "private": true, + "publishConfig": { + "access": "public", + "main": "dist/index.esm.js", + "types": "dist/index.d.ts" + }, + "scripts": { + "start": "backstage-cli backend:dev", + "build": "backstage-cli backend:build", + "lint": "backstage-cli lint", + "test": "backstage-cli test", + "prepack": "backstage-cli prepack", + "postpack": "backstage-cli postpack", + "clean": "backstage-cli clean", + "mock-data": "./scripts/mock-data.sh" + }, + "dependencies": { + "@backstage/backend-common": "^{{version}}", + "@types/express": "^4.17.6", + "express": "^4.17.1", + "express-promise-router": "^3.0.3" + }, + "devDependencies": { + "@backstage/cli": "^{{version}}", + "@types/supertest": "^2.0.8", + "supertest": "^4.0.2" + }, + "files": [ + "dist" + ] } diff --git a/packages/cli/templates/default-backend-plugin/scripts/mock-data.sh b/packages/cli/templates/default-backend-plugin/scripts/mock-data.sh new file mode 100755 index 0000000000..ff30921715 --- /dev/null +++ b/packages/cli/templates/default-backend-plugin/scripts/mock-data.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +echo "use this script to load your service with some mock data if needed!" diff --git a/packages/cli/templates/default-plugin/package.json.hbs b/packages/cli/templates/default-plugin/package.json.hbs index da611a13b7..b457bc41fe 100644 --- a/packages/cli/templates/default-plugin/package.json.hbs +++ b/packages/cli/templates/default-plugin/package.json.hbs @@ -38,7 +38,7 @@ "@testing-library/user-event": "^12.0.7", "@types/jest": "^25.2.2", "@types/node": "^12.0.0", - "jest-fetch-mock": "^3.0.3" + "msw": "^0.19.5" }, "files": [ "dist" From 1516a0872150b497ab21d66a89cd28008681467f Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 22 Jul 2020 15:32:53 +0200 Subject: [PATCH 03/25] chore(cli): removing some other stuff to make way for more things --- .../ExampleComponent.test.tsx.hbs | 34 ------ .../ExampleComponent/ExampleComponent.tsx.hbs | 57 --------- .../src/components/ExampleComponent/index.ts | 17 --- .../ExampleFetchComponent.test.tsx.hbs | 28 ----- .../ExampleFetchComponent.tsx.hbs | 108 ------------------ .../components/ExampleFetchComponent/index.ts | 17 --- .../default-backend-plugin/src/index.ts | 17 --- .../src/plugin.test.ts.hbs | 23 ---- .../default-backend-plugin/src/plugin.ts.hbs | 30 ----- 9 files changed, 331 deletions(-) delete mode 100644 packages/cli/templates/default-backend-plugin/src/components/ExampleComponent/ExampleComponent.test.tsx.hbs delete mode 100644 packages/cli/templates/default-backend-plugin/src/components/ExampleComponent/ExampleComponent.tsx.hbs delete mode 100644 packages/cli/templates/default-backend-plugin/src/components/ExampleComponent/index.ts delete mode 100644 packages/cli/templates/default-backend-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs delete mode 100644 packages/cli/templates/default-backend-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.tsx.hbs delete mode 100644 packages/cli/templates/default-backend-plugin/src/components/ExampleFetchComponent/index.ts delete mode 100644 packages/cli/templates/default-backend-plugin/src/index.ts delete mode 100644 packages/cli/templates/default-backend-plugin/src/plugin.test.ts.hbs delete mode 100644 packages/cli/templates/default-backend-plugin/src/plugin.ts.hbs diff --git a/packages/cli/templates/default-backend-plugin/src/components/ExampleComponent/ExampleComponent.test.tsx.hbs b/packages/cli/templates/default-backend-plugin/src/components/ExampleComponent/ExampleComponent.test.tsx.hbs deleted file mode 100644 index dff57e66a4..0000000000 --- a/packages/cli/templates/default-backend-plugin/src/components/ExampleComponent/ExampleComponent.test.tsx.hbs +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2020 Spotify AB - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import React from 'react'; -import { render } from '@testing-library/react'; -import mockFetch from 'jest-fetch-mock'; -import ExampleComponent from './ExampleComponent'; -import { ThemeProvider } from '@material-ui/core'; -import { lightTheme } from '@backstage/theme'; - -describe('ExampleComponent', () => { - it('should render', () => { - mockFetch.mockResponse(() => new Promise(() => {})); - const rendered = render( - - - , - ); - expect(rendered.getByText('Welcome to {{ id }}!')).toBeInTheDocument(); - }); -}); diff --git a/packages/cli/templates/default-backend-plugin/src/components/ExampleComponent/ExampleComponent.tsx.hbs b/packages/cli/templates/default-backend-plugin/src/components/ExampleComponent/ExampleComponent.tsx.hbs deleted file mode 100644 index 34e37f3e7b..0000000000 --- a/packages/cli/templates/default-backend-plugin/src/components/ExampleComponent/ExampleComponent.tsx.hbs +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2020 Spotify AB - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import React, { FC } from 'react'; -import { Typography, Grid } from '@material-ui/core'; -import { - InfoCard, - Header, - Page, - pageTheme, - Content, - ContentHeader, - HeaderLabel, - SupportButton, -} from '@backstage/core'; -import ExampleFetchComponent from '../ExampleFetchComponent'; - -const ExampleComponent: FC<{}> = () => ( - -
- - -
- - - A description of your plugin goes here. - - - - - - All content should be wrapped in a card like this. - - - - - - - - -
-); - -export default ExampleComponent; diff --git a/packages/cli/templates/default-backend-plugin/src/components/ExampleComponent/index.ts b/packages/cli/templates/default-backend-plugin/src/components/ExampleComponent/index.ts deleted file mode 100644 index e785d45082..0000000000 --- a/packages/cli/templates/default-backend-plugin/src/components/ExampleComponent/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright 2020 Spotify AB - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export { default } from './ExampleComponent'; diff --git a/packages/cli/templates/default-backend-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs b/packages/cli/templates/default-backend-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs deleted file mode 100644 index 7fecdc6f11..0000000000 --- a/packages/cli/templates/default-backend-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2020 Spotify AB - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import React from 'react'; -import { render } from '@testing-library/react'; -import mockFetch from 'jest-fetch-mock'; -import ExampleFetchComponent from './ExampleFetchComponent'; - -describe('ExampleFetchComponent', () => { - it('should render', async () => { - mockFetch.mockResponse(() => new Promise(() => {})); - const rendered = render(); - expect(await rendered.findByTestId('progress')).toBeInTheDocument(); - }); -}); diff --git a/packages/cli/templates/default-backend-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.tsx.hbs b/packages/cli/templates/default-backend-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.tsx.hbs deleted file mode 100644 index 2dd54f726e..0000000000 --- a/packages/cli/templates/default-backend-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.tsx.hbs +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2020 Spotify AB - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import React, { FC } from 'react'; -import { makeStyles } from '@material-ui/core/styles'; -import { Table, TableColumn, Progress } from '@backstage/core'; -import Alert from '@material-ui/lab/Alert'; -import { useAsync } from 'react-use'; - -const useStyles = makeStyles({ - avatar: { - height: 32, - width: 32, - borderRadius: '50%', - }, -}); - -type User = { - gender: string; // "male" - name: { - title: string; // "Mr", - first: string; // "Duane", - last: string; // "Reed" - }; - location: object; // {street: {number: 5060, name: "Hickory Creek Dr"}, city: "Albany", state: "New South Wales",…} - email: string; // "duane.reed@example.com" - login: object; // {uuid: "4b785022-9a23-4ab9-8a23-cb3fb43969a9", username: "blackdog796", password: "patch",…} - dob: object; // {date: "1983-06-22T12:30:23.016Z", age: 37} - registered: object; // {date: "2006-06-13T18:48:28.037Z", age: 14} - phone: string; // "07-2154-5651" - cell: string; // "0405-592-879" - id: { - name: string; // "TFN", - value: string; // "796260432" - }; - picture: { medium: string }; // {medium: "https://randomuser.me/api/portraits/men/95.jpg",…} - nat: string; // "AU" -}; - -type DenseTableProps = { - users: User[]; -}; - -export const DenseTable: FC = ({ users }) => { - const classes = useStyles(); - - const columns: TableColumn[] = [ - { title: 'Avatar', field: 'avatar' }, - { title: 'Name', field: 'name' }, - { title: 'Email', field: 'email' }, - { title: 'Nationality', field: 'nationality' }, - ]; - - const data = users.map((user) => { - return { - avatar: ( - {user.name.first} - ), - name: `${user.name.first} ${user.name.last}`, - email: user.email, - nationality: user.nat, - }; - }); - - return ( -
- ); -}; - -const ExampleFetchComponent: FC<{}> = () => { - const { value, loading, error } = useAsync(async (): Promise => { - const response = await fetch('https://randomuser.me/api/?results=20'); - const data = await response.json(); - return data.results; - }, []); - - if (loading) { - return ; - } else if (error) { - return {error.message}; - } - - return ; -}; - -export default ExampleFetchComponent; diff --git a/packages/cli/templates/default-backend-plugin/src/components/ExampleFetchComponent/index.ts b/packages/cli/templates/default-backend-plugin/src/components/ExampleFetchComponent/index.ts deleted file mode 100644 index 28482f9fe1..0000000000 --- a/packages/cli/templates/default-backend-plugin/src/components/ExampleFetchComponent/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright 2020 Spotify AB - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export { default } from './ExampleFetchComponent'; diff --git a/packages/cli/templates/default-backend-plugin/src/index.ts b/packages/cli/templates/default-backend-plugin/src/index.ts deleted file mode 100644 index 3a0a0fe2d3..0000000000 --- a/packages/cli/templates/default-backend-plugin/src/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright 2020 Spotify AB - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export { plugin } from './plugin'; diff --git a/packages/cli/templates/default-backend-plugin/src/plugin.test.ts.hbs b/packages/cli/templates/default-backend-plugin/src/plugin.test.ts.hbs deleted file mode 100644 index e34204c9ae..0000000000 --- a/packages/cli/templates/default-backend-plugin/src/plugin.test.ts.hbs +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2020 Spotify AB - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { plugin } from './plugin'; - -describe('{{ id }}', () => { - it('should export plugin', () => { - expect(plugin).toBeDefined(); - }); -}); diff --git a/packages/cli/templates/default-backend-plugin/src/plugin.ts.hbs b/packages/cli/templates/default-backend-plugin/src/plugin.ts.hbs deleted file mode 100644 index ad5db2e711..0000000000 --- a/packages/cli/templates/default-backend-plugin/src/plugin.ts.hbs +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2020 Spotify AB - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { createPlugin, createRouteRef } from '@backstage/core'; -import ExampleComponent from './components/ExampleComponent'; - -export const rootRouteRef = createRouteRef({ -path: '/{{ id }}', -title: '{{ id }}', -}); - -export const plugin = createPlugin({ -id: '{{ id }}', -register({ router }) { -router.addRoute(rootRouteRef, ExampleComponent); -}, -}); From 444b8f768c2a3dc80b0548bf12924cff6052168d Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 23 Jul 2020 10:41:46 +0200 Subject: [PATCH 04/25] chore(cli): finish the template for the backend plugin --- .../default-backend-plugin/README.md.hbs | 5 +- .../default-backend-plugin/package.json.hbs | 7 ++- .../default-backend-plugin/src/index.ts | 17 +++++++ .../default-backend-plugin/src/run.ts.hbs | 33 +++++++++++++ .../src/service/router.test.ts | 45 ++++++++++++++++++ .../src/service/router.ts | 40 ++++++++++++++++ .../src/service/standaloneServer.ts.hbs | 47 +++++++++++++++++++ 7 files changed, 190 insertions(+), 4 deletions(-) create mode 100644 packages/cli/templates/default-backend-plugin/src/index.ts create mode 100644 packages/cli/templates/default-backend-plugin/src/run.ts.hbs create mode 100644 packages/cli/templates/default-backend-plugin/src/service/router.test.ts create mode 100644 packages/cli/templates/default-backend-plugin/src/service/router.ts create mode 100644 packages/cli/templates/default-backend-plugin/src/service/standaloneServer.ts.hbs diff --git a/packages/cli/templates/default-backend-plugin/README.md.hbs b/packages/cli/templates/default-backend-plugin/README.md.hbs index d6f2d65134..5c34b40360 100644 --- a/packages/cli/templates/default-backend-plugin/README.md.hbs +++ b/packages/cli/templates/default-backend-plugin/README.md.hbs @@ -1,12 +1,13 @@ # {{id}} -Welcome to the {{id}} plugin! +Welcome to the {{id}} backend plugin! _This plugin was created through the Backstage CLI_ ## Getting started -Your plugin has been added to the example app in this repository, meaning you'll be able to access it by running `yarn start` in the root directory, and then navigating to [/{{id}}](http://localhost:3000/{{id}}). +Your plugin has been added to the example app in this repository, meaning you'll be able to access it by running `yarn +start` in the root directory, and then navigating to [/{{id}}](http://localhost:3000/{{id}}). You can also serve the plugin in isolation by running `yarn start` in the plugin directory. This method of serving the plugin provides quicker iteration speed and a faster startup and hot reloads. diff --git a/packages/cli/templates/default-backend-plugin/package.json.hbs b/packages/cli/templates/default-backend-plugin/package.json.hbs index 51be95a3ba..4d347107de 100644 --- a/packages/cli/templates/default-backend-plugin/package.json.hbs +++ b/packages/cli/templates/default-backend-plugin/package.json.hbs @@ -24,12 +24,15 @@ "@backstage/backend-common": "^{{version}}", "@types/express": "^4.17.6", "express": "^4.17.1", - "express-promise-router": "^3.0.3" + "express-promise-router": "^3.0.3", + "yn": "^4.0.0", + "whatwg-fetch": "^3.2.0" }, "devDependencies": { "@backstage/cli": "^{{version}}", "@types/supertest": "^2.0.8", - "supertest": "^4.0.2" + "supertest": "^4.0.2", + "msw": "^0.19.5" }, "files": [ "dist" diff --git a/packages/cli/templates/default-backend-plugin/src/index.ts b/packages/cli/templates/default-backend-plugin/src/index.ts new file mode 100644 index 0000000000..7612c392a2 --- /dev/null +++ b/packages/cli/templates/default-backend-plugin/src/index.ts @@ -0,0 +1,17 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export * from './service/router'; diff --git a/packages/cli/templates/default-backend-plugin/src/run.ts.hbs b/packages/cli/templates/default-backend-plugin/src/run.ts.hbs new file mode 100644 index 0000000000..b96989e4b8 --- /dev/null +++ b/packages/cli/templates/default-backend-plugin/src/run.ts.hbs @@ -0,0 +1,33 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { getRootLogger } from '@backstage/backend-common'; +import yn from 'yn'; +import { startStandaloneServer } from './service/standaloneServer'; + +const port = process.env.PLUGIN_PORT ? Number(process.env.PLUGIN_PORT) : 7000; +const enableCors = yn(process.env.PLUGIN_CORS, { default: false }); +const logger = getRootLogger(); + +startStandaloneServer({ port, enableCors, logger }).catch(err => { + logger.error(err); + process.exit(1); +}); + +process.on('SIGINT', () => { + logger.info('CTRL+C pressed; exiting.'); + process.exit(0); +}); diff --git a/packages/cli/templates/default-backend-plugin/src/service/router.test.ts b/packages/cli/templates/default-backend-plugin/src/service/router.test.ts new file mode 100644 index 0000000000..fba6b0ccdf --- /dev/null +++ b/packages/cli/templates/default-backend-plugin/src/service/router.test.ts @@ -0,0 +1,45 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { getVoidLogger } from '@backstage/backend-common'; +import express from 'express'; +import request from 'supertest'; + +import { createRouter } from './router'; + +describe('createRouter', () => { + let app: express.Express; + + beforeAll(async () => { + const router = await createRouter({ + logger: getVoidLogger(), + }); + app = express().use(router); + }); + + beforeEach(() => { + jest.resetAllMocks(); + }); + + describe('GET /ping', () => { + it('returns ok', async () => { + const response = await request(app).get('/ping'); + + expect(response.status).toEqual(200); + expect(response.body).toEqual({ status: 'ok' }); + }); + }); +}); diff --git a/packages/cli/templates/default-backend-plugin/src/service/router.ts b/packages/cli/templates/default-backend-plugin/src/service/router.ts new file mode 100644 index 0000000000..3ea8219365 --- /dev/null +++ b/packages/cli/templates/default-backend-plugin/src/service/router.ts @@ -0,0 +1,40 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { errorHandler } from '@backstage/backend-common'; +import express from 'express'; +import Router from 'express-promise-router'; +import { Logger } from 'winston'; + +export interface RouterOptions { + logger: Logger; +} + +export async function createRouter( + options: RouterOptions, +): Promise { + const { logger } = options; + + const router = Router(); + router.use(express.json()); + + router.get('/health', (_, response) => { + logger.info('PONG!'); + response.send({ status: 'ok' }); + }); + router.use(errorHandler()); + return router; +} diff --git a/packages/cli/templates/default-backend-plugin/src/service/standaloneServer.ts.hbs b/packages/cli/templates/default-backend-plugin/src/service/standaloneServer.ts.hbs new file mode 100644 index 0000000000..6e38965246 --- /dev/null +++ b/packages/cli/templates/default-backend-plugin/src/service/standaloneServer.ts.hbs @@ -0,0 +1,47 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { createServiceBuilder } from '@backstage/backend-common'; +import { Server } from 'http'; +import { Logger } from 'winston'; +import { createRouter } from './router'; + +export interface ServerOptions { + port: number; + enableCors: boolean; + logger: Logger; +} + +export async function startStandaloneServer( + options: ServerOptions, +): Promise { + const logger = options.logger.child({ service: '{{id}}-backend' }); + logger.debug('Starting application server...'); + const router = await createRouter({ + logger, + }); + + const service = createServiceBuilder(module) + .enableCors({ origin: 'http://localhost:3000' }) + .addRouter('/{{id}}', router); + + return await service.start().catch(err => { + logger.error(err); + process.exit(1); + }); +} + +module.hot?.accept(); From dd9cc6a666df8ef972e43dfe02ce8a60d06e091c Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 23 Jul 2020 10:42:55 +0200 Subject: [PATCH 05/25] chore(cli): polyfill whatwg-fetch in tests --- .../cli/templates/default-backend-plugin/src/setupTests.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/cli/templates/default-backend-plugin/src/setupTests.ts b/packages/cli/templates/default-backend-plugin/src/setupTests.ts index 8553642152..aa5bc44d68 100644 --- a/packages/cli/templates/default-backend-plugin/src/setupTests.ts +++ b/packages/cli/templates/default-backend-plugin/src/setupTests.ts @@ -13,7 +13,4 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -import '@testing-library/jest-dom'; - -require('jest-fetch-mock').enableMocks(); +require('whatwg-fetch'); From ffa1b38a7380b3c3aefe56b420971963eb74ac4a Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 23 Jul 2020 10:43:39 +0200 Subject: [PATCH 06/25] chore(cli): polyfill fetch in the server --- packages/cli/templates/default-backend-plugin/src/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/cli/templates/default-backend-plugin/src/index.ts b/packages/cli/templates/default-backend-plugin/src/index.ts index 7612c392a2..7332f92d68 100644 --- a/packages/cli/templates/default-backend-plugin/src/index.ts +++ b/packages/cli/templates/default-backend-plugin/src/index.ts @@ -14,4 +14,5 @@ * limitations under the License. */ +require('whatwg-fetch'); export * from './service/router'; From 93306ace29cfb30b2c3db76581ff649bb0ae8bb8 Mon Sep 17 00:00:00 2001 From: Ben Lambert Date: Thu, 23 Jul 2020 11:53:50 +0200 Subject: [PATCH 07/25] chore(cli): update eslint rules --- packages/cli/templates/default-backend-plugin/.eslintrc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/templates/default-backend-plugin/.eslintrc.js b/packages/cli/templates/default-backend-plugin/.eslintrc.js index 13573efa9c..16a033dbc6 100644 --- a/packages/cli/templates/default-backend-plugin/.eslintrc.js +++ b/packages/cli/templates/default-backend-plugin/.eslintrc.js @@ -1,3 +1,3 @@ module.exports = { - extends: [require.resolve('@backstage/cli/config/eslint')], + extends: [require.resolve('@backstage/cli/config/eslint.backend')], }; From 407f62e40ac26824e37fdd54c4cfcb2c7b3efea4 Mon Sep 17 00:00:00 2001 From: Ben Lambert Date: Thu, 23 Jul 2020 11:54:25 +0200 Subject: [PATCH 08/25] chore(cli): need to make a module --- packages/cli/templates/default-backend-plugin/src/setupTests.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/cli/templates/default-backend-plugin/src/setupTests.ts b/packages/cli/templates/default-backend-plugin/src/setupTests.ts index aa5bc44d68..ac41ef995a 100644 --- a/packages/cli/templates/default-backend-plugin/src/setupTests.ts +++ b/packages/cli/templates/default-backend-plugin/src/setupTests.ts @@ -14,3 +14,5 @@ * limitations under the License. */ require('whatwg-fetch'); + +export {}; From 168f1df9359fc9a1cb960fb9a7de2248bc0cef0e Mon Sep 17 00:00:00 2001 From: Ben Lambert Date: Thu, 23 Jul 2020 11:56:35 +0200 Subject: [PATCH 09/25] chore(cli): fixing dependenceis:Wq --- .../cli/templates/default-backend-plugin/package.json.hbs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/cli/templates/default-backend-plugin/package.json.hbs b/packages/cli/templates/default-backend-plugin/package.json.hbs index 4d347107de..a2328223db 100644 --- a/packages/cli/templates/default-backend-plugin/package.json.hbs +++ b/packages/cli/templates/default-backend-plugin/package.json.hbs @@ -25,8 +25,9 @@ "@types/express": "^4.17.6", "express": "^4.17.1", "express-promise-router": "^3.0.3", - "yn": "^4.0.0", - "whatwg-fetch": "^3.2.0" + "whatwg-fetch": "^3.2.0", + "winston": "^3.3.3", + "yn": "^4.0.0" }, "devDependencies": { "@backstage/cli": "^{{version}}", From f6296c078f6eace6ccbf30fbbb45e4a4781ead67 Mon Sep 17 00:00:00 2001 From: Ben Lambert Date: Thu, 23 Jul 2020 12:00:48 +0200 Subject: [PATCH 10/25] chore(cli): fixing winston dependency --- packages/cli/templates/default-backend-plugin/package.json.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/templates/default-backend-plugin/package.json.hbs b/packages/cli/templates/default-backend-plugin/package.json.hbs index a2328223db..92f0a9e10f 100644 --- a/packages/cli/templates/default-backend-plugin/package.json.hbs +++ b/packages/cli/templates/default-backend-plugin/package.json.hbs @@ -26,7 +26,7 @@ "express": "^4.17.1", "express-promise-router": "^3.0.3", "whatwg-fetch": "^3.2.0", - "winston": "^3.3.3", + "winston": "^3.2.1", "yn": "^4.0.0" }, "devDependencies": { From 7197ceba043ca96e23c22f8cdb0bd690f679053a Mon Sep 17 00:00:00 2001 From: Ben Lambert Date: Thu, 23 Jul 2020 12:02:33 +0200 Subject: [PATCH 11/25] chore(cli): updating endpoint for test --- .../default-backend-plugin/src/service/router.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/templates/default-backend-plugin/src/service/router.test.ts b/packages/cli/templates/default-backend-plugin/src/service/router.test.ts index fba6b0ccdf..0aaeafa379 100644 --- a/packages/cli/templates/default-backend-plugin/src/service/router.test.ts +++ b/packages/cli/templates/default-backend-plugin/src/service/router.test.ts @@ -34,9 +34,9 @@ describe('createRouter', () => { jest.resetAllMocks(); }); - describe('GET /ping', () => { + describe('GET /health', () => { it('returns ok', async () => { - const response = await request(app).get('/ping'); + const response = await request(app).get('/health'); expect(response.status).toEqual(200); expect(response.body).toEqual({ status: 'ok' }); From b958118d7497b1e9990ed2b9c471eb4310cb4e18 Mon Sep 17 00:00:00 2001 From: Ben Lambert Date: Thu, 23 Jul 2020 20:22:50 +0200 Subject: [PATCH 12/25] chore(cli): updating issues with wrong package version --- packages/cli/templates/default-backend-plugin/package.json.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/templates/default-backend-plugin/package.json.hbs b/packages/cli/templates/default-backend-plugin/package.json.hbs index 92f0a9e10f..1cf9ab1c5b 100644 --- a/packages/cli/templates/default-backend-plugin/package.json.hbs +++ b/packages/cli/templates/default-backend-plugin/package.json.hbs @@ -25,7 +25,7 @@ "@types/express": "^4.17.6", "express": "^4.17.1", "express-promise-router": "^3.0.3", - "whatwg-fetch": "^3.2.0", + "whatwg-fetch": "^2.0.0", "winston": "^3.2.1", "yn": "^4.0.0" }, From 0d07847859f1c6e664578ede645679b19a862be2 Mon Sep 17 00:00:00 2001 From: blam Date: Mon, 21 Sep 2020 00:46:02 +0200 Subject: [PATCH 13/25] feat(cli): adding the backend flag to the cli --- packages/cli/src/commands/create-plugin/createPlugin.ts | 9 ++++++--- packages/cli/src/commands/index.ts | 4 ++++ .../templates/default-backend-plugin/package.json.hbs | 6 +++--- .../default-backend-plugin/scripts/mock-data.sh | 2 -- .../cli/templates/default-backend-plugin/src/index.ts | 1 - .../templates/default-backend-plugin/src/setupTests.ts | 1 - 6 files changed, 13 insertions(+), 10 deletions(-) delete mode 100755 packages/cli/templates/default-backend-plugin/scripts/mock-data.sh diff --git a/packages/cli/src/commands/create-plugin/createPlugin.ts b/packages/cli/src/commands/create-plugin/createPlugin.ts index 5e6882a4a0..8f75728544 100644 --- a/packages/cli/src/commands/create-plugin/createPlugin.ts +++ b/packages/cli/src/commands/create-plugin/createPlugin.ts @@ -175,7 +175,7 @@ export async function movePlugin( }); } -export default async () => { +export default async ({ backend }: { backend: boolean }) => { const codeownersPath = await getCodeownersFilePath(paths.targetRoot); const questions: Question[] = [ @@ -223,7 +223,9 @@ export default async () => { const answers: Answers = await inquirer.prompt(questions); const appPackage = paths.resolveTargetRoot('packages/app'); - const templateDir = paths.resolveOwn('templates/default-plugin'); + const templateDir = paths.resolveOwn( + backend ? 'templates/default-backend-plugin' : 'templates/default-plugin', + ); const tempDir = resolvePath(os.tmpdir(), answers.id); const pluginDir = paths.resolveTargetRoot('plugins', answers.id); const ownerIds = parseOwnerIds(answers.owner); @@ -240,6 +242,7 @@ export default async () => { await createTemporaryPluginFolder(tempDir); Task.section('Preparing files'); + await templatingTask(templateDir, tempDir, { ...answers, version, @@ -252,7 +255,7 @@ export default async () => { Task.section('Building the plugin'); await buildPlugin(pluginDir); - if (await fs.pathExists(appPackage)) { + if ((await fs.pathExists(appPackage)) && !backend) { Task.section('Adding plugin as dependency in app'); await addPluginDependencyToApp(paths.targetRoot, answers.id, version); diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index 4e031cdbc1..a0b898db75 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -61,6 +61,10 @@ export function registerCommands(program: CommanderStatic) { program .command('create-plugin') + .option( + '--backend', + 'Create plugin with the backend dependencies as default', + ) .description('Creates a new plugin in the current repository') .action( lazy(() => import('./create-plugin/createPlugin').then(m => m.default)), diff --git a/packages/cli/templates/default-backend-plugin/package.json.hbs b/packages/cli/templates/default-backend-plugin/package.json.hbs index 1cf9ab1c5b..8a1d5a9522 100644 --- a/packages/cli/templates/default-backend-plugin/package.json.hbs +++ b/packages/cli/templates/default-backend-plugin/package.json.hbs @@ -17,16 +17,16 @@ "test": "backstage-cli test", "prepack": "backstage-cli prepack", "postpack": "backstage-cli postpack", - "clean": "backstage-cli clean", - "mock-data": "./scripts/mock-data.sh" + "clean": "backstage-cli clean" }, "dependencies": { "@backstage/backend-common": "^{{version}}", + "@backstage/config": "^{{version}}", "@types/express": "^4.17.6", "express": "^4.17.1", "express-promise-router": "^3.0.3", - "whatwg-fetch": "^2.0.0", "winston": "^3.2.1", + "node-fetch": "^2.6.0", "yn": "^4.0.0" }, "devDependencies": { diff --git a/packages/cli/templates/default-backend-plugin/scripts/mock-data.sh b/packages/cli/templates/default-backend-plugin/scripts/mock-data.sh deleted file mode 100755 index ff30921715..0000000000 --- a/packages/cli/templates/default-backend-plugin/scripts/mock-data.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env bash -echo "use this script to load your service with some mock data if needed!" diff --git a/packages/cli/templates/default-backend-plugin/src/index.ts b/packages/cli/templates/default-backend-plugin/src/index.ts index 7332f92d68..7612c392a2 100644 --- a/packages/cli/templates/default-backend-plugin/src/index.ts +++ b/packages/cli/templates/default-backend-plugin/src/index.ts @@ -14,5 +14,4 @@ * limitations under the License. */ -require('whatwg-fetch'); export * from './service/router'; diff --git a/packages/cli/templates/default-backend-plugin/src/setupTests.ts b/packages/cli/templates/default-backend-plugin/src/setupTests.ts index ac41ef995a..ba33cf996b 100644 --- a/packages/cli/templates/default-backend-plugin/src/setupTests.ts +++ b/packages/cli/templates/default-backend-plugin/src/setupTests.ts @@ -13,6 +13,5 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -require('whatwg-fetch'); export {}; From 8953211c5bc77711058654dd7395f613a14dad64 Mon Sep 17 00:00:00 2001 From: blam Date: Mon, 21 Sep 2020 01:08:04 +0200 Subject: [PATCH 14/25] chore(cli): fixed the failing tests --- packages/app/package.json | 1 + packages/app/src/plugins.ts | 1 + packages/cli/src/commands/create-plugin/createPlugin.ts | 1 + .../ExampleComponent/ExampleComponent.test.tsx.hbs | 9 ++++----- .../ExampleFetchComponent.test.tsx.hbs | 2 -- packages/cli/templates/default-plugin/src/setupTests.ts | 2 -- 6 files changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/app/package.json b/packages/app/package.json index cb61e1ed8c..84a8dd361c 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -8,6 +8,7 @@ "@backstage/cli": "^0.1.1-alpha.22", "@backstage/core": "^0.1.1-alpha.22", "@backstage/plugin-api-docs": "^0.1.1-alpha.22", + "@backstage/plugin-asd": "^0.1.1-alpha.22", "@backstage/plugin-catalog": "^0.1.1-alpha.22", "@backstage/plugin-circleci": "^0.1.1-alpha.22", "@backstage/plugin-explore": "^0.1.1-alpha.22", diff --git a/packages/app/src/plugins.ts b/packages/app/src/plugins.ts index b36d0323e0..f7a3834bfc 100644 --- a/packages/app/src/plugins.ts +++ b/packages/app/src/plugins.ts @@ -33,3 +33,4 @@ export { plugin as Jenkins } from '@backstage/plugin-jenkins'; export { plugin as ApiDocs } from '@backstage/plugin-api-docs'; export { plugin as GithubPullRequests } from '@roadiehq/backstage-plugin-github-pull-requests'; export { plugin as GcpProjects } from '@backstage/plugin-gcp-projects'; +export { plugin as Asd } from '@backstage/plugin-asd'; diff --git a/packages/cli/src/commands/create-plugin/createPlugin.ts b/packages/cli/src/commands/create-plugin/createPlugin.ts index 8f75728544..b42edc99ec 100644 --- a/packages/cli/src/commands/create-plugin/createPlugin.ts +++ b/packages/cli/src/commands/create-plugin/createPlugin.ts @@ -176,6 +176,7 @@ export async function movePlugin( } export default async ({ backend }: { backend: boolean }) => { + console.warn(backend); const codeownersPath = await getCodeownersFilePath(paths.targetRoot); const questions: Question[] = [ diff --git a/packages/cli/templates/default-plugin/src/components/ExampleComponent/ExampleComponent.test.tsx.hbs b/packages/cli/templates/default-plugin/src/components/ExampleComponent/ExampleComponent.test.tsx.hbs index 37759313ee..4d52fa82b5 100644 --- a/packages/cli/templates/default-plugin/src/components/ExampleComponent/ExampleComponent.test.tsx.hbs +++ b/packages/cli/templates/default-plugin/src/components/ExampleComponent/ExampleComponent.test.tsx.hbs @@ -1,18 +1,17 @@ import React from 'react'; import { render } from '@testing-library/react'; -import mockFetch from 'jest-fetch-mock'; import ExampleComponent from './ExampleComponent'; import { ThemeProvider } from '@material-ui/core'; import { lightTheme } from '@backstage/theme'; describe('ExampleComponent', () => { it('should render', () => { - mockFetch.mockResponse(() => new Promise(() => {})); const rendered = render( - + , - ); - expect(rendered.getByText('Welcome to {{ id }}!')).toBeInTheDocument(); + ); + expect(rendered.getByText('Welcome to {{ id }}!')).toBeInTheDocument(); }); }); + \ No newline at end of file diff --git a/packages/cli/templates/default-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs b/packages/cli/templates/default-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs index cc61c215cd..aad4fac10a 100644 --- a/packages/cli/templates/default-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs +++ b/packages/cli/templates/default-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs @@ -1,11 +1,9 @@ import React from 'react'; import { render } from '@testing-library/react'; -import mockFetch from 'jest-fetch-mock'; import ExampleFetchComponent from './ExampleFetchComponent'; describe('ExampleFetchComponent', () => { it('should render', async () => { - mockFetch.mockResponse(() => new Promise(() => {})); const rendered = render(); expect(await rendered.findByTestId('progress')).toBeInTheDocument(); }); diff --git a/packages/cli/templates/default-plugin/src/setupTests.ts b/packages/cli/templates/default-plugin/src/setupTests.ts index 3fa8703ac4..7b0828bfa8 100644 --- a/packages/cli/templates/default-plugin/src/setupTests.ts +++ b/packages/cli/templates/default-plugin/src/setupTests.ts @@ -1,3 +1 @@ import '@testing-library/jest-dom'; - -require('jest-fetch-mock').enableMocks(); From 9f8f07d483e54b5c2d1c85775ce795bcbf654f3d Mon Sep 17 00:00:00 2001 From: blam Date: Mon, 21 Sep 2020 01:13:57 +0200 Subject: [PATCH 15/25] chore(cli): fixing issues --- packages/app/package.json | 1 - packages/app/src/plugins.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/packages/app/package.json b/packages/app/package.json index 84a8dd361c..cb61e1ed8c 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -8,7 +8,6 @@ "@backstage/cli": "^0.1.1-alpha.22", "@backstage/core": "^0.1.1-alpha.22", "@backstage/plugin-api-docs": "^0.1.1-alpha.22", - "@backstage/plugin-asd": "^0.1.1-alpha.22", "@backstage/plugin-catalog": "^0.1.1-alpha.22", "@backstage/plugin-circleci": "^0.1.1-alpha.22", "@backstage/plugin-explore": "^0.1.1-alpha.22", diff --git a/packages/app/src/plugins.ts b/packages/app/src/plugins.ts index f7a3834bfc..b36d0323e0 100644 --- a/packages/app/src/plugins.ts +++ b/packages/app/src/plugins.ts @@ -33,4 +33,3 @@ export { plugin as Jenkins } from '@backstage/plugin-jenkins'; export { plugin as ApiDocs } from '@backstage/plugin-api-docs'; export { plugin as GithubPullRequests } from '@roadiehq/backstage-plugin-github-pull-requests'; export { plugin as GcpProjects } from '@backstage/plugin-gcp-projects'; -export { plugin as Asd } from '@backstage/plugin-asd'; From cd0f2bd3db9c389b4b1eea2b2b52e4892de3b5cf Mon Sep 17 00:00:00 2001 From: blam Date: Mon, 21 Sep 2020 15:48:55 +0200 Subject: [PATCH 16/25] chore(cli/backend): fixing some drit --- packages/cli/src/commands/create-plugin/createPlugin.ts | 1 - packages/cli/templates/default-backend-plugin/package.json.hbs | 2 +- .../components/ExampleComponent/ExampleComponent.test.tsx.hbs | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/commands/create-plugin/createPlugin.ts b/packages/cli/src/commands/create-plugin/createPlugin.ts index b42edc99ec..8f75728544 100644 --- a/packages/cli/src/commands/create-plugin/createPlugin.ts +++ b/packages/cli/src/commands/create-plugin/createPlugin.ts @@ -176,7 +176,6 @@ export async function movePlugin( } export default async ({ backend }: { backend: boolean }) => { - console.warn(backend); const codeownersPath = await getCodeownersFilePath(paths.targetRoot); const questions: Question[] = [ diff --git a/packages/cli/templates/default-backend-plugin/package.json.hbs b/packages/cli/templates/default-backend-plugin/package.json.hbs index 8a1d5a9522..fd2c57f87d 100644 --- a/packages/cli/templates/default-backend-plugin/package.json.hbs +++ b/packages/cli/templates/default-backend-plugin/package.json.hbs @@ -7,7 +7,7 @@ "private": true, "publishConfig": { "access": "public", - "main": "dist/index.esm.js", + "main": "dist/index.cjs.js", "types": "dist/index.d.ts" }, "scripts": { diff --git a/packages/cli/templates/default-plugin/src/components/ExampleComponent/ExampleComponent.test.tsx.hbs b/packages/cli/templates/default-plugin/src/components/ExampleComponent/ExampleComponent.test.tsx.hbs index 4d52fa82b5..f49457490f 100644 --- a/packages/cli/templates/default-plugin/src/components/ExampleComponent/ExampleComponent.test.tsx.hbs +++ b/packages/cli/templates/default-plugin/src/components/ExampleComponent/ExampleComponent.test.tsx.hbs @@ -8,7 +8,7 @@ describe('ExampleComponent', () => { it('should render', () => { const rendered = render( - + , ); expect(rendered.getByText('Welcome to {{ id }}!')).toBeInTheDocument(); From 6f70008386fb128a90b88c756995a1dc402520f3 Mon Sep 17 00:00:00 2001 From: blam Date: Mon, 21 Sep 2020 23:37:35 +0200 Subject: [PATCH 17/25] chore(cli): fixing issues with the new dependency --- packages/cli/src/commands/create-plugin/createPlugin.ts | 2 +- packages/cli/templates/default-backend-plugin/package.json.hbs | 2 +- packages/cli/templates/default-plugin/package.json.hbs | 2 +- plugins/api-docs/package.json | 3 ++- plugins/app-backend/package.json | 2 +- plugins/auth-backend/package.json | 3 ++- plugins/catalog-graphql/package.json | 2 +- plugins/circleci/package.json | 3 ++- plugins/explore/package.json | 3 ++- plugins/gcp-projects/package.json | 3 ++- plugins/github-actions/package.json | 3 ++- plugins/gitops-profiles/package.json | 3 ++- plugins/graphiql/package.json | 3 ++- plugins/identity-backend/package.json | 3 ++- plugins/jenkins/package.json | 3 ++- plugins/lighthouse/package.json | 3 ++- plugins/newrelic/package.json | 3 ++- plugins/register-component/package.json | 3 ++- plugins/rollbar/package.json | 3 ++- plugins/scaffolder/package.json | 3 ++- plugins/sentry/package.json | 3 ++- plugins/tech-radar/package.json | 3 ++- plugins/techdocs/package.json | 3 ++- plugins/welcome/package.json | 3 ++- 24 files changed, 43 insertions(+), 24 deletions(-) diff --git a/packages/cli/src/commands/create-plugin/createPlugin.ts b/packages/cli/src/commands/create-plugin/createPlugin.ts index 37c026ecae..cbaf956bdb 100644 --- a/packages/cli/src/commands/create-plugin/createPlugin.ts +++ b/packages/cli/src/commands/create-plugin/createPlugin.ts @@ -272,7 +272,7 @@ export default async (cmd: Command) => { Task.section('Building the plugin'); await buildPlugin(pluginDir); - if ((await fs.pathExists(appPackage)) && !backend) { + if ((await fs.pathExists(appPackage)) && !cmd.backend) { Task.section('Adding plugin as dependency in app'); await addPluginDependencyToApp(paths.targetRoot, name, version); diff --git a/packages/cli/templates/default-backend-plugin/package.json.hbs b/packages/cli/templates/default-backend-plugin/package.json.hbs index 2ecdbcef01..a4b6e7aaf9 100644 --- a/packages/cli/templates/default-backend-plugin/package.json.hbs +++ b/packages/cli/templates/default-backend-plugin/package.json.hbs @@ -36,7 +36,7 @@ "@backstage/cli": "^{{version}}", "@types/supertest": "^2.0.8", "supertest": "^4.0.2", - "msw": "^0.19.5" + "msw": "^0.20.5" }, "files": [ "dist" diff --git a/packages/cli/templates/default-plugin/package.json.hbs b/packages/cli/templates/default-plugin/package.json.hbs index 7597d3dc28..0d26339843 100644 --- a/packages/cli/templates/default-plugin/package.json.hbs +++ b/packages/cli/templates/default-plugin/package.json.hbs @@ -41,7 +41,7 @@ "@testing-library/user-event": "^12.0.7", "@types/jest": "^26.0.7", "@types/node": "^12.0.0", - "msw": "^0.19.5" + "msw": "^0.20.5" }, "files": [ "dist" diff --git a/plugins/api-docs/package.json b/plugins/api-docs/package.json index 378ceb2d08..254dc9aba0 100644 --- a/plugins/api-docs/package.json +++ b/plugins/api-docs/package.json @@ -49,7 +49,8 @@ "@types/node": "^12.0.0", "@types/react": "^16.9", "@types/swagger-ui-react": "^3.23.3", - "jest-fetch-mock": "^3.0.3" + "jest-fetch-mock": "^3.0.3", + "msw": "^0.20.5" }, "files": [ "dist" diff --git a/plugins/app-backend/package.json b/plugins/app-backend/package.json index c4738c7105..2854425e75 100644 --- a/plugins/app-backend/package.json +++ b/plugins/app-backend/package.json @@ -32,7 +32,7 @@ "devDependencies": { "@backstage/cli": "^0.1.1-alpha.22", "@types/supertest": "^2.0.8", - "msw": "^0.19.5", + "msw": "^0.20.5", "supertest": "^4.0.2" }, "files": [ diff --git a/plugins/auth-backend/package.json b/plugins/auth-backend/package.json index 91fe08c0fa..aff6470e71 100644 --- a/plugins/auth-backend/package.json +++ b/plugins/auth-backend/package.json @@ -58,7 +58,8 @@ "@types/passport-google-oauth20": "^2.0.3", "@types/passport-microsoft": "^0.0.0", "@types/passport-saml": "^1.1.2", - "jest-fetch-mock": "^3.0.3" + "jest-fetch-mock": "^3.0.3", + "msw": "^0.20.5" }, "files": [ "dist", diff --git a/plugins/catalog-graphql/package.json b/plugins/catalog-graphql/package.json index c508215f29..505f7bb4df 100644 --- a/plugins/catalog-graphql/package.json +++ b/plugins/catalog-graphql/package.json @@ -40,7 +40,7 @@ "@graphql-codegen/typescript-resolvers": "^1.17.7", "ts-node": "^8.10.2", "eslint-plugin-graphql": "^4.0.0", - "msw": "^0.19.5", + "msw": "^0.20.5", "supertest": "^4.0.2" }, "files": [ diff --git a/plugins/circleci/package.json b/plugins/circleci/package.json index 10278fc065..47600d5452 100644 --- a/plugins/circleci/package.json +++ b/plugins/circleci/package.json @@ -46,7 +46,8 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "@types/react-lazylog": "^4.5.0", - "jest-fetch-mock": "^3.0.3" + "jest-fetch-mock": "^3.0.3", + "msw": "^0.20.5" }, "files": [ "dist" diff --git a/plugins/explore/package.json b/plugins/explore/package.json index c889f96153..f094c4f908 100644 --- a/plugins/explore/package.json +++ b/plugins/explore/package.json @@ -41,7 +41,8 @@ "@testing-library/user-event": "^12.0.7", "@types/jest": "^26.0.7", "@types/node": "^12.0.0", - "jest-fetch-mock": "^3.0.3" + "jest-fetch-mock": "^3.0.3", + "msw": "^0.20.5" }, "files": [ "dist" diff --git a/plugins/gcp-projects/package.json b/plugins/gcp-projects/package.json index b71cebf6e4..fa72f0e66d 100644 --- a/plugins/gcp-projects/package.json +++ b/plugins/gcp-projects/package.json @@ -39,7 +39,8 @@ "@testing-library/user-event": "^12.0.7", "@types/jest": "^26.0.7", "@types/node": "^12.0.0", - "jest-fetch-mock": "^3.0.3" + "jest-fetch-mock": "^3.0.3", + "msw": "^0.20.5" }, "files": [ "dist" diff --git a/plugins/github-actions/package.json b/plugins/github-actions/package.json index 9d1538ce99..1ee1e44074 100644 --- a/plugins/github-actions/package.json +++ b/plugins/github-actions/package.json @@ -47,7 +47,8 @@ "@testing-library/user-event": "^12.0.7", "@types/jest": "^26.0.7", "@types/node": "^12.0.0", - "jest-fetch-mock": "^3.0.3" + "jest-fetch-mock": "^3.0.3", + "msw": "^0.20.5" }, "files": [ "dist" diff --git a/plugins/gitops-profiles/package.json b/plugins/gitops-profiles/package.json index cb25167ba6..7805f35f85 100644 --- a/plugins/gitops-profiles/package.json +++ b/plugins/gitops-profiles/package.json @@ -39,7 +39,8 @@ "@testing-library/user-event": "^12.0.7", "@types/jest": "^26.0.7", "@types/node": "^12.0.0", - "jest-fetch-mock": "^3.0.3" + "jest-fetch-mock": "^3.0.3", + "msw": "^0.20.5" }, "files": [ "dist" diff --git a/plugins/graphiql/package.json b/plugins/graphiql/package.json index e6122eb38b..5747ff5726 100644 --- a/plugins/graphiql/package.json +++ b/plugins/graphiql/package.json @@ -53,7 +53,8 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "jest-fetch-mock": "^3.0.3", - "react-router-dom": "6.0.0-beta.0" + "react-router-dom": "6.0.0-beta.0", + "msw": "^0.20.5" }, "files": [ "dist" diff --git a/plugins/identity-backend/package.json b/plugins/identity-backend/package.json index a34049fb91..ab006d3ecc 100644 --- a/plugins/identity-backend/package.json +++ b/plugins/identity-backend/package.json @@ -34,7 +34,8 @@ }, "devDependencies": { "@backstage/cli": "^0.1.1-alpha.22", - "jest-fetch-mock": "^3.0.3" + "jest-fetch-mock": "^3.0.3", + "msw": "^0.20.5" }, "files": [ "dist" diff --git a/plugins/jenkins/package.json b/plugins/jenkins/package.json index 398161f270..07ec728b34 100644 --- a/plugins/jenkins/package.json +++ b/plugins/jenkins/package.json @@ -44,7 +44,8 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "@types/testing-library__jest-dom": "^5.9.1", - "jest-fetch-mock": "^3.0.3" + "jest-fetch-mock": "^3.0.3", + "msw": "^0.20.5" }, "files": [ "dist" diff --git a/plugins/lighthouse/package.json b/plugins/lighthouse/package.json index c5522ae67a..ea73010491 100644 --- a/plugins/lighthouse/package.json +++ b/plugins/lighthouse/package.json @@ -42,7 +42,8 @@ "@testing-library/user-event": "^12.0.7", "@types/jest": "^26.0.7", "@types/node": "^12.0.0", - "jest-fetch-mock": "^3.0.3" + "jest-fetch-mock": "^3.0.3", + "msw": "^0.20.5" }, "files": [ "dist" diff --git a/plugins/newrelic/package.json b/plugins/newrelic/package.json index 0cadf440f7..63a6d0a1b4 100644 --- a/plugins/newrelic/package.json +++ b/plugins/newrelic/package.json @@ -38,7 +38,8 @@ "@testing-library/user-event": "^12.0.7", "@types/jest": "^26.0.7", "@types/node": "^12.0.0", - "jest-fetch-mock": "^3.0.3" + "jest-fetch-mock": "^3.0.3", + "msw": "^0.20.5" }, "files": [ "dist" diff --git a/plugins/register-component/package.json b/plugins/register-component/package.json index 8ccaae9914..c2d9709643 100644 --- a/plugins/register-component/package.json +++ b/plugins/register-component/package.json @@ -43,7 +43,8 @@ "@testing-library/user-event": "^12.0.7", "@types/jest": "^26.0.7", "@types/node": "^12.0.0", - "jest-fetch-mock": "^3.0.3" + "jest-fetch-mock": "^3.0.3", + "msw": "^0.20.5" }, "files": [ "dist" diff --git a/plugins/rollbar/package.json b/plugins/rollbar/package.json index cb37c6187a..c2154a2c85 100644 --- a/plugins/rollbar/package.json +++ b/plugins/rollbar/package.json @@ -47,7 +47,8 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "@types/react": "^16.9", - "jest-fetch-mock": "^3.0.3" + "jest-fetch-mock": "^3.0.3", + "msw": "^0.20.5" }, "files": [ "dist" diff --git a/plugins/scaffolder/package.json b/plugins/scaffolder/package.json index ab95e83201..21b95a6aaf 100644 --- a/plugins/scaffolder/package.json +++ b/plugins/scaffolder/package.json @@ -49,7 +49,8 @@ "@testing-library/user-event": "^12.0.7", "@types/jest": "^26.0.7", "@types/node": "^12.0.0", - "jest-fetch-mock": "^3.0.3" + "jest-fetch-mock": "^3.0.3", + "msw": "^0.20.5" }, "files": [ "dist" diff --git a/plugins/sentry/package.json b/plugins/sentry/package.json index 6e7daea15c..1fd836b83f 100644 --- a/plugins/sentry/package.json +++ b/plugins/sentry/package.json @@ -43,7 +43,8 @@ "@testing-library/user-event": "^12.0.7", "@types/jest": "^26.0.7", "@types/node": "^12.0.0", - "jest-fetch-mock": "^3.0.3" + "jest-fetch-mock": "^3.0.3", + "msw": "^0.20.5" }, "files": [ "dist" diff --git a/plugins/tech-radar/package.json b/plugins/tech-radar/package.json index f25ec752e1..36318be766 100644 --- a/plugins/tech-radar/package.json +++ b/plugins/tech-radar/package.json @@ -45,7 +45,8 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "@types/react": "^16.9", - "jest-fetch-mock": "^3.0.3" + "jest-fetch-mock": "^3.0.3", + "msw": "^0.20.5" }, "files": [ "dist" diff --git a/plugins/techdocs/package.json b/plugins/techdocs/package.json index d2f99cb824..d467f8ef5f 100644 --- a/plugins/techdocs/package.json +++ b/plugins/techdocs/package.json @@ -48,7 +48,8 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "canvas": "^2.6.1", - "jest-fetch-mock": "^3.0.3" + "jest-fetch-mock": "^3.0.3", + "msw": "^0.20.5" }, "files": [ "dist" diff --git a/plugins/welcome/package.json b/plugins/welcome/package.json index 741a680cd9..7784d8ff97 100644 --- a/plugins/welcome/package.json +++ b/plugins/welcome/package.json @@ -39,7 +39,8 @@ "@testing-library/user-event": "^12.0.7", "@types/jest": "^26.0.7", "@types/node": "^12.0.0", - "jest-fetch-mock": "^3.0.3" + "jest-fetch-mock": "^3.0.3", + "msw": "^0.20.5" }, "files": [ "dist" From 65664e2c30cb263c0ebcd821bd94e1d1e5310482 Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 22 Sep 2020 01:54:38 +0200 Subject: [PATCH 18/25] chore(cli): fixing create again --- .../ExampleComponent.test.tsx.hbs | 18 +++++++++ .../ExampleFetchComponent.test.tsx.hbs | 16 ++++++++ packages/test-utils-core/package.json | 4 +- yarn.lock | 37 ++----------------- 4 files changed, 40 insertions(+), 35 deletions(-) diff --git a/packages/cli/templates/default-plugin/src/components/ExampleComponent/ExampleComponent.test.tsx.hbs b/packages/cli/templates/default-plugin/src/components/ExampleComponent/ExampleComponent.test.tsx.hbs index f49457490f..1069790218 100644 --- a/packages/cli/templates/default-plugin/src/components/ExampleComponent/ExampleComponent.test.tsx.hbs +++ b/packages/cli/templates/default-plugin/src/components/ExampleComponent/ExampleComponent.test.tsx.hbs @@ -3,8 +3,26 @@ import { render } from '@testing-library/react'; import ExampleComponent from './ExampleComponent'; import { ThemeProvider } from '@material-ui/core'; import { lightTheme } from '@backstage/theme'; +import { rest } from 'msw'; +import { setupServer } from 'msw/node'; + describe('ExampleComponent', () => { + const server = setupServer(); + // Enable API mocking before tests. + beforeAll(() => server.listen()) + + // Reset any runtime request handlers we may add during the tests. + afterEach(() => server.resetHandlers()) + + // Disable API mocking after the tests are done. + afterAll(() => server.close()) + + // setup mock response + beforeEach(() => { + server.use(rest.get('/*', (_, res, ctx) => res(ctx.status(200), ctx.json({})))) + }) + it('should render', () => { const rendered = render( diff --git a/packages/cli/templates/default-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs b/packages/cli/templates/default-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs index aad4fac10a..309fa34aee 100644 --- a/packages/cli/templates/default-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs +++ b/packages/cli/templates/default-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs @@ -1,8 +1,24 @@ import React from 'react'; import { render } from '@testing-library/react'; import ExampleFetchComponent from './ExampleFetchComponent'; +import { rest } from 'msw'; +import { setupServer } from 'msw/node'; describe('ExampleFetchComponent', () => { + const server = setupServer(); + // Enable API mocking before tests. + beforeAll(() => server.listen()) + + // Reset any runtime request handlers we may add during the tests. + afterEach(() => server.resetHandlers()) + + // Disable API mocking after the tests are done. + afterAll(() => server.close()) + + // setup mock response + beforeEach(() => { + server.use(rest.get('/*', (_, res, ctx) => res(ctx.status(200), ctx.delay(2000), ctx.json({})))) + }) it('should render', async () => { const rendered = render(); expect(await rendered.findByTestId('progress')).toBeInTheDocument(); diff --git a/packages/test-utils-core/package.json b/packages/test-utils-core/package.json index d79acf80a8..c279656736 100644 --- a/packages/test-utils-core/package.json +++ b/packages/test-utils-core/package.json @@ -18,8 +18,8 @@ "backstage" ], "license": "Apache-2.0", - "main": "src/index.ts", - "types": "src/index.ts", + "main": "dist/index.esm.js", + "types": "dist/index.d.ts", "scripts": { "build": "backstage-cli build --outputs types,esm", "lint": "backstage-cli lint", diff --git a/yarn.lock b/yarn.lock index 0cdce51f95..df2c58400e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3287,7 +3287,7 @@ dependencies: "@types/node" ">= 8" -"@open-draft/until@^1.0.0", "@open-draft/until@^1.0.3": +"@open-draft/until@^1.0.3": version "1.0.3" resolved "https://registry.npmjs.org/@open-draft/until/-/until-1.0.3.tgz#db9cc719191a62e7d9200f6e7bab21c5b848adca" integrity sha512-Aq58f5HiWdyDlFffbbSjAlv596h/cOnt2DO1w3DOC7OJ5EHs0hd/nycJfiu9RJbT6Yk6F1knnRRXNSpxoIVZ9Q== @@ -4507,11 +4507,6 @@ dependencies: "@types/express" "*" -"@types/cookie@^0.3.3": - version "0.3.3" - resolved "https://registry.npmjs.org/@types/cookie/-/cookie-0.3.3.tgz#85bc74ba782fb7aa3a514d11767832b0e3bc6803" - integrity sha512-LKVP3cgXBT9RYj+t+9FDKwS5tdI+rPBXaNSkma7hvqy35lc7mAokC2zsqWJH0LaqIt3B962nuYI77hsJoT1gow== - "@types/cookie@^0.4.0": version "0.4.0" resolved "https://registry.npmjs.org/@types/cookie/-/cookie-0.4.0.tgz#14f854c0f93d326e39da6e3b6f34f7d37513d108" @@ -11817,7 +11812,7 @@ graphql-upload@^8.0.2: http-errors "^1.7.3" object-path "^0.11.4" -graphql@15.3.0, graphql@^15.0.0, graphql@^15.3.0: +graphql@15.3.0, graphql@^15.3.0: version "15.3.0" resolved "https://registry.npmjs.org/graphql/-/graphql-15.3.0.tgz#3ad2b0caab0d110e3be4a5a9b2aa281e362b5278" integrity sha512-GTCJtzJmkFLWRfFJuoo9RWWa/FfamUHgiFosxi/X1Ani4AVWbeyBenZTNX6dM+7WSbbFfTo/25eh0LLkwHMw2w== @@ -11993,7 +11988,7 @@ he@^1.1.0, he@^1.2.0: resolved "https://registry.npmjs.org/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f" integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw== -headers-utils@^1.1.9, headers-utils@^1.2.0: +headers-utils@^1.2.0: version "1.2.0" resolved "https://registry.npmjs.org/headers-utils/-/headers-utils-1.2.0.tgz#5e10d1bc9d2bccf789547afca5b991a3167241e8" integrity sha512-4/BMXcWrJErw7JpM87gF8MNEXcIMLzepYZjNRv/P9ctgupl2Ywa3u1PgHtNhSRq84bHH9Ndlkdy7bSi+bZ9I9A== @@ -15555,22 +15550,6 @@ ms@^2.0.0, ms@^2.1.1: resolved "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== -msw@^0.19.5: - version "0.19.5" - resolved "https://registry.npmjs.org/msw/-/msw-0.19.5.tgz#7d2a1a852ccf1644d3db6735d69fff6777aac33f" - integrity sha512-J5eQ++gDVZoHPC8gVXtWcakLjgmPipvFj/sEnlRV/WViXuiq2CamSqO3Wbh6H8bAmj+k2vUWCfcVT1HjMdKB2Q== - dependencies: - "@open-draft/until" "^1.0.0" - "@types/cookie" "^0.3.3" - chalk "^4.0.0" - cookie "^0.4.1" - graphql "^15.0.0" - headers-utils "^1.1.9" - node-match-path "^0.4.2" - node-request-interceptor "^0.2.5" - statuses "^2.0.0" - yargs "^15.3.1" - msw@^0.20.5: version "0.20.5" resolved "https://registry.npmjs.org/msw/-/msw-0.20.5.tgz#b6141080c0d8b17c451d9ca36c28cc47b4ac487a" @@ -15830,7 +15809,7 @@ node-libs-browser@^2.2.1: util "^0.11.0" vm-browserify "^1.0.1" -node-match-path@^0.4.2, node-match-path@^0.4.4: +node-match-path@^0.4.4: version "0.4.4" resolved "https://registry.npmjs.org/node-match-path/-/node-match-path-0.4.4.tgz#516a10926093c0cc6f237d020685b593b19baebb" integrity sha512-pBq9gp7TG0r0VXuy/oeZmQsjBSnYQo7G886Ly/B3azRwZuEtHCY155dzmfoKWcDPGgyfIGD8WKVC7h3+6y7yTg== @@ -15889,14 +15868,6 @@ node-releases@^1.1.52, node-releases@^1.1.58: resolved "https://registry.npmjs.org/node-releases/-/node-releases-1.1.60.tgz#6948bdfce8286f0b5d0e5a88e8384e954dfe7084" integrity sha512-gsO4vjEdQaTusZAEebUWp2a5d7dF5DYoIpDG7WySnk7BuZDW+GPpHXoXXuYawRBr/9t5q54tirPz79kFIWg4dA== -node-request-interceptor@^0.2.5: - version "0.2.6" - resolved "https://registry.npmjs.org/node-request-interceptor/-/node-request-interceptor-0.2.6.tgz#541278d7033bb6a8befb5dd793f83428cf6446a2" - integrity sha512-aJW1tPSM7nzuZFRe+C/KSz22GJO3CVFMxHHmMGX8Z+tjP7TCIVbzeckLFVfJG68BdVgrdOOP7Ejc57ag820eyA== - dependencies: - debug "^4.1.1" - headers-utils "^1.2.0" - node-request-interceptor@^0.3.5: version "0.3.5" resolved "https://registry.npmjs.org/node-request-interceptor/-/node-request-interceptor-0.3.5.tgz#4b26159617829c9a70643012c0fdc3ae4c78ae43" From 23275680fa3693ad68991bd1b064e3713fd1b8fe Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 22 Sep 2020 02:53:27 +0200 Subject: [PATCH 19/25] chore(cli): revert some core testing utils --- packages/test-utils-core/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/test-utils-core/package.json b/packages/test-utils-core/package.json index c279656736..d79acf80a8 100644 --- a/packages/test-utils-core/package.json +++ b/packages/test-utils-core/package.json @@ -18,8 +18,8 @@ "backstage" ], "license": "Apache-2.0", - "main": "dist/index.esm.js", - "types": "dist/index.d.ts", + "main": "src/index.ts", + "types": "src/index.ts", "scripts": { "build": "backstage-cli build --outputs types,esm", "lint": "backstage-cli lint", From a9adf229ff8ae800db0ed8a1efeb5d02f05b363a Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 22 Sep 2020 03:25:08 +0200 Subject: [PATCH 20/25] chore(cli): fixing cli issues --- .../ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/templates/default-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs b/packages/cli/templates/default-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs index 309fa34aee..c584289077 100644 --- a/packages/cli/templates/default-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs +++ b/packages/cli/templates/default-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs @@ -17,7 +17,7 @@ describe('ExampleFetchComponent', () => { // setup mock response beforeEach(() => { - server.use(rest.get('/*', (_, res, ctx) => res(ctx.status(200), ctx.delay(2000), ctx.json({})))) + server.use(rest.get('https://randomuser.me/*', (_, res, ctx) => res(ctx.status(200), ctx.delay(2000), ctx.json({})))) }) it('should render', async () => { const rendered = render(); From b60086db6b5968be2f87b68f338d8c28a6aa7046 Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 22 Sep 2020 03:56:16 +0200 Subject: [PATCH 21/25] chore(cli): updating nodefetch --- packages/cli/templates/default-backend-plugin/package.json.hbs | 2 +- .../cli/templates/default-backend-plugin/src/setupTests.ts | 1 + packages/cli/templates/default-plugin/package.json.hbs | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/cli/templates/default-backend-plugin/package.json.hbs b/packages/cli/templates/default-backend-plugin/package.json.hbs index a4b6e7aaf9..40e612609a 100644 --- a/packages/cli/templates/default-backend-plugin/package.json.hbs +++ b/packages/cli/templates/default-backend-plugin/package.json.hbs @@ -29,7 +29,7 @@ "express": "^4.17.1", "express-promise-router": "^3.0.3", "winston": "^3.2.1", - "node-fetch": "^2.6.0", + "node-fetch": "^2.6.1", "yn": "^4.0.0" }, "devDependencies": { diff --git a/packages/cli/templates/default-backend-plugin/src/setupTests.ts b/packages/cli/templates/default-backend-plugin/src/setupTests.ts index ba33cf996b..a5907fd52f 100644 --- a/packages/cli/templates/default-backend-plugin/src/setupTests.ts +++ b/packages/cli/templates/default-backend-plugin/src/setupTests.ts @@ -15,3 +15,4 @@ */ export {}; +global.fetch = require('node-fetch'); diff --git a/packages/cli/templates/default-plugin/package.json.hbs b/packages/cli/templates/default-plugin/package.json.hbs index 0d26339843..e024884547 100644 --- a/packages/cli/templates/default-plugin/package.json.hbs +++ b/packages/cli/templates/default-plugin/package.json.hbs @@ -41,7 +41,8 @@ "@testing-library/user-event": "^12.0.7", "@types/jest": "^26.0.7", "@types/node": "^12.0.0", - "msw": "^0.20.5" + "msw": "^0.20.5", + "node-fetch": "^2.6.1" }, "files": [ "dist" From 37a4a3afd0ed498ac35e983ffb1cb56b0662468e Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 24 Sep 2020 10:52:26 +0200 Subject: [PATCH 22/25] chore(deps): updating dependencies for plugin --- plugins/api-docs/package.json | 3 ++- plugins/catalog/package.json | 3 ++- plugins/circleci/package.json | 3 ++- plugins/explore/package.json | 3 ++- plugins/gcp-projects/package.json | 3 ++- plugins/github-actions/package.json | 3 ++- plugins/gitops-profiles/package.json | 3 ++- plugins/graphiql/package.json | 3 ++- plugins/jenkins/package.json | 3 ++- plugins/lighthouse/package.json | 3 ++- plugins/newrelic/package.json | 3 ++- plugins/register-component/package.json | 3 ++- plugins/rollbar/package.json | 3 ++- plugins/scaffolder/package.json | 3 ++- plugins/sentry/package.json | 3 ++- plugins/tech-radar/package.json | 3 ++- plugins/techdocs/package.json | 3 ++- plugins/welcome/package.json | 3 ++- 18 files changed, 36 insertions(+), 18 deletions(-) diff --git a/plugins/api-docs/package.json b/plugins/api-docs/package.json index 254dc9aba0..ee86e29183 100644 --- a/plugins/api-docs/package.json +++ b/plugins/api-docs/package.json @@ -50,7 +50,8 @@ "@types/react": "^16.9", "@types/swagger-ui-react": "^3.23.3", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5" + "msw": "^0.20.5", + "node-fetch": "^2.6.1" }, "files": [ "dist" diff --git a/plugins/catalog/package.json b/plugins/catalog/package.json index f5520f39f9..9d777c9bcd 100644 --- a/plugins/catalog/package.json +++ b/plugins/catalog/package.json @@ -53,7 +53,8 @@ "jest-fetch-mock": "^3.0.3", "msw": "^0.20.5", "react-test-renderer": "^16.13.1", - "whatwg-fetch": "^3.4.0" + "whatwg-fetch": "^3.4.0", + "node-fetch": "^2.6.1" }, "files": [ "dist" diff --git a/plugins/circleci/package.json b/plugins/circleci/package.json index 47600d5452..7dce54f8b3 100644 --- a/plugins/circleci/package.json +++ b/plugins/circleci/package.json @@ -47,7 +47,8 @@ "@types/node": "^12.0.0", "@types/react-lazylog": "^4.5.0", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5" + "msw": "^0.20.5", + "node-fetch": "^2.6.1" }, "files": [ "dist" diff --git a/plugins/explore/package.json b/plugins/explore/package.json index f094c4f908..7a46a2954f 100644 --- a/plugins/explore/package.json +++ b/plugins/explore/package.json @@ -42,7 +42,8 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5" + "msw": "^0.20.5", + "node-fetch": "^2.6.1" }, "files": [ "dist" diff --git a/plugins/gcp-projects/package.json b/plugins/gcp-projects/package.json index fa72f0e66d..c6424056c8 100644 --- a/plugins/gcp-projects/package.json +++ b/plugins/gcp-projects/package.json @@ -40,7 +40,8 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5" + "msw": "^0.20.5", + "node-fetch": "^2.6.1" }, "files": [ "dist" diff --git a/plugins/github-actions/package.json b/plugins/github-actions/package.json index 1ee1e44074..8ee00bef06 100644 --- a/plugins/github-actions/package.json +++ b/plugins/github-actions/package.json @@ -48,7 +48,8 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5" + "msw": "^0.20.5", + "node-fetch": "^2.6.1" }, "files": [ "dist" diff --git a/plugins/gitops-profiles/package.json b/plugins/gitops-profiles/package.json index 7805f35f85..79b9b3a708 100644 --- a/plugins/gitops-profiles/package.json +++ b/plugins/gitops-profiles/package.json @@ -40,7 +40,8 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5" + "msw": "^0.20.5", + "node-fetch": "^2.6.1" }, "files": [ "dist" diff --git a/plugins/graphiql/package.json b/plugins/graphiql/package.json index 5747ff5726..ab80901fa0 100644 --- a/plugins/graphiql/package.json +++ b/plugins/graphiql/package.json @@ -54,7 +54,8 @@ "@types/node": "^12.0.0", "jest-fetch-mock": "^3.0.3", "react-router-dom": "6.0.0-beta.0", - "msw": "^0.20.5" + "msw": "^0.20.5", + "node-fetch": "^2.6.1" }, "files": [ "dist" diff --git a/plugins/jenkins/package.json b/plugins/jenkins/package.json index 07ec728b34..091ef9356a 100644 --- a/plugins/jenkins/package.json +++ b/plugins/jenkins/package.json @@ -45,7 +45,8 @@ "@types/node": "^12.0.0", "@types/testing-library__jest-dom": "^5.9.1", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5" + "msw": "^0.20.5", + "node-fetch": "^2.6.1" }, "files": [ "dist" diff --git a/plugins/lighthouse/package.json b/plugins/lighthouse/package.json index ea73010491..a5e7ae7b62 100644 --- a/plugins/lighthouse/package.json +++ b/plugins/lighthouse/package.json @@ -43,7 +43,8 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5" + "msw": "^0.20.5", + "node-fetch": "^2.6.1" }, "files": [ "dist" diff --git a/plugins/newrelic/package.json b/plugins/newrelic/package.json index 63a6d0a1b4..7ad697a254 100644 --- a/plugins/newrelic/package.json +++ b/plugins/newrelic/package.json @@ -39,7 +39,8 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5" + "msw": "^0.20.5", + "node-fetch": "^2.6.1" }, "files": [ "dist" diff --git a/plugins/register-component/package.json b/plugins/register-component/package.json index c2d9709643..58fe9855a2 100644 --- a/plugins/register-component/package.json +++ b/plugins/register-component/package.json @@ -44,7 +44,8 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5" + "msw": "^0.20.5", + "node-fetch": "^2.6.1" }, "files": [ "dist" diff --git a/plugins/rollbar/package.json b/plugins/rollbar/package.json index c2154a2c85..3faa06d0d3 100644 --- a/plugins/rollbar/package.json +++ b/plugins/rollbar/package.json @@ -48,7 +48,8 @@ "@types/node": "^12.0.0", "@types/react": "^16.9", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5" + "msw": "^0.20.5", + "node-fetch": "^2.6.1" }, "files": [ "dist" diff --git a/plugins/scaffolder/package.json b/plugins/scaffolder/package.json index 21b95a6aaf..db8f335156 100644 --- a/plugins/scaffolder/package.json +++ b/plugins/scaffolder/package.json @@ -50,7 +50,8 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5" + "msw": "^0.20.5", + "node-fetch": "^2.6.1" }, "files": [ "dist" diff --git a/plugins/sentry/package.json b/plugins/sentry/package.json index 1fd836b83f..8ac1ab2838 100644 --- a/plugins/sentry/package.json +++ b/plugins/sentry/package.json @@ -44,7 +44,8 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5" + "msw": "^0.20.5", + "node-fetch": "^2.6.1" }, "files": [ "dist" diff --git a/plugins/tech-radar/package.json b/plugins/tech-radar/package.json index 36318be766..a8eded052c 100644 --- a/plugins/tech-radar/package.json +++ b/plugins/tech-radar/package.json @@ -46,7 +46,8 @@ "@types/node": "^12.0.0", "@types/react": "^16.9", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5" + "msw": "^0.20.5", + "node-fetch": "^2.6.1" }, "files": [ "dist" diff --git a/plugins/techdocs/package.json b/plugins/techdocs/package.json index d467f8ef5f..ab2e0dd038 100644 --- a/plugins/techdocs/package.json +++ b/plugins/techdocs/package.json @@ -49,7 +49,8 @@ "@types/node": "^12.0.0", "canvas": "^2.6.1", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5" + "msw": "^0.20.5", + "node-fetch": "^2.6.1" }, "files": [ "dist" diff --git a/plugins/welcome/package.json b/plugins/welcome/package.json index 7784d8ff97..61406087aa 100644 --- a/plugins/welcome/package.json +++ b/plugins/welcome/package.json @@ -40,7 +40,8 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5" + "msw": "^0.20.5", + "node-fetch": "^2.6.1" }, "files": [ "dist" From 95c4d68e511243755da2747b0cf0d541555f9e24 Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 24 Sep 2020 11:20:07 +0200 Subject: [PATCH 23/25] chore(cli): added node-fetch as a setup dependeny --- packages/cli/templates/default-plugin/src/setupTests.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/cli/templates/default-plugin/src/setupTests.ts b/packages/cli/templates/default-plugin/src/setupTests.ts index 7b0828bfa8..cc559f672e 100644 --- a/packages/cli/templates/default-plugin/src/setupTests.ts +++ b/packages/cli/templates/default-plugin/src/setupTests.ts @@ -1 +1,2 @@ import '@testing-library/jest-dom'; +global.fetch = require('node-fetch'); From f77e21ea8db430ba1f34c6bc1f899bd862b016e3 Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 24 Sep 2020 11:46:52 +0200 Subject: [PATCH 24/25] chore(diff): updating plugin diff for new k8s plugin --- plugins/kubernetes/package.json | 4 +++- yarn.lock | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/kubernetes/package.json b/plugins/kubernetes/package.json index d9311deb85..ffe6207680 100644 --- a/plugins/kubernetes/package.json +++ b/plugins/kubernetes/package.json @@ -39,7 +39,9 @@ "@testing-library/user-event": "^12.0.7", "@types/jest": "^26.0.7", "@types/node": "^12.0.0", - "jest-fetch-mock": "^3.0.3" + "jest-fetch-mock": "^3.0.3", + "msw": "^0.20.5", + "node-fetch": "^2.6.1" }, "files": [ "dist" diff --git a/yarn.lock b/yarn.lock index 24050ef3d4..0b6a8c83f4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -16110,7 +16110,7 @@ node-fetch@^1.0.1: encoding "^0.1.11" is-stream "^1.0.1" -node-fetch@^2.1.2, node-fetch@^2.2.0, node-fetch@^2.3.0, node-fetch@^2.5.0, node-fetch@^2.6.0: +node-fetch@^2.1.2, node-fetch@^2.2.0, node-fetch@^2.3.0, node-fetch@^2.5.0, node-fetch@^2.6.0, node-fetch@^2.6.1: version "2.6.1" resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052" integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw== From d432037459c195060ce2ffb673df1abad155148c Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 24 Sep 2020 12:37:48 +0200 Subject: [PATCH 25/25] chore(cli): addding backstage backend plugin creation --- packages/e2e-test/src/e2e-test.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/e2e-test/src/e2e-test.ts b/packages/e2e-test/src/e2e-test.ts index 969a77cb2a..7efcce567d 100644 --- a/packages/e2e-test/src/e2e-test.ts +++ b/packages/e2e-test/src/e2e-test.ts @@ -55,6 +55,9 @@ async function main() { print('Creating a Backstage Plugin'); const pluginName = await createPlugin('test-plugin', appDir); + print('Creating a Backstage Backend Plugin'); + await createPlugin('test-backend-plugin', appDir, ['--backend']); + print('Starting the app'); await testAppServe(pluginName, appDir); @@ -238,8 +241,12 @@ async function overrideModuleResolutions(appDir: string, workspaceDir: string) { /** * Uses create-plugin command to create a new plugin in the app */ -async function createPlugin(pluginName: string, appDir: string) { - const child = spawnPiped(['yarn', 'create-plugin'], { +async function createPlugin( + pluginName: string, + appDir: string, + options: string[] = [], +) { + const child = spawnPiped(['yarn', 'create-plugin', ...options], { cwd: appDir, });