e2e-test: converted into a CLI

This commit is contained in:
Patrik Oldsberg
2020-10-10 17:26:27 +02:00
parent dc0261e6bc
commit 7de1004f03
11 changed files with 104 additions and 25 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'e2e-test': minor
---
Converted into a CLI, use `yarn e2e-test run` to run
+1 -1
View File
@@ -40,4 +40,4 @@ jobs:
- name: yarn build
run: yarn build --ignore example-app --ignore example-backend --ignore @techdocs/cli
- name: run E2E test
run: yarn workspace e2e-test start
run: yarn e2e-test run
+1 -1
View File
@@ -70,7 +70,7 @@ jobs:
- name: run E2E test
run: |
sudo sysctl fs.inotify.max_user_watches=524288
yarn workspace e2e-test start
yarn e2e-test run
env:
POSTGRES_HOST: localhost
POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }}
+1 -1
View File
@@ -14,7 +14,7 @@ yarn tsc
yarn build
```
Once those tasks have completed, you can now run the test using `yarn start` inside this package.
Once those tasks have completed, you can now run the test using `yarn e2e-test run`.
If you make changes to other packages you will need to rerun `yarn tsc && yarn build`. Changes to this package do not require a rebuild.
+5 -2
View File
@@ -1,3 +1,4 @@
#!/usr/bin/env node
/*
* Copyright 2020 Spotify AB
*
@@ -14,13 +15,15 @@
* limitations under the License.
*/
const path = require('path');
require('ts-node').register({
transpileOnly: true,
/* eslint-disable-next-line no-restricted-syntax */
project: require('path').resolve(__dirname, '../../../tsconfig.json'),
project: path.resolve(__dirname, '../../../tsconfig.json'),
compilerOptions: {
module: 'CommonJS',
},
});
require('./e2e-test');
require('../src');
+6 -1
View File
@@ -13,17 +13,22 @@
"backstage"
],
"license": "Apache-2.0",
"main": "src/index.js",
"main": "src/index.ts",
"scripts": {
"start": "node .",
"lint": "backstage-cli lint",
"test": "backstage-cli test",
"test:e2e": "yarn start"
},
"bin": {
"e2e-test": "bin/e2e-test"
},
"devDependencies": {
"@backstage/cli-common": "^0.1.1-alpha.24",
"@types/fs-extra": "^9.0.1",
"@types/node": "^13.7.2",
"chalk": "^4.0.0",
"commander": "^6.1.0",
"fs-extra": "^9.0.0",
"handlebars": "^4.7.3",
"node-fetch": "^2.6.0",
+22
View File
@@ -0,0 +1,22 @@
/*
* 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 { CommanderStatic } from 'commander';
import { run } from './run';
export function registerCommands(program: CommanderStatic) {
program.command('run').description('Run e2e tests').action(run);
}
@@ -24,16 +24,15 @@ import Browser from 'zombie';
import {
spawnPiped,
runPlain,
handleError,
waitForPageWithText,
waitFor,
waitForExit,
print,
} from './helpers';
} from '../lib/helpers';
import pgtools from 'pgtools';
import { findPaths } from '@backstage/cli-common';
/* eslint-disable-next-line no-restricted-syntax */
// eslint-disable-next-line no-restricted-syntax
const paths = findPaths(__dirname);
const templatePackagePaths = [
@@ -42,7 +41,7 @@ const templatePackagePaths = [
'packages/create-app/templates/default-app/packages/backend/package.json.hbs',
];
async function main() {
export async function run() {
const rootDir = await fs.mkdtemp(resolvePath(os.tmpdir(), 'backstage-e2e-'));
print(`CLI E2E test root: ${rootDir}\n`);
@@ -413,16 +412,3 @@ async function testBackendStart(appDir: string, isPostgres: boolean) {
print('Backend startup test finished successfully');
}
}
process.on('unhandledRejection', (error: Error) => {
// Try to avoid exiting if the unhandled error is coming from jsdom, i.e. zombie.
// Those are typically errors on the page that should be benign, at least in the
// context of this test. We have other ways of asserting that the page is being
// rendered correctly.
if (error?.stack?.includes('node_modules/jsdom/lib')) {
console.log(`Ignored error inside jsdom, ${error}`);
} else {
handleError(error);
}
});
main().catch(handleError);
+58
View File
@@ -0,0 +1,58 @@
/*
* 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 program from 'commander';
import chalk from 'chalk';
import { registerCommands } from './commands';
import { version } from '../package.json';
import { exitWithError } from './lib/helpers';
async function main(argv: string[]) {
program.name('e2e-test').version(version);
registerCommands(program);
program.on('command:*', () => {
console.log();
console.log(chalk.red(`Invalid command: ${program.args.join(' ')}`));
console.log();
program.outputHelp();
process.exit(1);
});
program.parse(argv);
}
process.on('unhandledRejection', (rejection: unknown) => {
// Try to avoid exiting if the unhandled error is coming from jsdom, i.e. zombie.
// Those are typically errors on the page that should be benign, at least in the
// context of this test. We have other ways of asserting that the page is being
// rendered correctly.
if (
rejection instanceof Error &&
rejection?.stack?.includes('node_modules/jsdom/lib')
) {
console.log(`Ignored error inside jsdom, ${rejection?.stack ?? rejection}`);
} else {
if (rejection instanceof Error) {
exitWithError(rejection);
} else {
exitWithError(new Error(`Unknown rejection: '${rejection}'`));
}
}
});
main(process.argv).catch(exitWithError);
@@ -42,7 +42,7 @@ export function spawnPiped(cmd: string[], options?: SpawnOptions) {
shell: true,
...options,
});
child.on('error', handleError);
child.on('error', exitWithError);
const logPrefix = cmd.map(s => s.replace(/.+\//, '')).join(' ');
child.stdout?.on(
@@ -75,7 +75,7 @@ export async function runPlain(cmd: string[], options?: SpawnOptions) {
}
}
export function handleError(err: Error & { code?: unknown }) {
export function exitWithError(err: Error & { code?: unknown }) {
process.stdout.write(`${err.name}: ${err.stack || err.message}\n`);
if (typeof err.code === 'number') {