Skip to content

Commit

Permalink
feat(util): validate DOWNLOADS_DIR exists and refactor download.js
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Dec 31, 2019
1 parent b82e070 commit 3aa8b8a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 1 addition & 4 deletions pages/download.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const { By, until } = require('selenium-webdriver');
const { readdir } = require('fs').promises;
const { homedir } = require('os');
const { resolve } = require('path');

const { saveDownloadedWorkspace } = require('../util');

Expand All @@ -13,8 +11,7 @@ const NEXT_LOCATOR = By.xpath('//span[contains(text(), "Next")]');
const WORKSPACE_IMAGE_LOCATOR = By.xpath('//strong[text()="Workspace image"]');
const DOWNLOAD_LOCATOR = By.xpath('//button[text()="Download"]');

const DOWNLOADS_DIR =
process.env.DOWNLOADS_DIR || resolve(homedir(), 'Downloads');
const { DOWNLOADS_DIR } = process.env;

class DownloadPage {
/**
Expand Down
9 changes: 9 additions & 0 deletions util/validate-environment.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const { accessSync } = require('fs');
const { homedir } = require('os');
const { resolve } = require('path');
const semver = require('semver');

/**
Expand Down Expand Up @@ -28,6 +31,12 @@ const validateEnvironment = () => {
} else {
console.log(`PASSWORD: ${'*'.repeat(process.env.PASSWORD.length)}`);
}

if (!process.env.DOWNLOADS_DIR) {
process.env.DOWNLOADS_DIR = resolve(homedir(), 'Downloads');
}
accessSync(process.env.DOWNLOADS_DIR);
console.log(`DOWNLOADS_DIR: ${process.env.DOWNLOADS_DIR}`);
};

module.exports = validateEnvironment;

0 comments on commit 3aa8b8a

Please sign in to comment.