Merge pull request #550 from spotify/eide/app-e2e

Add create-app to e2e
This commit is contained in:
Patrik Oldsberg
2020-04-16 16:42:05 +02:00
committed by GitHub
14 changed files with 376 additions and 153 deletions
+2 -1
View File
@@ -19,7 +19,8 @@ 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) {
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.
@@ -30,7 +30,7 @@ export async function withCache(
buildFunc: () => Promise<void>,
): Promise<void> {
const key = await Cache.readInputKey(options.inputs);
if (!key) {
if (!key || process.env.BACKSTAGE_E2E_CLI_TEST) {
print('input directory is dirty, skipping cache');
await fs.remove(options.output);
await buildFunc();
@@ -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.BACKSTAGE_E2E_CLI_TEST) {
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);
@@ -134,6 +171,7 @@ export default async () => {
chalk.green(`🥇 Successfully created ${chalk.cyan(answers.name)}`),
);
Task.log();
Task.exit();
} catch (error) {
Task.error(error.message);
@@ -143,5 +181,6 @@ export default async () => {
Task.section('Cleanup');
await cleanUp(tempDir);
Task.error('🔥 Failed to create app!');
Task.exit(1);
}
};
@@ -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);
}
};
@@ -46,6 +46,7 @@ export default {
json(),
typescript({
include: `${paths.resolveTarget('src')}/**/*.{js,jsx,ts,tsx}`,
clean: true,
}),
],
} as RollupWatchOptions;
+1 -1
View File
@@ -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) {
+4
View File
@@ -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,
@@ -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",