From ceb716c3b4c7df5b9cfb11845c75d0ea1377e1a7 Mon Sep 17 00:00:00 2001 From: Marcus Eide Date: Tue, 14 Apr 2020 08:55:07 +0200 Subject: [PATCH 01/18] Add create-app to e2e and move common functionality into seperate modules --- scripts/cli-e2e-test.js | 158 ++++++------------------------------ scripts/createTestApp.js | 41 ++++++++++ scripts/createTestPlugin.js | 44 ++++++++++ scripts/helpers.js | 137 +++++++++++++++++++++++++++++++ 4 files changed, 245 insertions(+), 135 deletions(-) create mode 100644 scripts/createTestApp.js create mode 100644 scripts/createTestPlugin.js create mode 100644 scripts/helpers.js diff --git a/scripts/cli-e2e-test.js b/scripts/cli-e2e-test.js index 48058550d9..e852f73ed0 100644 --- a/scripts/cli-e2e-test.js +++ b/scripts/cli-e2e-test.js @@ -15,11 +15,18 @@ */ const { resolve: resolvePath } = require('path'); -const childProcess = require('child_process'); -const { spawn } = childProcess; const Browser = require('zombie'); -const EXPECTED_LOAD_ERRORS = /ECONNREFUSED|ECONNRESET|did not get to load all resources/; +const { + spawnPiped, + handleError, + waitForPageWithText, + waitForExit, + print, +} = require('./helpers'); + +const createTestApp = require('./createTestApp'); +const createTestPlugin = require('./createTestPlugin'); Browser.localhost('localhost', 3000); @@ -29,154 +36,35 @@ async function main() { const projectDir = resolvePath(__dirname, '..'); process.chdir(projectDir); - const start = spawnPiped(['yarn', 'start']); + await createTestApp(); + + const appDir = resolvePath(projectDir, 'test-app'); + process.chdir(appDir); + + print('Starting the app'); + const startApp = spawnPiped(['yarn', 'start']); try { const browser = new Browser(); + await createTestPlugin(); await waitForPageWithText(browser, '/', 'Welcome to Backstage'); - print('Backstage loaded correctly, creating plugin'); - - const createPlugin = spawnPiped(['yarn', 'create-plugin']); - - let stdout = ''; - createPlugin.stdout.on('data', data => { - stdout = stdout + data.toString('utf8'); - }); - - await waitFor(() => stdout.includes('Enter an ID for the plugin')); - createPlugin.stdin.write('test-plugin\n'); - - await waitFor(() => stdout.includes('Enter the owner(s) of the plugin')); - createPlugin.stdin.write('@someuser\n'); - - print('Waiting for plugin create script to be done'); - await waitForExit(createPlugin); - - print('Plugin create script is done, waiting for plugin page to load'); await waitForPageWithText( browser, '/test-plugin', 'Welcome to test-plugin!', ); - print('Test plugin loaded correctly, exiting'); + print('Both App and Plugin loaded correctly'); } finally { - start.kill(); + startApp.kill(); } - await waitForExit(start); + await waitForExit(startApp); + + print('All tests done'); process.exit(0); } -function waitFor(fn) { - return new Promise(resolve => { - const handle = setInterval(() => { - if (fn()) { - clearInterval(handle); - resolve(); - return; - } - }, 100); - }); -} - -function print(msg) { - return process.stdout.write(`${msg}\n`); -} - -async function waitForExit(child) { - if (child.exitCode !== null) { - throw new Error(`Child already exited with code ${child.exitCode}`); - } - await new Promise((resolve, reject) => - child.once('exit', code => { - if (code) { - reject(new Error(`Child exited with code ${code}`)); - } else { - resolve(); - } - }), - ); -} - -function spawnPiped(cmd, options) { - function pipeWithPrefix(stream, prefix = '') { - return data => { - const prefixedMsg = data - .toString('utf8') - .trimRight() - .replace(/^/gm, prefix); - stream.write(`${prefixedMsg}\n`, 'utf8'); - }; - } - - const child = spawn(cmd[0], cmd.slice(1), { - stdio: 'pipe', - shell: true, - ...options, - }); - child.on('error', handleError); - child.on('exit', code => { - if (code) { - print(`Child '${cmd.join(' ')}' exited with code ${code}`); - process.exit(code); - } - }); - child.stdout.on( - 'data', - pipeWithPrefix(process.stdout, `[${cmd.join(' ')}].out: `), - ); - child.stderr.on( - 'data', - pipeWithPrefix(process.stderr, `[${cmd.join(' ')}].err: `), - ); - - return child; -} - -async function waitForPageWithText( - browser, - path, - text, - { intervalMs = 1000, maxAttempts = 120 } = {}, -) { - let attempts = 0; - for (;;) { - try { - await new Promise(resolve => setTimeout(resolve, intervalMs)); - await browser.visit(path); - break; - } catch (error) { - if (error.message.match(EXPECTED_LOAD_ERRORS)) { - attempts++; - if (attempts > maxAttempts) { - throw new Error( - `Failed to load page '${path}', max number of attempts reached`, - ); - } - } else { - throw error; - } - } - } - - const escapedText = text.replace(/"/g, '\\"'); - browser.assert.evaluate( - `Array.from(document.querySelectorAll("*")).some(el => el.textContent === "${escapedText}")`, - true, - `expected to find text ${text}`, - ); -} - -function handleError(err) { - process.stdout.write(`${err.name}: ${err.stack || err.message}\n`); - if (typeof err.code === 'number') { - process.exit(err.code); - } else { - process.exit(1); - } -} - process.on('unhandledRejection', handleError); main(process.argv.slice(2)).catch(handleError); diff --git a/scripts/createTestApp.js b/scripts/createTestApp.js new file mode 100644 index 0000000000..89fa023436 --- /dev/null +++ b/scripts/createTestApp.js @@ -0,0 +1,41 @@ +/* + * 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. + */ + +const { spawnPiped, waitFor, waitForExit, print } = require('./helpers'); + +async function createTestApp() { + print('Creating a Backstage App'); + const createApp = spawnPiped(['yarn', 'create-app']); + + try { + let stdout = ''; + createApp.stdout.on('data', data => { + stdout = stdout + data.toString('utf8'); + }); + + await waitFor(() => stdout.includes('Enter a name for the app')); + createApp.stdin.write('test-app\n'); + + print('Waiting for app create script to be done'); + await waitForExit(createApp); + + print('Test app created'); + } finally { + createApp.kill(); + } +} + +module.exports = createTestApp; diff --git a/scripts/createTestPlugin.js b/scripts/createTestPlugin.js new file mode 100644 index 0000000000..c204067ae3 --- /dev/null +++ b/scripts/createTestPlugin.js @@ -0,0 +1,44 @@ +/* + * 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. + */ + +const { spawnPiped, waitFor, waitForExit, print } = require('./helpers'); + +async function createTestPlugin() { + print('Creating a Backstage Plugin'); + const createPlugin = spawnPiped(['yarn', 'create-plugin']); + + try { + let stdout = ''; + createPlugin.stdout.on('data', data => { + stdout = stdout + data.toString('utf8'); + }); + + await waitFor(() => stdout.includes('Enter an ID for the plugin')); + createPlugin.stdin.write('test-plugin\n'); + + await waitFor(() => stdout.includes('Enter the owner(s) of the plugin')); + createPlugin.stdin.write('@someuser\n'); + + print('Waiting for plugin create script to be done'); + await waitForExit(createPlugin); + + print('Test plugin created'); + } finally { + createPlugin.kill(); + } +} + +module.exports = createTestPlugin; diff --git a/scripts/helpers.js b/scripts/helpers.js new file mode 100644 index 0000000000..7ad1bedfd5 --- /dev/null +++ b/scripts/helpers.js @@ -0,0 +1,137 @@ +/* + * 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. + */ + +const childProcess = require('child_process'); +const { spawn } = childProcess; + +const EXPECTED_LOAD_ERRORS = /ECONNREFUSED|ECONNRESET|did not get to load all resources/; + +function spawnPiped(cmd, options) { + function pipeWithPrefix(stream, prefix = '') { + return data => { + const prefixedMsg = data + .toString('utf8') + .trimRight() + .replace(/^/gm, prefix); + stream.write(`${prefixedMsg}\n`, 'utf8'); + }; + } + + const child = spawn(cmd[0], cmd.slice(1), { + stdio: 'pipe', + shell: true, + ...options, + }); + child.on('error', handleError); + child.on('exit', code => { + if (code) { + print(`Child '${cmd.join(' ')}' exited with code ${code}`); + process.exit(code); + } + }); + child.stdout.on( + 'data', + pipeWithPrefix(process.stdout, `[${cmd.join(' ')}].out: `), + ); + child.stderr.on( + 'data', + pipeWithPrefix(process.stderr, `[${cmd.join(' ')}].err: `), + ); + + return child; +} + +function handleError(err) { + process.stdout.write(`${err.name}: ${err.stack || err.message}\n`); + if (typeof err.code === 'number') { + process.exit(err.code); + } else { + process.exit(1); + } +} + +function waitFor(fn) { + return new Promise(resolve => { + const handle = setInterval(() => { + if (fn()) { + clearInterval(handle); + resolve(); + return; + } + }, 100); + }); +} + +async function waitForExit(child) { + if (child.exitCode !== null) { + throw new Error(`Child already exited with code ${child.exitCode}`); + } + await new Promise((resolve, reject) => + child.once('exit', code => { + if (code) { + reject(new Error(`Child exited with code ${code}`)); + } else { + print('Child finished'); + resolve(); + } + }), + ); +} + +async function waitForPageWithText( + browser, + path, + text, + { intervalMs = 1000, maxAttempts = 240 } = {}, +) { + let attempts = 0; + for (;;) { + try { + await new Promise(resolve => setTimeout(resolve, intervalMs)); + await browser.visit(path); + break; + } catch (error) { + if (error.message.match(EXPECTED_LOAD_ERRORS)) { + attempts++; + if (attempts > maxAttempts) { + throw new Error( + `Failed to load page '${path}', max number of attempts reached`, + ); + } + } else { + throw error; + } + } + } + + const escapedText = text.replace(/"/g, '\\"'); + browser.assert.evaluate( + `Array.from(document.querySelectorAll("*")).some(el => el.textContent === "${escapedText}")`, + true, + `expected to find text ${text}`, + ); +} + +function print(msg) { + return process.stdout.write(`${msg}\n`); +} + +module.exports.spawnPiped = spawnPiped; +module.exports.handleError = handleError; +module.exports.waitFor = waitFor; +module.exports.waitForExit = waitForExit; +module.exports.waitForPageWithText = waitForPageWithText; +module.exports.print = print; From ca2ccb314524e36cbd00b98a2b2fbd0e949354b6 Mon Sep 17 00:00:00 2001 From: Marcus Eide Date: Tue, 14 Apr 2020 09:14:26 +0200 Subject: [PATCH 02/18] Modify cli workflow --- .github/workflows/cli.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/cli.yml b/.github/workflows/cli.yml index d571703294..44a18f10da 100644 --- a/.github/workflows/cli.yml +++ b/.github/workflows/cli.yml @@ -6,6 +6,7 @@ on: - '.github/workflows/cli.yml' - 'packages/cli/**' - 'packages/core/**' + - 'scripts/**' jobs: build: @@ -40,17 +41,18 @@ jobs: - name: yarn install run: yarn install --frozen-lockfile - run: yarn build - # This creates a new plugin and pollutes the workspace, so it should be run last. - - name: verify app serve and plugin creation on Windows + # This creates a new app and plugin which pollutes the workspace, so it should be run last. + - name: verify app and plugin creation on Windows if: runner.os == 'Windows' run: node scripts/cli-e2e-test.js - - name: verify app serve and plugin creation on Linux + - name: verify app and plugin creation on Linux if: runner.os == 'Linux' run: | sudo sysctl fs.inotify.max_user_watches=524288 node scripts/cli-e2e-test.js - - name: yarn lint, test after plugin creation - working-directory: plugins/test-plugin + # This should lint and test both an app and a plugin + - name: yarn lint, test after creation + working-directory: test-app run: | yarn lint yarn test From ce53096b5c99f4e843c4d584666cbed61fa19da9 Mon Sep 17 00:00:00 2001 From: Marcus Eide Date: Tue, 14 Apr 2020 09:20:46 +0200 Subject: [PATCH 03/18] Add create-app yarn command to package.json --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 0387a4e7ce..64f5765312 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "lint:all": "lerna run lint --", "docker-build": "yarn bundle && docker build . -t spotify/backstage", "create-plugin": "backstage-cli create-plugin", + "create-app": "backstage-cli create-app", "release": "if [ \"$(git symbolic-ref --short HEAD)\" = master ]; then echo \"don't try to release master\"; exit 1; else lerna version --no-push; fi", "lerna": "lerna", "storybook": "yarn workspace storybook start" From fbc2048350c3a199e503ec3316b1fce8663821e3 Mon Sep 17 00:00:00 2001 From: Marcus Eide Date: Tue, 14 Apr 2020 12:54:13 +0200 Subject: [PATCH 04/18] Add copyright notice to default-app template files --- .../default-app/packages/app/src/App.test.tsx | 16 ++++++++++++++++ .../default-app/packages/app/src/App.tsx | 16 ++++++++++++++++ .../default-app/packages/app/src/index.tsx | 16 ++++++++++++++++ .../default-app/packages/app/src/plugins.ts | 16 ++++++++++++++++ .../default-app/packages/app/src/setupTests.ts | 16 ++++++++++++++++ .../welcome/src/components/Timer/Timer.tsx | 16 ++++++++++++++++ .../welcome/src/components/Timer/index.ts | 16 ++++++++++++++++ .../components/WelcomePage/WelcomePage.test.tsx | 16 ++++++++++++++++ .../src/components/WelcomePage/WelcomePage.tsx | 16 ++++++++++++++++ .../welcome/src/components/WelcomePage/index.ts | 16 ++++++++++++++++ .../default-app/plugins/welcome/src/index.ts | 16 ++++++++++++++++ .../plugins/welcome/src/plugin.test.ts | 16 ++++++++++++++++ .../default-app/plugins/welcome/src/plugin.ts | 16 ++++++++++++++++ .../plugins/welcome/src/setupTests.ts | 16 ++++++++++++++++ 14 files changed, 224 insertions(+) diff --git a/packages/cli/templates/default-app/packages/app/src/App.test.tsx b/packages/cli/templates/default-app/packages/app/src/App.test.tsx index 0074416375..ace8f42f45 100644 --- a/packages/cli/templates/default-app/packages/app/src/App.test.tsx +++ b/packages/cli/templates/default-app/packages/app/src/App.test.tsx @@ -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 React from 'react'; import { render } from '@testing-library/react'; import App from './App'; diff --git a/packages/cli/templates/default-app/packages/app/src/App.tsx b/packages/cli/templates/default-app/packages/app/src/App.tsx index ec8d8d435a..ea318c6721 100644 --- a/packages/cli/templates/default-app/packages/app/src/App.tsx +++ b/packages/cli/templates/default-app/packages/app/src/App.tsx @@ -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 { CssBaseline, makeStyles, ThemeProvider } from '@material-ui/core'; import { createApp } from '@backstage/core'; import { BackstageTheme } from '@backstage/theme'; diff --git a/packages/cli/templates/default-app/packages/app/src/index.tsx b/packages/cli/templates/default-app/packages/app/src/index.tsx index b597a44232..2ea8d3f1dd 100644 --- a/packages/cli/templates/default-app/packages/app/src/index.tsx +++ b/packages/cli/templates/default-app/packages/app/src/index.tsx @@ -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 React from 'react'; import ReactDOM from 'react-dom'; import App from './App'; diff --git a/packages/cli/templates/default-app/packages/app/src/plugins.ts b/packages/cli/templates/default-app/packages/app/src/plugins.ts index 000bd79f3e..ba7b721672 100644 --- a/packages/cli/templates/default-app/packages/app/src/plugins.ts +++ b/packages/cli/templates/default-app/packages/app/src/plugins.ts @@ -1 +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 as WelcomePlugin } from 'plugin-welcome'; diff --git a/packages/cli/templates/default-app/packages/app/src/setupTests.ts b/packages/cli/templates/default-app/packages/app/src/setupTests.ts index 666127af39..8925258421 100644 --- a/packages/cli/templates/default-app/packages/app/src/setupTests.ts +++ b/packages/cli/templates/default-app/packages/app/src/setupTests.ts @@ -1 +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. + */ + import '@testing-library/jest-dom/extend-expect'; diff --git a/packages/cli/templates/default-app/plugins/welcome/src/components/Timer/Timer.tsx b/packages/cli/templates/default-app/plugins/welcome/src/components/Timer/Timer.tsx index 24c79f91ee..770f98e762 100644 --- a/packages/cli/templates/default-app/plugins/welcome/src/components/Timer/Timer.tsx +++ b/packages/cli/templates/default-app/plugins/welcome/src/components/Timer/Timer.tsx @@ -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 React, { FC } from 'react'; import { HeaderLabel } from '@backstage/core'; diff --git a/packages/cli/templates/default-app/plugins/welcome/src/components/Timer/index.ts b/packages/cli/templates/default-app/plugins/welcome/src/components/Timer/index.ts index f1fc55bfe9..a67293c20e 100644 --- a/packages/cli/templates/default-app/plugins/welcome/src/components/Timer/index.ts +++ b/packages/cli/templates/default-app/plugins/welcome/src/components/Timer/index.ts @@ -1 +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 './Timer'; diff --git a/packages/cli/templates/default-app/plugins/welcome/src/components/WelcomePage/WelcomePage.test.tsx b/packages/cli/templates/default-app/plugins/welcome/src/components/WelcomePage/WelcomePage.test.tsx index 6d9268fadd..0bf0b2135f 100644 --- a/packages/cli/templates/default-app/plugins/welcome/src/components/WelcomePage/WelcomePage.test.tsx +++ b/packages/cli/templates/default-app/plugins/welcome/src/components/WelcomePage/WelcomePage.test.tsx @@ -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 React from 'react'; import { render } from '@testing-library/react'; import WelcomePage from './WelcomePage'; diff --git a/packages/cli/templates/default-app/plugins/welcome/src/components/WelcomePage/WelcomePage.tsx b/packages/cli/templates/default-app/plugins/welcome/src/components/WelcomePage/WelcomePage.tsx index d9ef0524c6..feafaa0ade 100644 --- a/packages/cli/templates/default-app/plugins/welcome/src/components/WelcomePage/WelcomePage.tsx +++ b/packages/cli/templates/default-app/plugins/welcome/src/components/WelcomePage/WelcomePage.tsx @@ -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 React, { FC } from 'react'; import { Link as RouterLink } from 'react-router-dom'; import { diff --git a/packages/cli/templates/default-app/plugins/welcome/src/components/WelcomePage/index.ts b/packages/cli/templates/default-app/plugins/welcome/src/components/WelcomePage/index.ts index b031301e7e..fcdde9d498 100644 --- a/packages/cli/templates/default-app/plugins/welcome/src/components/WelcomePage/index.ts +++ b/packages/cli/templates/default-app/plugins/welcome/src/components/WelcomePage/index.ts @@ -1 +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 './WelcomePage'; diff --git a/packages/cli/templates/default-app/plugins/welcome/src/index.ts b/packages/cli/templates/default-app/plugins/welcome/src/index.ts index 99edba26c3..3a0a0fe2d3 100644 --- a/packages/cli/templates/default-app/plugins/welcome/src/index.ts +++ b/packages/cli/templates/default-app/plugins/welcome/src/index.ts @@ -1 +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-app/plugins/welcome/src/plugin.test.ts b/packages/cli/templates/default-app/plugins/welcome/src/plugin.test.ts index f5bf8e68c3..d60c73ec68 100644 --- a/packages/cli/templates/default-app/plugins/welcome/src/plugin.test.ts +++ b/packages/cli/templates/default-app/plugins/welcome/src/plugin.test.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. + */ + import { plugin } from './plugin'; describe('welcome', () => { diff --git a/packages/cli/templates/default-app/plugins/welcome/src/plugin.ts b/packages/cli/templates/default-app/plugins/welcome/src/plugin.ts index a65fad5348..addf4c8c34 100644 --- a/packages/cli/templates/default-app/plugins/welcome/src/plugin.ts +++ b/packages/cli/templates/default-app/plugins/welcome/src/plugin.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. + */ + import { createPlugin } from '@backstage/core'; import WelcomePage from './components/WelcomePage'; diff --git a/packages/cli/templates/default-app/plugins/welcome/src/setupTests.ts b/packages/cli/templates/default-app/plugins/welcome/src/setupTests.ts index 666127af39..8925258421 100644 --- a/packages/cli/templates/default-app/plugins/welcome/src/setupTests.ts +++ b/packages/cli/templates/default-app/plugins/welcome/src/setupTests.ts @@ -1 +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. + */ + import '@testing-library/jest-dom/extend-expect'; From ce950bed7aa5b6e68093e9d30fde472cf39f637c Mon Sep 17 00:00:00 2001 From: Marcus Eide Date: Tue, 14 Apr 2020 14:13:58 +0200 Subject: [PATCH 05/18] Add exit() method to Task and use in create-app and create-plugin --- packages/cli/src/commands/create-app/createApp.ts | 2 ++ packages/cli/src/commands/create-plugin/createPlugin.ts | 2 ++ packages/cli/src/helpers/tasks.ts | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/packages/cli/src/commands/create-app/createApp.ts b/packages/cli/src/commands/create-app/createApp.ts index 5863d9e705..b596d9ac73 100644 --- a/packages/cli/src/commands/create-app/createApp.ts +++ b/packages/cli/src/commands/create-app/createApp.ts @@ -134,6 +134,7 @@ export default async () => { chalk.green(`🥇 Successfully created ${chalk.cyan(answers.name)}`), ); Task.log(); + Task.exit(); } catch (error) { Task.error(error.message); @@ -143,5 +144,6 @@ export default async () => { Task.section('Cleanup'); await cleanUp(tempDir); Task.error('🔥 Failed to create app!'); + Task.exit(1); } }; diff --git a/packages/cli/src/commands/create-plugin/createPlugin.ts b/packages/cli/src/commands/create-plugin/createPlugin.ts index df8b71f619..51f749a6ac 100644 --- a/packages/cli/src/commands/create-plugin/createPlugin.ts +++ b/packages/cli/src/commands/create-plugin/createPlugin.ts @@ -268,6 +268,7 @@ export default async () => { )}`, ); Task.log(); + Task.exit(); } catch (error) { Task.error(error.message); @@ -277,5 +278,6 @@ export default async () => { Task.section('Cleanup'); await cleanUp(tempDir); Task.error('🔥 Failed to create plugin!'); + Task.exit(1); } }; diff --git a/packages/cli/src/helpers/tasks.ts b/packages/cli/src/helpers/tasks.ts index 3cba4d262f..0753301b78 100644 --- a/packages/cli/src/helpers/tasks.ts +++ b/packages/cli/src/helpers/tasks.ts @@ -37,6 +37,10 @@ export class Task { process.stdout.write(`\n ${title}\n`); } + static exit(code: number = 0) { + process.exit(code); + } + static async forItem( task: string, item: string, From 300a891f71f369662bc58e35271fb43e9db07260 Mon Sep 17 00:00:00 2001 From: Marcus Eide Date: Wed, 15 Apr 2020 14:58:20 +0200 Subject: [PATCH 06/18] Create new app in temp dir --- .github/workflows/cli.yml | 14 ++++++--- packages/cli/bin/backstage-cli | 6 +++- .../cli/src/commands/build-cache/index.ts | 2 +- .../cli/src/commands/plugin/rollup.config.ts | 1 + .../templates/default-app/package.json.hbs | 3 ++ .../default-app/packages/app/package.json.hbs | 4 ++- scripts/cli-e2e-test.js | 23 ++++++++++---- scripts/createTestApp.js | 4 +-- scripts/createTestPlugin.js | 4 +-- scripts/generateTempDir.js | 30 +++++++++++++++++++ 10 files changed, 74 insertions(+), 17 deletions(-) create mode 100644 scripts/generateTempDir.js diff --git a/.github/workflows/cli.yml b/.github/workflows/cli.yml index 44a18f10da..6b32834ebd 100644 --- a/.github/workflows/cli.yml +++ b/.github/workflows/cli.yml @@ -41,18 +41,24 @@ jobs: - name: yarn install run: yarn install --frozen-lockfile - run: yarn build - # This creates a new app and plugin which pollutes the workspace, so it should be run last. + # generate temp directory + - name: generate tempdir + id: generate_tempdir + run: echo ::set-output name=tempdir::$(node scripts/generateTempDir.js) + # This creates a new app and plugin which pollutes the workspace, so it should be run last. - name: verify app and plugin creation on Windows + working-directory: ${{ steps.generate_tempdir.outputs.tempdir }} if: runner.os == 'Windows' - run: node scripts/cli-e2e-test.js + run: node ${{ github.workspace }}/scripts/cli-e2e-test.js - name: verify app and plugin creation on Linux + working-directory: ${{ steps.generate_tempdir.outputs.tempdir }} if: runner.os == 'Linux' run: | sudo sysctl fs.inotify.max_user_watches=524288 - node scripts/cli-e2e-test.js + node ${{ github.workspace }}/scripts/cli-e2e-test.js # This should lint and test both an app and a plugin - name: yarn lint, test after creation - working-directory: test-app + working-directory: ${{ steps.generate_tempdir.outputs.tempdir }}/test-app run: | yarn lint yarn test diff --git a/packages/cli/bin/backstage-cli b/packages/cli/bin/backstage-cli index a8ba74f28a..1cdf8c81af 100755 --- a/packages/cli/bin/backstage-cli +++ b/packages/cli/bin/backstage-cli @@ -19,7 +19,11 @@ const path = require('path'); // Figure out whether we're running inside the backstage repo or as an installed dependency const isLocal = require('fs').existsSync(path.resolve(__dirname, '../src')); -if (!isLocal) { + +// This is used for e2e-tests where we create a new app in a tmp folder +const isTemp = path.resolve(__dirname).includes(require('os').tmpdir()); + +if (!isLocal || isTemp || process.env.E2E) { // src-relative imports are a pain to get to work with plain tsc compilation, as the // transpiled code will maintain the imports as they are in the source. Which means an // import for `helpers/paths` will start like that in the output, which won't work in NodeJS. diff --git a/packages/cli/src/commands/build-cache/index.ts b/packages/cli/src/commands/build-cache/index.ts index a8a1a27e9d..368fac2593 100644 --- a/packages/cli/src/commands/build-cache/index.ts +++ b/packages/cli/src/commands/build-cache/index.ts @@ -30,7 +30,7 @@ export async function withCache( buildFunc: () => Promise, ): Promise { const key = await Cache.readInputKey(options.inputs); - if (!key) { + if (!key || process.env.E2E) { print('input directory is dirty, skipping cache'); await fs.remove(options.output); await buildFunc(); diff --git a/packages/cli/src/commands/plugin/rollup.config.ts b/packages/cli/src/commands/plugin/rollup.config.ts index fe2675e0e0..c991fa3efb 100644 --- a/packages/cli/src/commands/plugin/rollup.config.ts +++ b/packages/cli/src/commands/plugin/rollup.config.ts @@ -46,6 +46,7 @@ export default { json(), typescript({ include: `${paths.resolveTarget('src')}/**/*.{js,jsx,ts,tsx}`, + clean: true, }), ], } as RollupWatchOptions; diff --git a/packages/cli/templates/default-app/package.json.hbs b/packages/cli/templates/default-app/package.json.hbs index 7b5fab5221..5161e85fe0 100644 --- a/packages/cli/templates/default-app/package.json.hbs +++ b/packages/cli/templates/default-app/package.json.hbs @@ -25,5 +25,8 @@ "@backstage/cli": "^{{version}}", "lerna": "^3.20.2", "prettier": "^1.19.1" + }, + "resolutions": { + "@backstage/cli": "file:/home/runner/work/backstage/backstage/packages/cli" } } diff --git a/packages/cli/templates/default-app/packages/app/package.json.hbs b/packages/cli/templates/default-app/packages/app/package.json.hbs index a5b2b07b96..940091380a 100644 --- a/packages/cli/templates/default-app/packages/app/package.json.hbs +++ b/packages/cli/templates/default-app/packages/app/package.json.hbs @@ -5,6 +5,7 @@ "dependencies": { "@material-ui/core": "^4.9.1", "@material-ui/icons": "^4.9.1", + "@material-ui/lab": "4.0.0-alpha.45", "@backstage/cli": "^{{version}}", "@backstage/core": "^{{version}}", "@backstage/theme": "^{{version}}", @@ -17,7 +18,8 @@ "plugin-welcome": "0.0.0", "react": "^16.12.0", "react-dom": "^16.12.0", - "react-router-dom": "^5.1.2" + "react-router-dom": "^5.1.2", + "react-use": "^13.24.0" }, "scripts": { "start": "backstage-cli app:serve", diff --git a/scripts/cli-e2e-test.js b/scripts/cli-e2e-test.js index e852f73ed0..814d2d6f60 100644 --- a/scripts/cli-e2e-test.js +++ b/scripts/cli-e2e-test.js @@ -27,27 +27,38 @@ const { const createTestApp = require('./createTestApp'); const createTestPlugin = require('./createTestPlugin'); +const generateTempDir = require('./generateTempDir.js'); Browser.localhost('localhost', 3000); async function main() { - process.env.CI = 'true'; + process.env.E2E = 'true'; - const projectDir = resolvePath(__dirname, '..'); - process.chdir(projectDir); + const rootDir = process.env.CI + ? resolvePath(process.env.GITHUB_WORKSPACE) + : resolvePath(__dirname, '..'); - await createTestApp(); + const tempDir = process.env.CI + ? resolvePath(__dirname) + : await generateTempDir(); - const appDir = resolvePath(projectDir, 'test-app'); + process.chdir(tempDir); + await waitForExit(spawnPiped(['yarn', 'init --yes'])); + + const createAppCmd = `${rootDir}/packages/cli/bin/backstage-cli create-app`; + await createTestApp(createAppCmd); + + const appDir = resolvePath(tempDir, 'test-app'); process.chdir(appDir); + await createTestPlugin(); + print('Starting the app'); const startApp = spawnPiped(['yarn', 'start']); try { const browser = new Browser(); - await createTestPlugin(); await waitForPageWithText(browser, '/', 'Welcome to Backstage'); await waitForPageWithText( browser, diff --git a/scripts/createTestApp.js b/scripts/createTestApp.js index 89fa023436..80f7bf3b18 100644 --- a/scripts/createTestApp.js +++ b/scripts/createTestApp.js @@ -16,9 +16,9 @@ const { spawnPiped, waitFor, waitForExit, print } = require('./helpers'); -async function createTestApp() { +async function createTestApp(cmd) { print('Creating a Backstage App'); - const createApp = spawnPiped(['yarn', 'create-app']); + const createApp = spawnPiped(['node', cmd]); try { let stdout = ''; diff --git a/scripts/createTestPlugin.js b/scripts/createTestPlugin.js index c204067ae3..59e8d6dd77 100644 --- a/scripts/createTestPlugin.js +++ b/scripts/createTestPlugin.js @@ -29,8 +29,8 @@ async function createTestPlugin() { await waitFor(() => stdout.includes('Enter an ID for the plugin')); createPlugin.stdin.write('test-plugin\n'); - await waitFor(() => stdout.includes('Enter the owner(s) of the plugin')); - createPlugin.stdin.write('@someuser\n'); + // await waitFor(() => stdout.includes('Enter the owner(s) of the plugin')); + // createPlugin.stdin.write('@someuser\n'); print('Waiting for plugin create script to be done'); await waitForExit(createPlugin); diff --git a/scripts/generateTempDir.js b/scripts/generateTempDir.js new file mode 100644 index 0000000000..e455a29320 --- /dev/null +++ b/scripts/generateTempDir.js @@ -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. + */ + +const { handleError } = require('./helpers'); + +async function generateTempDir() { + const tempDir = await require('fs-extra').mkdtemp( + require('path').join(require('os').tmpdir(), 'backstage-e2e-'), + ); + process.stdout.write(tempDir); + return tempDir; +} + +module.exports = generateTempDir; + +process.on('unhandledRejection', handleError); +generateTempDir().catch(handleError); From 06150f7094f8af67a6283007c1f473b37edb7532 Mon Sep 17 00:00:00 2001 From: Marcus Eide Date: Thu, 16 Apr 2020 08:53:19 +0200 Subject: [PATCH 07/18] Remove yarn create-app from package.json --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 64f5765312..0387a4e7ce 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,6 @@ "lint:all": "lerna run lint --", "docker-build": "yarn bundle && docker build . -t spotify/backstage", "create-plugin": "backstage-cli create-plugin", - "create-app": "backstage-cli create-app", "release": "if [ \"$(git symbolic-ref --short HEAD)\" = master ]; then echo \"don't try to release master\"; exit 1; else lerna version --no-push; fi", "lerna": "lerna", "storybook": "yarn workspace storybook start" From 85752b4795f979503b6c88dee88b52b152512f51 Mon Sep 17 00:00:00 2001 From: Marcus Eide Date: Thu, 16 Apr 2020 08:53:55 +0200 Subject: [PATCH 08/18] Revert "Add copyright notice to default-app template files" This reverts commit fbc2048350c3a199e503ec3316b1fce8663821e3. --- .../default-app/packages/app/src/App.test.tsx | 16 ---------------- .../default-app/packages/app/src/App.tsx | 16 ---------------- .../default-app/packages/app/src/index.tsx | 16 ---------------- .../default-app/packages/app/src/plugins.ts | 16 ---------------- .../default-app/packages/app/src/setupTests.ts | 16 ---------------- .../welcome/src/components/Timer/Timer.tsx | 16 ---------------- .../welcome/src/components/Timer/index.ts | 16 ---------------- .../components/WelcomePage/WelcomePage.test.tsx | 16 ---------------- .../src/components/WelcomePage/WelcomePage.tsx | 16 ---------------- .../welcome/src/components/WelcomePage/index.ts | 16 ---------------- .../default-app/plugins/welcome/src/index.ts | 16 ---------------- .../plugins/welcome/src/plugin.test.ts | 16 ---------------- .../default-app/plugins/welcome/src/plugin.ts | 16 ---------------- .../plugins/welcome/src/setupTests.ts | 16 ---------------- 14 files changed, 224 deletions(-) diff --git a/packages/cli/templates/default-app/packages/app/src/App.test.tsx b/packages/cli/templates/default-app/packages/app/src/App.test.tsx index ace8f42f45..0074416375 100644 --- a/packages/cli/templates/default-app/packages/app/src/App.test.tsx +++ b/packages/cli/templates/default-app/packages/app/src/App.test.tsx @@ -1,19 +1,3 @@ -/* - * 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 App from './App'; diff --git a/packages/cli/templates/default-app/packages/app/src/App.tsx b/packages/cli/templates/default-app/packages/app/src/App.tsx index ea318c6721..ec8d8d435a 100644 --- a/packages/cli/templates/default-app/packages/app/src/App.tsx +++ b/packages/cli/templates/default-app/packages/app/src/App.tsx @@ -1,19 +1,3 @@ -/* - * 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 { CssBaseline, makeStyles, ThemeProvider } from '@material-ui/core'; import { createApp } from '@backstage/core'; import { BackstageTheme } from '@backstage/theme'; diff --git a/packages/cli/templates/default-app/packages/app/src/index.tsx b/packages/cli/templates/default-app/packages/app/src/index.tsx index 2ea8d3f1dd..b597a44232 100644 --- a/packages/cli/templates/default-app/packages/app/src/index.tsx +++ b/packages/cli/templates/default-app/packages/app/src/index.tsx @@ -1,19 +1,3 @@ -/* - * 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 ReactDOM from 'react-dom'; import App from './App'; diff --git a/packages/cli/templates/default-app/packages/app/src/plugins.ts b/packages/cli/templates/default-app/packages/app/src/plugins.ts index ba7b721672..000bd79f3e 100644 --- a/packages/cli/templates/default-app/packages/app/src/plugins.ts +++ b/packages/cli/templates/default-app/packages/app/src/plugins.ts @@ -1,17 +1 @@ -/* - * 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 as WelcomePlugin } from 'plugin-welcome'; diff --git a/packages/cli/templates/default-app/packages/app/src/setupTests.ts b/packages/cli/templates/default-app/packages/app/src/setupTests.ts index 8925258421..666127af39 100644 --- a/packages/cli/templates/default-app/packages/app/src/setupTests.ts +++ b/packages/cli/templates/default-app/packages/app/src/setupTests.ts @@ -1,17 +1 @@ -/* - * 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/extend-expect'; diff --git a/packages/cli/templates/default-app/plugins/welcome/src/components/Timer/Timer.tsx b/packages/cli/templates/default-app/plugins/welcome/src/components/Timer/Timer.tsx index 770f98e762..24c79f91ee 100644 --- a/packages/cli/templates/default-app/plugins/welcome/src/components/Timer/Timer.tsx +++ b/packages/cli/templates/default-app/plugins/welcome/src/components/Timer/Timer.tsx @@ -1,19 +1,3 @@ -/* - * 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 { HeaderLabel } from '@backstage/core'; diff --git a/packages/cli/templates/default-app/plugins/welcome/src/components/Timer/index.ts b/packages/cli/templates/default-app/plugins/welcome/src/components/Timer/index.ts index a67293c20e..f1fc55bfe9 100644 --- a/packages/cli/templates/default-app/plugins/welcome/src/components/Timer/index.ts +++ b/packages/cli/templates/default-app/plugins/welcome/src/components/Timer/index.ts @@ -1,17 +1 @@ -/* - * 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 './Timer'; diff --git a/packages/cli/templates/default-app/plugins/welcome/src/components/WelcomePage/WelcomePage.test.tsx b/packages/cli/templates/default-app/plugins/welcome/src/components/WelcomePage/WelcomePage.test.tsx index 0bf0b2135f..6d9268fadd 100644 --- a/packages/cli/templates/default-app/plugins/welcome/src/components/WelcomePage/WelcomePage.test.tsx +++ b/packages/cli/templates/default-app/plugins/welcome/src/components/WelcomePage/WelcomePage.test.tsx @@ -1,19 +1,3 @@ -/* - * 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 WelcomePage from './WelcomePage'; diff --git a/packages/cli/templates/default-app/plugins/welcome/src/components/WelcomePage/WelcomePage.tsx b/packages/cli/templates/default-app/plugins/welcome/src/components/WelcomePage/WelcomePage.tsx index feafaa0ade..d9ef0524c6 100644 --- a/packages/cli/templates/default-app/plugins/welcome/src/components/WelcomePage/WelcomePage.tsx +++ b/packages/cli/templates/default-app/plugins/welcome/src/components/WelcomePage/WelcomePage.tsx @@ -1,19 +1,3 @@ -/* - * 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 { Link as RouterLink } from 'react-router-dom'; import { diff --git a/packages/cli/templates/default-app/plugins/welcome/src/components/WelcomePage/index.ts b/packages/cli/templates/default-app/plugins/welcome/src/components/WelcomePage/index.ts index fcdde9d498..b031301e7e 100644 --- a/packages/cli/templates/default-app/plugins/welcome/src/components/WelcomePage/index.ts +++ b/packages/cli/templates/default-app/plugins/welcome/src/components/WelcomePage/index.ts @@ -1,17 +1 @@ -/* - * 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 './WelcomePage'; diff --git a/packages/cli/templates/default-app/plugins/welcome/src/index.ts b/packages/cli/templates/default-app/plugins/welcome/src/index.ts index 3a0a0fe2d3..99edba26c3 100644 --- a/packages/cli/templates/default-app/plugins/welcome/src/index.ts +++ b/packages/cli/templates/default-app/plugins/welcome/src/index.ts @@ -1,17 +1 @@ -/* - * 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-app/plugins/welcome/src/plugin.test.ts b/packages/cli/templates/default-app/plugins/welcome/src/plugin.test.ts index d60c73ec68..f5bf8e68c3 100644 --- a/packages/cli/templates/default-app/plugins/welcome/src/plugin.test.ts +++ b/packages/cli/templates/default-app/plugins/welcome/src/plugin.test.ts @@ -1,19 +1,3 @@ -/* - * 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('welcome', () => { diff --git a/packages/cli/templates/default-app/plugins/welcome/src/plugin.ts b/packages/cli/templates/default-app/plugins/welcome/src/plugin.ts index addf4c8c34..a65fad5348 100644 --- a/packages/cli/templates/default-app/plugins/welcome/src/plugin.ts +++ b/packages/cli/templates/default-app/plugins/welcome/src/plugin.ts @@ -1,19 +1,3 @@ -/* - * 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 '@backstage/core'; import WelcomePage from './components/WelcomePage'; diff --git a/packages/cli/templates/default-app/plugins/welcome/src/setupTests.ts b/packages/cli/templates/default-app/plugins/welcome/src/setupTests.ts index 8925258421..666127af39 100644 --- a/packages/cli/templates/default-app/plugins/welcome/src/setupTests.ts +++ b/packages/cli/templates/default-app/plugins/welcome/src/setupTests.ts @@ -1,17 +1 @@ -/* - * 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/extend-expect'; From ed32b1d161f99f161ed8db738c324551f83239cd Mon Sep 17 00:00:00 2001 From: Marcus Eide Date: Thu, 16 Apr 2020 09:07:02 +0200 Subject: [PATCH 09/18] Properly change to temp directory --- .github/workflows/cli.yml | 2 ++ scripts/cli-e2e-test.js | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cli.yml b/.github/workflows/cli.yml index 6b32834ebd..8b056a7772 100644 --- a/.github/workflows/cli.yml +++ b/.github/workflows/cli.yml @@ -60,6 +60,8 @@ jobs: - name: yarn lint, test after creation working-directory: ${{ steps.generate_tempdir.outputs.tempdir }}/test-app run: | + pwd + ls -la yarn lint yarn test env: diff --git a/scripts/cli-e2e-test.js b/scripts/cli-e2e-test.js index 814d2d6f60..934585bee5 100644 --- a/scripts/cli-e2e-test.js +++ b/scripts/cli-e2e-test.js @@ -38,9 +38,7 @@ async function main() { ? resolvePath(process.env.GITHUB_WORKSPACE) : resolvePath(__dirname, '..'); - const tempDir = process.env.CI - ? resolvePath(__dirname) - : await generateTempDir(); + const tempDir = process.env.CI ? process.cwd() : await generateTempDir(); process.chdir(tempDir); await waitForExit(spawnPiped(['yarn', 'init --yes'])); From 432a2a3c31e508d74576368ca0af9e9ba9292e7e Mon Sep 17 00:00:00 2001 From: Marcus Eide Date: Thu, 16 Apr 2020 10:15:17 +0200 Subject: [PATCH 10/18] Use :all flags for lint and test to not depend on git since --- .github/workflows/cli.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/cli.yml b/.github/workflows/cli.yml index 8b056a7772..916caf3bfe 100644 --- a/.github/workflows/cli.yml +++ b/.github/workflows/cli.yml @@ -60,9 +60,7 @@ jobs: - name: yarn lint, test after creation working-directory: ${{ steps.generate_tempdir.outputs.tempdir }}/test-app run: | - pwd - ls -la - yarn lint - yarn test + yarn lint:all + yarn test:all env: CI: true From 55b767a3fab707875a2c6a01d5159a0cbc3a9306 Mon Sep 17 00:00:00 2001 From: Marcus Eide Date: Thu, 16 Apr 2020 12:16:12 +0200 Subject: [PATCH 11/18] Link local packages in package.json if in e2e-test --- .../cli/src/commands/create-app/createApp.ts | 37 +++++++++++++++++++ packages/cli/src/helpers/paths.ts | 2 +- .../templates/default-app/package.json.hbs | 3 -- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/packages/cli/src/commands/create-app/createApp.ts b/packages/cli/src/commands/create-app/createApp.ts index b596d9ac73..475c9d7cdc 100644 --- a/packages/cli/src/commands/create-app/createApp.ts +++ b/packages/cli/src/commands/create-app/createApp.ts @@ -86,6 +86,34 @@ export async function moveApp( }); } +async function addPackageResolutions(rootDir: string, appDir: string) { + process.chdir(appDir); + + const packageFileContent = await fs.readFile('package.json', 'utf-8'); + const packageFileJson = JSON.parse(packageFileContent); + + if (packageFileJson.resolutions) { + throw new Error('package.json already contains resolutions'); + } + packageFileJson.resolutions = {}; + + const packages = ['cli', 'core', 'test-utils', 'test-utils-core', 'theme']; + + for (const pkg of packages) { + await Task.forItem('adding', `${pkg} link to package.json`, async () => { + const pkgPath = require('path').join(rootDir, 'packages', pkg); + packageFileJson.resolutions[`@backstage/${pkg}`] = `file:${pkgPath}`; + const newContents = `${JSON.stringify(packageFileJson, null, 2)}\n`; + + await fs.writeFile('package.json', newContents, 'utf-8').catch(error => { + throw new Error( + `Failed to add resolutions to package.json: ${error.message}`, + ); + }); + }); + } +} + export default async () => { const questions: Question[] = [ { @@ -126,6 +154,15 @@ export default async () => { Task.section('Moving to final location'); await moveApp(tempDir, appDir, answers.name); + // e2e testing needs special treatment + if (process.env.E2E) { + Task.section('Linking packages locally for e2e tests'); + const rootDir = process.env.CI + ? resolvePath(process.env.GITHUB_WORKSPACE!) + : resolvePath(__dirname, '..', '..', '..'); + await addPackageResolutions(rootDir, appDir); + } + Task.section('Building the app'); await buildApp(appDir); diff --git a/packages/cli/src/helpers/paths.ts b/packages/cli/src/helpers/paths.ts index 746b3f6ea8..173e77e1c5 100644 --- a/packages/cli/src/helpers/paths.ts +++ b/packages/cli/src/helpers/paths.ts @@ -53,7 +53,7 @@ export function findRootPath(topPath: string): string { try { const contents = fs.readFileSync(packagePath, 'utf8'); const data = JSON.parse(contents); - if (data.name === 'root') { + if (data.name === 'root' || data.name.includes('backstage-e2e')) { return path; } } catch (error) { diff --git a/packages/cli/templates/default-app/package.json.hbs b/packages/cli/templates/default-app/package.json.hbs index 5161e85fe0..7b5fab5221 100644 --- a/packages/cli/templates/default-app/package.json.hbs +++ b/packages/cli/templates/default-app/package.json.hbs @@ -25,8 +25,5 @@ "@backstage/cli": "^{{version}}", "lerna": "^3.20.2", "prettier": "^1.19.1" - }, - "resolutions": { - "@backstage/cli": "file:/home/runner/work/backstage/backstage/packages/cli" } } From c8f8759379ed9710bc4ffd64bda6b5767769108c Mon Sep 17 00:00:00 2001 From: Marcus Eide Date: Thu, 16 Apr 2020 14:41:53 +0200 Subject: [PATCH 12/18] Try different approach to change dir in final step --- .github/workflows/cli.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cli.yml b/.github/workflows/cli.yml index 916caf3bfe..8adc4efdad 100644 --- a/.github/workflows/cli.yml +++ b/.github/workflows/cli.yml @@ -58,8 +58,9 @@ jobs: node ${{ github.workspace }}/scripts/cli-e2e-test.js # This should lint and test both an app and a plugin - name: yarn lint, test after creation - working-directory: ${{ steps.generate_tempdir.outputs.tempdir }}/test-app + working-directory: ${{ steps.generate_tempdir.outputs.tempdir }} run: | + cd test-app yarn lint:all yarn test:all env: From 3eca6cc9d5cf83e4e8104a6f8738031b49327362 Mon Sep 17 00:00:00 2001 From: Marcus Eide Date: Thu, 16 Apr 2020 15:00:21 +0200 Subject: [PATCH 13/18] Change name of env variable used in script --- packages/cli/bin/backstage-cli | 5 +---- packages/cli/src/commands/build-cache/index.ts | 2 +- packages/cli/src/commands/create-app/createApp.ts | 2 +- scripts/cli-e2e-test.js | 2 +- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/cli/bin/backstage-cli b/packages/cli/bin/backstage-cli index 1cdf8c81af..5288f913d9 100755 --- a/packages/cli/bin/backstage-cli +++ b/packages/cli/bin/backstage-cli @@ -20,10 +20,7 @@ const path = require('path'); // Figure out whether we're running inside the backstage repo or as an installed dependency const isLocal = require('fs').existsSync(path.resolve(__dirname, '../src')); -// This is used for e2e-tests where we create a new app in a tmp folder -const isTemp = path.resolve(__dirname).includes(require('os').tmpdir()); - -if (!isLocal || isTemp || process.env.E2E) { +if (!isLocal || process.env.BACKSTAGE_E2E_CLI_TEST) { // src-relative imports are a pain to get to work with plain tsc compilation, as the // transpiled code will maintain the imports as they are in the source. Which means an // import for `helpers/paths` will start like that in the output, which won't work in NodeJS. diff --git a/packages/cli/src/commands/build-cache/index.ts b/packages/cli/src/commands/build-cache/index.ts index 368fac2593..a825a7f415 100644 --- a/packages/cli/src/commands/build-cache/index.ts +++ b/packages/cli/src/commands/build-cache/index.ts @@ -30,7 +30,7 @@ export async function withCache( buildFunc: () => Promise, ): Promise { const key = await Cache.readInputKey(options.inputs); - if (!key || process.env.E2E) { + if (!key || process.env.BACKSTAGE_E2E_CLI_TEST) { print('input directory is dirty, skipping cache'); await fs.remove(options.output); await buildFunc(); diff --git a/packages/cli/src/commands/create-app/createApp.ts b/packages/cli/src/commands/create-app/createApp.ts index 475c9d7cdc..219406704d 100644 --- a/packages/cli/src/commands/create-app/createApp.ts +++ b/packages/cli/src/commands/create-app/createApp.ts @@ -155,7 +155,7 @@ export default async () => { await moveApp(tempDir, appDir, answers.name); // e2e testing needs special treatment - if (process.env.E2E) { + if (process.env.BACKSTAGE_E2E_CLI_TEST) { Task.section('Linking packages locally for e2e tests'); const rootDir = process.env.CI ? resolvePath(process.env.GITHUB_WORKSPACE!) diff --git a/scripts/cli-e2e-test.js b/scripts/cli-e2e-test.js index 934585bee5..d67154537e 100644 --- a/scripts/cli-e2e-test.js +++ b/scripts/cli-e2e-test.js @@ -32,7 +32,7 @@ const generateTempDir = require('./generateTempDir.js'); Browser.localhost('localhost', 3000); async function main() { - process.env.E2E = 'true'; + process.env.BACKSTAGE_E2E_CLI_TEST = 'true'; const rootDir = process.env.CI ? resolvePath(process.env.GITHUB_WORKSPACE) From e762e953687e56c14caaab13bab4d5378080fcf1 Mon Sep 17 00:00:00 2001 From: Marcus Eide Date: Thu, 16 Apr 2020 15:20:20 +0200 Subject: [PATCH 14/18] Modify envs in cli workflow --- .github/workflows/cli.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/cli.yml b/.github/workflows/cli.yml index 8adc4efdad..972087ffff 100644 --- a/.github/workflows/cli.yml +++ b/.github/workflows/cli.yml @@ -20,6 +20,7 @@ jobs: env: CI: true NODE_OPTIONS: --max-old-space-size=4096 + BACKSTAGE_E2E_CLI_TEST: true name: Node ${{ matrix.node-version }} on ${{ matrix.os }} steps: @@ -63,5 +64,3 @@ jobs: cd test-app yarn lint:all yarn test:all - env: - CI: true From 99986cfc1116475d2b933b8f2d131761a266c1a4 Mon Sep 17 00:00:00 2001 From: Marcus Eide Date: Thu, 16 Apr 2020 15:23:38 +0200 Subject: [PATCH 15/18] Fix path for cli cmd and add debug logs --- scripts/cli-e2e-test.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/scripts/cli-e2e-test.js b/scripts/cli-e2e-test.js index d67154537e..4af26e2e41 100644 --- a/scripts/cli-e2e-test.js +++ b/scripts/cli-e2e-test.js @@ -40,14 +40,24 @@ async function main() { const tempDir = process.env.CI ? process.cwd() : await generateTempDir(); + process.stdout.write(`Initial directory: ${process.cwd()}\n`); process.chdir(tempDir); + process.stdout.write(`Temp directory: ${process.cwd()}\n`); + await waitForExit(spawnPiped(['yarn', 'init --yes'])); - const createAppCmd = `${rootDir}/packages/cli/bin/backstage-cli create-app`; - await createTestApp(createAppCmd); + const createCmdPath = require('path').join( + rootDir, + 'packages', + 'cli', + 'bin', + 'backstage-cli', + ); + await createTestApp(`${createCmdPath} create-app`); const appDir = resolvePath(tempDir, 'test-app'); process.chdir(appDir); + process.stdout.write(`App directory: ${appDir}\n`); await createTestPlugin(); From 99c2c5879e0b540f91e82464df0cd96b743d3b79 Mon Sep 17 00:00:00 2001 From: Marcus Eide Date: Thu, 16 Apr 2020 15:31:14 +0200 Subject: [PATCH 16/18] Export helper methods differently --- scripts/helpers.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/scripts/helpers.js b/scripts/helpers.js index 7ad1bedfd5..7e34f10a63 100644 --- a/scripts/helpers.js +++ b/scripts/helpers.js @@ -129,9 +129,11 @@ function print(msg) { return process.stdout.write(`${msg}\n`); } -module.exports.spawnPiped = spawnPiped; -module.exports.handleError = handleError; -module.exports.waitFor = waitFor; -module.exports.waitForExit = waitForExit; -module.exports.waitForPageWithText = waitForPageWithText; -module.exports.print = print; +module.exports = { + spawnPiped, + handleError, + waitFor, + waitForExit, + waitForPageWithText, + print, +}; From 60d6392e4183843ad773fedbe90f2baa3e3aa0a4 Mon Sep 17 00:00:00 2001 From: Marcus Eide Date: Thu, 16 Apr 2020 15:43:54 +0200 Subject: [PATCH 17/18] Add back isTemp check --- packages/cli/bin/backstage-cli | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/cli/bin/backstage-cli b/packages/cli/bin/backstage-cli index 5288f913d9..385911896c 100755 --- a/packages/cli/bin/backstage-cli +++ b/packages/cli/bin/backstage-cli @@ -20,7 +20,10 @@ const path = require('path'); // Figure out whether we're running inside the backstage repo or as an installed dependency const isLocal = require('fs').existsSync(path.resolve(__dirname, '../src')); -if (!isLocal || process.env.BACKSTAGE_E2E_CLI_TEST) { +// This is used for e2e-tests where we create a new app in a tmp folder +const isTemp = path.resolve(__dirname).includes(require('os').tmpdir()); + +if (!isLocal || isTemp || process.env.BACKSTAGE_E2E_CLI_TEST) { // src-relative imports are a pain to get to work with plain tsc compilation, as the // transpiled code will maintain the imports as they are in the source. Which means an // import for `helpers/paths` will start like that in the output, which won't work in NodeJS. From fb42fd490b2f9ce8748413aa79e28c4ee313ce36 Mon Sep 17 00:00:00 2001 From: Marcus Eide Date: Thu, 16 Apr 2020 15:49:18 +0200 Subject: [PATCH 18/18] wip: trying different things --- .github/workflows/cli.yml | 9 +++++++-- packages/cli/bin/backstage-cli | 5 +---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/cli.yml b/.github/workflows/cli.yml index 972087ffff..dad8437613 100644 --- a/.github/workflows/cli.yml +++ b/.github/workflows/cli.yml @@ -20,7 +20,6 @@ jobs: env: CI: true NODE_OPTIONS: --max-old-space-size=4096 - BACKSTAGE_E2E_CLI_TEST: true name: Node ${{ matrix.node-version }} on ${{ matrix.os }} steps: @@ -45,18 +44,22 @@ jobs: # generate temp directory - name: generate tempdir id: generate_tempdir - run: echo ::set-output name=tempdir::$(node scripts/generateTempDir.js) + run: echo "::set-output name=tempdir::$(node scripts/generateTempDir.js)" # This creates a new app and plugin which pollutes the workspace, so it should be run last. - name: verify app and plugin creation on Windows working-directory: ${{ steps.generate_tempdir.outputs.tempdir }} if: runner.os == 'Windows' run: node ${{ github.workspace }}/scripts/cli-e2e-test.js + env: + BACKSTAGE_E2E_CLI_TEST: true - name: verify app and plugin creation on Linux working-directory: ${{ steps.generate_tempdir.outputs.tempdir }} if: runner.os == 'Linux' run: | sudo sysctl fs.inotify.max_user_watches=524288 node ${{ github.workspace }}/scripts/cli-e2e-test.js + env: + BACKSTAGE_E2E_CLI_TEST: true # This should lint and test both an app and a plugin - name: yarn lint, test after creation working-directory: ${{ steps.generate_tempdir.outputs.tempdir }} @@ -64,3 +67,5 @@ jobs: cd test-app yarn lint:all yarn test:all + env: + BACKSTAGE_E2E_CLI_TEST: true diff --git a/packages/cli/bin/backstage-cli b/packages/cli/bin/backstage-cli index 385911896c..5288f913d9 100755 --- a/packages/cli/bin/backstage-cli +++ b/packages/cli/bin/backstage-cli @@ -20,10 +20,7 @@ const path = require('path'); // Figure out whether we're running inside the backstage repo or as an installed dependency const isLocal = require('fs').existsSync(path.resolve(__dirname, '../src')); -// This is used for e2e-tests where we create a new app in a tmp folder -const isTemp = path.resolve(__dirname).includes(require('os').tmpdir()); - -if (!isLocal || isTemp || process.env.BACKSTAGE_E2E_CLI_TEST) { +if (!isLocal || process.env.BACKSTAGE_E2E_CLI_TEST) { // src-relative imports are a pain to get to work with plain tsc compilation, as the // transpiled code will maintain the imports as they are in the source. Which means an // import for `helpers/paths` will start like that in the output, which won't work in NodeJS.