e2e-test: added --keep option + error message improvements

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2024-04-05 17:28:12 +02:00
parent d627a67acf
commit 9d74e68f79
3 changed files with 29 additions and 8 deletions
+2 -1
View File
@@ -12,7 +12,7 @@ Options:
-h, --help
Commands:
run
run [options]
help [command]
```
@@ -22,5 +22,6 @@ Commands:
Usage: e2e-test run [options]
Options:
--keep
-h, --help
```
+5 -1
View File
@@ -18,5 +18,9 @@ import { Command } from 'commander';
import { run } from './run';
export function registerCommands(program: Command) {
program.command('run').description('Run e2e tests').action(run);
program
.command('run')
.option('--keep', 'Do not remove the temporary dir after tests complete')
.description('Run e2e tests')
.action(run);
}
+22 -6
View File
@@ -34,6 +34,7 @@ import mysql from 'mysql2/promise';
import pgtools from 'pgtools';
import { findPaths } from '@backstage/cli-common';
import { OptionValues } from 'commander';
// eslint-disable-next-line no-restricted-syntax
const paths = findPaths(__dirname);
@@ -45,7 +46,7 @@ const templatePackagePaths = [
'packages/create-app/templates/default-app/packages/backend/package.json.hbs',
];
export async function run() {
export async function run(opts: OptionValues) {
const rootDir = await fs.mkdtemp(resolvePath(os.tmpdir(), 'backstage-e2e-'));
print(`CLI E2E test root: ${rootDir}\n`);
@@ -109,8 +110,12 @@ export async function run() {
// runner will be destroyed anyway
print('All tests successful');
} else {
print('All tests successful, removing test dir');
await fs.remove(rootDir);
if (opts.keep) {
print(`All tests successful, app dir available at ${appDir}`);
} else {
print('All tests successful, removing test dir');
await fs.remove(rootDir);
}
}
// Just in case some child process was left hanging
@@ -546,9 +551,20 @@ async function testBackendStart(appDir: string, ...args: string[]) {
print('Try to fetch entities from the backend');
// Try fetch entities, should be ok
await fetch('http://localhost:7007/api/catalog/entities').then(res =>
res.json(),
);
const res = await fetch('http://localhost:7007/api/catalog/entities');
if (!res.ok) {
throw new Error(
`Failed to fetch entities: ${res.status} ${res.statusText}`,
);
}
const content = await res.text();
try {
JSON.parse(content);
} catch (error) {
throw new Error(
`Failed to parse entities JSON response: ${error}\n${content}`,
);
}
print('Entities fetched successfully');
successful = true;
} catch (error) {