From 07f61e4c2eb8766661039c8ad4af98c5cc81d7b3 Mon Sep 17 00:00:00 2001 From: Mateus Marquezini Date: Thu, 19 Mar 2020 14:20:43 -0300 Subject: [PATCH 01/10] added yarn lint and test after plugin creation. Fixed some mirror things related with eslint errors --- .github/workflows/frontend.yml | 6 ++++ packages/cli/src/commands/plugin/assets.d.ts | 16 +++++++++ packages/cli/src/commands/plugin/build.ts | 36 +++++++++---------- .../ExampleFetchComponent.tsx.hbs | 1 + .../default-plugin/src/plugin.test.ts.hbs | 16 +++++++++ .../default-plugin/src/plugin.ts.hbs | 16 +++++++++ packages/core/src/testUtils/logCollector.js | 1 + 7 files changed, 74 insertions(+), 18 deletions(-) diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index 5db1f65aa3..d56bebfad2 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -40,3 +40,9 @@ jobs: run: | sudo sysctl fs.inotify.max_user_watches=524288 node scripts/cli-e2e-test.js + - name: yarn lint, test after plugin creation + run: | + yarn lint + yarn test + env: + CI: true diff --git a/packages/cli/src/commands/plugin/assets.d.ts b/packages/cli/src/commands/plugin/assets.d.ts index 34ba07f75c..54523e926b 100644 --- a/packages/cli/src/commands/plugin/assets.d.ts +++ b/packages/cli/src/commands/plugin/assets.d.ts @@ -1,3 +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. + */ + /// /// /// diff --git a/packages/cli/src/commands/plugin/build.ts b/packages/cli/src/commands/plugin/build.ts index ff95bb994a..4c2113eb2a 100644 --- a/packages/cli/src/commands/plugin/build.ts +++ b/packages/cli/src/commands/plugin/build.ts @@ -16,10 +16,27 @@ import { Command } from 'commander'; import fs from 'fs-extra'; -import recursive from 'recursive-readdir'; import path from 'path'; +import recursive from 'recursive-readdir'; import { run } from '../../helpers/run'; +const copyStaticAssets = async () => { + const pluginRoot = fs.realpathSync(process.cwd()); + const source = path.resolve(pluginRoot, 'src'); + const destination = path.resolve(pluginRoot, 'dist', 'cjs'); + const assetFiles = await recursive(source, [ + '**/*.tsx', + '**/*.ts', + '**/*.js', + ]); + assetFiles.forEach(file => { + const fileToBeCopied = file.replace(source, destination); + const dirForFileToBeCopied = path.dirname(fileToBeCopied); + fs.ensureDirSync(dirForFileToBeCopied); + fs.copyFileSync(file, file.replace(source, destination).toString()); + }); +}; + export default async (cmd: Command) => { const args = [ '--outDir', @@ -37,20 +54,3 @@ export default async (cmd: Command) => { await copyStaticAssets(); await run('tsc', args); }; - -const copyStaticAssets = async () => { - const pluginRoot = fs.realpathSync(process.cwd()); - const source = path.resolve(pluginRoot, 'src'); - const destination = path.resolve(pluginRoot, 'dist', 'cjs'); - const assetFiles = await recursive(source, [ - '**/*.tsx', - '**/*.ts', - '**/*.js', - ]); - assetFiles.forEach(file => { - const fileToBeCopied = file.replace(source, destination); - const dirForFileToBeCopied = path.dirname(fileToBeCopied); - fs.ensureDirSync(dirForFileToBeCopied); - fs.copyFileSync(file, file.replace(source, destination).toString()); - }); -}; diff --git a/packages/cli/templates/default-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.tsx.hbs b/packages/cli/templates/default-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.tsx.hbs index 2bb43d5cce..4801dea6dd 100644 --- a/packages/cli/templates/default-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.tsx.hbs +++ b/packages/cli/templates/default-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.tsx.hbs @@ -1,3 +1,4 @@ +/* eslint-disable react/prop-types */ /* * Copyright 2020 Spotify AB * diff --git a/packages/cli/templates/default-plugin/src/plugin.test.ts.hbs b/packages/cli/templates/default-plugin/src/plugin.test.ts.hbs index 0139d97727..4e94ca5d50 100644 --- a/packages/cli/templates/default-plugin/src/plugin.test.ts.hbs +++ b/packages/cli/templates/default-plugin/src/plugin.test.ts.hbs @@ -1,3 +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 plugin from './plugin'; describe('{{ id }}', () => { diff --git a/packages/cli/templates/default-plugin/src/plugin.ts.hbs b/packages/cli/templates/default-plugin/src/plugin.ts.hbs index 830de5f553..ccac096007 100644 --- a/packages/cli/templates/default-plugin/src/plugin.ts.hbs +++ b/packages/cli/templates/default-plugin/src/plugin.ts.hbs @@ -1,3 +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 { createPlugin } from '@spotify-backstage/core'; import ExampleComponent from './components/ExampleComponent'; diff --git a/packages/core/src/testUtils/logCollector.js b/packages/core/src/testUtils/logCollector.js index 57b30c8f5c..c3ffa525b3 100644 --- a/packages/core/src/testUtils/logCollector.js +++ b/packages/core/src/testUtils/logCollector.js @@ -15,6 +15,7 @@ */ /* eslint-disable no-console */ +/* eslint-disable no-param-reassign */ // If the callback function is async this one will be too. export function withLogCollector(logsToCollect, callback) { From d958b1d8d2538fa9d3eb8df2b322bf2088a6cc28 Mon Sep 17 00:00:00 2001 From: Mateus Marquezini Date: Fri, 20 Mar 2020 10:01:58 -0300 Subject: [PATCH 02/10] fixed theme provider in a plugin test --- .../ExampleComponent/ExampleComponent.test.tsx.hbs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 ac68f95ee0..79c292512c 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 @@ -17,10 +17,16 @@ import React from 'react'; import { render } from '@testing-library/react'; import ExampleComponent from './ExampleComponent'; +import { ThemeProvider } from '@material-ui/core'; +import { BackstageTheme } from '@spotify-backstage/core'; describe('ExampleComponent', () => { it('should render', () => { - const rendered = render(); + const rendered = render( + + + + ); expect(rendered.getByText('Welcome to {{ id }}!')).toBeInTheDocument(); }); }); From 6dc109ab1d90a4a02c1bd12fd796ba76b1cdb47f Mon Sep 17 00:00:00 2001 From: Mateus Marquezini Date: Fri, 20 Mar 2020 13:26:26 -0300 Subject: [PATCH 03/10] added path to run lint and tests inside an specific folder --- .github/workflows/frontend.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index d56bebfad2..6aa13dd75d 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -41,6 +41,7 @@ jobs: sudo sysctl fs.inotify.max_user_watches=524288 node scripts/cli-e2e-test.js - name: yarn lint, test after plugin creation + path: 'plugins/*' run: | yarn lint yarn test From 293038a0120e7fa7fe0f2cce7e69e1bb7cd02e2d Mon Sep 17 00:00:00 2001 From: Mateus Marquezini Date: Fri, 20 Mar 2020 13:29:23 -0300 Subject: [PATCH 04/10] added path to run lint and tests inside an specific folder --- .github/workflows/frontend.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index 6aa13dd75d..a53e2d9386 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -41,7 +41,8 @@ jobs: sudo sysctl fs.inotify.max_user_watches=524288 node scripts/cli-e2e-test.js - name: yarn lint, test after plugin creation - path: 'plugins/*' + paths: + - 'plugins/*' run: | yarn lint yarn test From d60e7dc068f3e4b61d3a11fded7a3431596caa04 Mon Sep 17 00:00:00 2001 From: Mateus Marquezini Date: Fri, 20 Mar 2020 13:33:19 -0300 Subject: [PATCH 05/10] added path to run lint and tests inside an specific folder --- .github/workflows/frontend.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index a53e2d9386..a1586b9095 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -41,8 +41,8 @@ jobs: sudo sysctl fs.inotify.max_user_watches=524288 node scripts/cli-e2e-test.js - name: yarn lint, test after plugin creation - paths: - - 'plugins/*' + with: + path: 'plugins/*' run: | yarn lint yarn test From c25691d0c05aa6e91bf3a45bfad25dae534b0dbf Mon Sep 17 00:00:00 2001 From: Mateus Marquezini Date: Fri, 20 Mar 2020 13:36:46 -0300 Subject: [PATCH 06/10] reverted changes --- .github/workflows/frontend.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index a1586b9095..d56bebfad2 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -41,8 +41,6 @@ jobs: sudo sysctl fs.inotify.max_user_watches=524288 node scripts/cli-e2e-test.js - name: yarn lint, test after plugin creation - with: - path: 'plugins/*' run: | yarn lint yarn test From a8038bac0842a3a1acd8c9b972217d74cb810740 Mon Sep 17 00:00:00 2001 From: Mateus Marquezini Date: Fri, 20 Mar 2020 13:51:51 -0300 Subject: [PATCH 07/10] added path to run lint and tests inside an specific folder --- .github/workflows/frontend.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index d56bebfad2..b5fd92e06a 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -41,6 +41,7 @@ jobs: sudo sysctl fs.inotify.max_user_watches=524288 node scripts/cli-e2e-test.js - name: yarn lint, test after plugin creation + working-directory: ./plugins/* run: | yarn lint yarn test From e0127c79a6d2f2caae0f6289bb1809b2e1f78a39 Mon Sep 17 00:00:00 2001 From: Mateus Marquezini Date: Fri, 20 Mar 2020 14:04:21 -0300 Subject: [PATCH 08/10] added path to run lint and tests inside an specific folder --- .github/workflows/frontend.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index b5fd92e06a..f2708eb2cb 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -41,7 +41,7 @@ jobs: sudo sysctl fs.inotify.max_user_watches=524288 node scripts/cli-e2e-test.js - name: yarn lint, test after plugin creation - working-directory: ./plugins/* + working-directory: /plugins run: | yarn lint yarn test From 32399cd7b69a17a062d726cd985eaa7fa0c3406e Mon Sep 17 00:00:00 2001 From: Mateus Marquezini Date: Fri, 20 Mar 2020 14:11:13 -0300 Subject: [PATCH 09/10] added path to run lint and tests inside an specific folder --- .github/workflows/frontend.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index f2708eb2cb..14e40f3a3c 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -41,7 +41,7 @@ jobs: sudo sysctl fs.inotify.max_user_watches=524288 node scripts/cli-e2e-test.js - name: yarn lint, test after plugin creation - working-directory: /plugins + working-directory: plugins run: | yarn lint yarn test From a6a757c9fe64c06031a5c0dbb2527299be2d1345 Mon Sep 17 00:00:00 2001 From: Mateus Marquezini Date: Fri, 20 Mar 2020 14:49:55 -0300 Subject: [PATCH 10/10] added path to run lint and tests inside an specific folder --- .github/workflows/frontend.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index 14e40f3a3c..599ad8a893 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -41,7 +41,7 @@ jobs: sudo sysctl fs.inotify.max_user_watches=524288 node scripts/cli-e2e-test.js - name: yarn lint, test after plugin creation - working-directory: plugins + working-directory: plugins/test-plugin run: | yarn lint yarn test