From 2f98cf16c6912be16c9fd5cf692b3d5fa4c9f21a Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 4 Mar 2021 12:47:03 +0100 Subject: [PATCH 1/2] chore: make sure to throw when e2e fails Signed-off-by: blam --- packages/e2e-test/src/commands/run.ts | 49 ++++++++++++++++----------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/packages/e2e-test/src/commands/run.ts b/packages/e2e-test/src/commands/run.ts index 5f4894f9e9..851dccae16 100644 --- a/packages/e2e-test/src/commands/run.ts +++ b/packages/e2e-test/src/commands/run.ts @@ -42,33 +42,44 @@ const templatePackagePaths = [ ]; export async function run() { - const rootDir = await fs.mkdtemp(resolvePath(os.tmpdir(), 'backstage-e2e-')); - print(`CLI E2E test root: ${rootDir}\n`); + try { + const rootDir = await fs.mkdtemp( + resolvePath(os.tmpdir(), 'backstage-e2e-'), + ); + print(`CLI E2E test root: ${rootDir}\n`); - print('Building dist workspace'); - const workspaceDir = await buildDistWorkspace('workspace', rootDir); + print('Building dist workspace'); + const workspaceDir = await buildDistWorkspace('workspace', rootDir); - const isPostgres = Boolean(process.env.POSTGRES_USER); - print('Creating a Backstage App'); - const appDir = await createApp('test-app', isPostgres, workspaceDir, rootDir); + const isPostgres = Boolean(process.env.POSTGRES_USER); + print('Creating a Backstage App'); + const appDir = await createApp( + 'test-app', + isPostgres, + workspaceDir, + rootDir, + ); - print('Creating a Backstage Plugin'); - const pluginName = await createPlugin('test-plugin', appDir); + print('Creating a Backstage Plugin'); + const pluginName = await createPlugin('test-plugin', appDir); - print('Creating a Backstage Backend Plugin'); - await createPlugin('test-plugin', appDir, ['--backend']); + print('Creating a Backstage Backend Plugin'); + await createPlugin('test-plugin', appDir, ['--backend']); - print('Starting the app'); - await testAppServe(pluginName, appDir); + print('Starting the app'); + await testAppServe(pluginName, appDir); - print('Testing the backend startup'); - await testBackendStart(appDir, isPostgres); + print('Testing the backend startup'); + await testBackendStart(appDir, isPostgres); - print('All tests successful, removing test dir'); - await fs.remove(rootDir); + print('All tests successful, removing test dir'); + await fs.remove(rootDir); - // Just in case some child process was left hanging - process.exit(0); + // Just in case some child process was left hanging + process.exit(0); + } catch { + process.exit(1); + } } /** From 946615dbab38123bb4f67ae7e74d736e02d3c869 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 4 Mar 2021 13:12:03 +0100 Subject: [PATCH 2/2] cli: fix plugin template by using renderInTestApp in component test Signed-off-by: Patrik Oldsberg --- .../ExampleComponent/ExampleComponent.test.tsx.hbs | 7 +++---- 1 file changed, 3 insertions(+), 4 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 e6eab17493..0044b67a37 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,11 +1,10 @@ import React from 'react'; -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'; -import { msw } from '@backstage/test-utils'; +import { msw, renderInTestApp } from '@backstage/test-utils'; describe('ExampleComponent', () => { const server = setupServer(); @@ -19,8 +18,8 @@ describe('ExampleComponent', () => { ); }); - it('should render', () => { - const rendered = render( + it('should render', async () => { + const rendered = await renderInTestApp( ,