scripts/cli-e2e-test: refactor path handling a bit

This commit is contained in:
Patrik Oldsberg
2020-04-16 18:54:50 +02:00
parent be0881ff35
commit 7a320302c1
3 changed files with 10 additions and 17 deletions
+1 -12
View File
@@ -34,24 +34,13 @@ Browser.localhost('localhost', 3000);
async function main() {
process.env.BACKSTAGE_E2E_CLI_TEST = 'true';
const rootDir = process.env.CI
? resolvePath(process.env.GITHUB_WORKSPACE)
: resolvePath(__dirname, '..');
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`);
const createCmdPath = require('path').join(
rootDir,
'packages',
'cli',
'bin',
'backstage-cli',
);
await createTestApp(`${createCmdPath} create-app`);
await createTestApp();
const appDir = resolvePath(tempDir, 'test-app');
process.chdir(appDir);
+5 -2
View File
@@ -14,11 +14,14 @@
* limitations under the License.
*/
const { resolve: resolvePath } = require('path');
const { spawnPiped, waitFor, waitForExit, print } = require('./helpers');
async function createTestApp(cmd) {
async function createTestApp() {
const cliPath = resolvePath(__dirname, '../packages/cli/bin/backstage-cli');
print('Creating a Backstage App');
const createApp = spawnPiped(['node', cmd]);
const createApp = spawnPiped(['node', cliPath, 'create-app']);
try {
let stdout = '';
+4 -3
View File
@@ -14,12 +14,13 @@
* limitations under the License.
*/
const fs = require('fs-extra');
const os = require('os');
const { resolve: resolvePath } = require('path');
const { handleError } = require('./helpers');
async function generateTempDir() {
const tempDir = await require('fs-extra').mkdtemp(
require('path').join(require('os').tmpdir(), 'backstage-e2e-'),
);
const tempDir = await fs.mkdtemp(resolvePath(os.tmpdir(), 'backstage-e2e-'));
process.stdout.write(tempDir);
return tempDir;
}