Skip to content

Commit

Permalink
Create target dir if not exists. Closes #6
Browse files Browse the repository at this point in the history
  • Loading branch information
ivarni committed Jul 22, 2016
1 parent 062996f commit 32f6408
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,3 +4,6 @@

### 1.0.1
- Fix inaccurate (wrong) docs

### 1.0.2
- If target directory does not exist, create it
5 changes: 3 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "get-selenium",
"version": "1.0.1",
"version": "1.0.2",
"description": "Make sure you've got the selenium jar and the chromedriver executable",
"main": "lib/index.js",
"scripts": {
Expand All @@ -26,6 +26,7 @@
"extract-zip": "^1.5.0",
"file-exists": "^1.0.0",
"md5-file": "^3.1.1",
"mkdirp": "^0.5.1",
"request": "^2.73.0"
},
"devDependencies": {
Expand All @@ -44,10 +45,10 @@
"eslint-plugin-react": "^5.2.2",
"expect.js": "^0.3.1",
"glob": "^7.0.5",
"mkdirp": "^0.5.1",
"mocha": "^2.5.3",
"mocha-lcov-reporter": "^1.2.0",
"nyc": "^7.0.0",
"rimraf": "^2.5.3",
"tmp": "0.0.28"
},
"files": [
Expand Down
3 changes: 3 additions & 0 deletions src/index.js
Expand Up @@ -2,15 +2,18 @@ import 'babel-polyfill';
import bluebird from 'bluebird';
import glob from 'glob';
import path from 'path';
import mkdirp from 'mkdirp';

import selenium from './selenium';
import chromedriver from './chromedriver';
import { unlink } from './util';

const globber = bluebird.promisify(glob);
const makeDir = bluebird.promisify(mkdirp);

/* eslint-disable no-console, func-names */
const ensure = async function(target) {
await makeDir(target);
console.log('Getting selenium');
await selenium(target);
console.log('Got selenium');
Expand Down
19 changes: 15 additions & 4 deletions test/ensure.spec.js
Expand Up @@ -5,6 +5,7 @@ import path from 'path';
import mkdirp from 'mkdirp';
import fs from 'fs';
import glob from 'glob';
import rmrf from 'rimraf';

import {
ensure,
Expand All @@ -23,6 +24,11 @@ before(async function() {
//tmpPath = path.join('/', 'home', 'ivarni', 'Downloads');
tmpPath = path.join(await dir(), 'selenium');
await makeDir(tmpPath);
console.log(tmpPath)
});

after(done => {
rmrf(tmpPath, done);
});

describe('ensure', function() {
Expand All @@ -33,10 +39,6 @@ describe('ensure', function() {
await ensure(tmpPath);
});

after(() => {
// get rid of the tmp dir
});

it('downloads selenium and chromedriver', async function() {
await stat(path.join(tmpPath, 'selenium.jar'));
const files = await globber(path.join(tmpPath, 'chromedriver*'));
Expand All @@ -48,6 +50,15 @@ describe('ensure', function() {
expect(files.length).to.be(0);
});

describe('if target directory does not exist', async function() {

it('creates it', async function() {
await bluebird.promisify(rmrf)(tmpPath);
await ensure(tmpPath);
});

})

});

describe('update', function() {
Expand Down

0 comments on commit 32f6408

Please sign in to comment.