Skip to content

Commit

Permalink
Lint major changes and plugin tests pass with npm test
Browse files Browse the repository at this point in the history
  • Loading branch information
danactive committed Oct 17, 2016
1 parent 5f89b76 commit 1cccf0b
Show file tree
Hide file tree
Showing 17 changed files with 695 additions and 711 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
[*.{eslintrc,md}]
trim_trailing_whitespace = false
indent_style = tab
indent_size = 4

[*.xml]
[*.{html,xml}]
trim_trailing_whitespace = false
indent_style = tab
indent_size = 2
6 changes: 6 additions & 0 deletions plugins/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "airbnb-base",
"rules": {
"max-len": [2, 150, 4]
}
}
6 changes: 0 additions & 6 deletions plugins/dev-mode/.eslintrc.json

This file was deleted.

43 changes: 0 additions & 43 deletions plugins/dev-mode/package.json

This file was deleted.

28 changes: 19 additions & 9 deletions plugins/exists/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
'use strict';
const boom = require('boom');
const fs = require('fs');
const path = require('path');

const moduleName = 'pathExists';

/**
Verify if a path exists on the file system
@method pathExists
@param {string} path relative/absolute path (file or folder) on the file system
@param {promise}
@param {string} verifyPath relative/absolute path (file or folder) on the file system
@returns {promise}
**/
function pathExists(verifyPath) {
return new Promise((resolve, reject) => {
const boom = require('boom');
if (verifyPath === undefined) {
reject(boom.notFound(`pathExists module: is missing a path to verify`));
reject(boom.notFound(`${moduleName} module: File system path is missing (${verifyPath})`));
}
const verifiedPath = require('path').isAbsolute(verifyPath) ?
verifyPath : require('app-root-path').resolve(verifyPath);

require('fs').stat(verifiedPath, (error, type) => {
const verifiedPath = path.isAbsolute(verifyPath) ? verifyPath : path.resolve('../', verifyPath);

fs.stat(verifiedPath, (error, type) => {
if (error) {
return reject(boom.notFound(`pathExists module: File system path is missing ${error}`));
const pathType = path.isAbsolute(verifyPath) ? 'absolute' : 'relative';

return reject(boom.notFound(`${moduleName} module: File system path is ${pathType} and not found
due to error (${error})`));
}

if (type.isFile() || type.isDirectory()) {
return resolve(verifiedPath);
}

return reject(boom.notFound('File failed'));
});
});
}
Expand Down
28 changes: 0 additions & 28 deletions plugins/exists/package.json

This file was deleted.

135 changes: 66 additions & 69 deletions plugins/exists/test/index.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,77 @@
'use strict';
const test = require('tape');
const tape = require('tape-catch');

test('Real relative file exists', (assert) => {
const module = require('../lib');
const testPath = './plugins/exists/test/fixtures/exists.txt';
tape('Index', { skip: false }, (describe) => {
const path = require('path');

module.pathExists(testPath)
.then(() => {
assert.pass('Resolved promise is returned');
assert.end();
})
.catch(() => {
assert.fail(`File system is missing folder (${testPath})`);
assert.end();
});
});
const lib = require('../lib');

test('Real relative folder exists', (assert) => {
const module = require('../lib');
const testPath = './plugins/exists/test/fixtures';
describe.test('* Real relative file exists', (assert) => {
const testPath = './plugins/exists/test/fixtures/exists.txt';

module.pathExists(testPath)
.then(() => {
assert.pass('Resolved promise is returned');
assert.end();
})
.catch(() => {
assert.fail(`File system is missing folder (${testPath})`);
assert.end();
});
});
lib.pathExists(testPath)
.then(() => {
assert.pass('Resolved promise is returned');
assert.end();
})
.catch((error) => {
assert.fail(error);
assert.end();
});
});

test('Real absolute file exists', (assert) => {
const module = require('../lib');
const path = require('path');
const testPath = path.join(__dirname, './fixtures/exists.txt');
describe.test('* Real relative folder exists', (assert) => {
const testPath = './plugins/exists/test/fixtures';

module.pathExists(testPath)
.then((verifiedPath) => {
assert.equal(verifiedPath, testPath, 'Resolved path matches');
assert.end();
})
.catch(() => {
assert.fail(`File system is missing folder (${testPath})`);
assert.end();
});
});
lib.pathExists(testPath)
.then(() => {
assert.pass('Resolved promise is returned');
assert.end();
})
.catch((error) => {
assert.fail(error);
assert.end();
});
});

test('Real absolute folder exists', (assert) => {
const module = require('../lib');
const path = require('path');
const testPath = path.join(__dirname, './fixtures');
describe.test('* Real absolute file exists', (assert) => {
const testPath = path.join(__dirname, './fixtures/exists.txt');

module.pathExists(testPath)
.then((verifiedPath) => {
assert.equal(verifiedPath, testPath, 'Resolved path matches');
assert.end();
})
.catch(() => {
assert.fail(`File system is missing folder (${testPath})`);
assert.end();
});
});
lib.pathExists(testPath)
.then((verifiedPath) => {
assert.equal(verifiedPath, testPath, 'Resolved path matches');
assert.end();
})
.catch((error) => {
assert.fail(error);
assert.end();
});
});

test('Fake absolute path does not exists', (assert) => {
const module = require('../lib');
const path = require('path');
const testPath = path.join(__dirname, './fixtures/fakeFolder');
describe.test('* Real absolute folder exists', (assert) => {
const testPath = path.join(__dirname, './fixtures');

lib.pathExists(testPath)
.then((verifiedPath) => {
assert.equal(verifiedPath, testPath, 'Resolved path matches');
assert.end();
})
.catch((error) => {
assert.fail(error);
assert.end();
});
});

describe.test('* Fake absolute path does not exists', (assert) => {
const testPath = path.join(__dirname, './fixtures/fakeFolder');

module.pathExists(testPath)
.then(() => {
assert.fail(`File system found a fake folder (${testPath})`);
assert.end();
})
.catch((error) => {
assert.equal(error.isBoom, true, 'Rejected promise is a boom error');
assert.end();
});
lib.pathExists(testPath)
.then(() => {
assert.fail(`File system found a fake folder (${testPath})`);
assert.end();
})
.catch((error) => {
assert.equal(error.isBoom, true, 'Rejected promise is a boom error');
assert.end();
});
});
});
26 changes: 19 additions & 7 deletions plugins/dev-mode/shared-gulpfile.js → plugins/gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
const gulp = require('gulp');
const eslint = require('gulp-eslint');
const expect = require('gulp-expect-file');
const gulp = require('gulp');
const print = require('gulp-print');
const tape = require('gulp-tape');

const paths = {
scripts: ['../../lib/**/*.js'],
test: ['../../test/**/*.js']
lib: [
'exists/lib/*.js',
'rename/lib/*.js'
],
test: [
'exists/test/*.js',
'rename/test/*.js'
]
};

gulp.task('lint', () => {
const files = paths.scripts.concat(paths.test);
function lint(files, configFile) {
return gulp.src(files)
.pipe(print())
.pipe(expect(files))
.pipe(eslint({ configFile: '.eslintrc.json' }))
.pipe(eslint({ configFile }))
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
}

gulp.task('lint', ['lint-test'], () => lint(paths.lib, '.eslintrc'));
gulp.task('lint-test', () => lint(paths.test, 'test.eslintrc'));

gulp.task('test', () => {
const files = paths.test;

return gulp.src(files)
.pipe(print())
.pipe(expect(files))
.pipe(tape());
});
Expand Down
44 changes: 44 additions & 0 deletions plugins/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "history-plugins",
"version": "1.1.10",
"description": "Developer dependencies for history plugins",
"main": "gulpfile.js",
"scripts": {
"dev": "gulp",
"lint": "gulp lint",
"test": "gulp test"
},
"dependencies": {
"app-root-path": "^2.0.1",
"async": "^2.1.2",
"boom": "^4.0.0",
"glob": "^7.0.0",
"joi": "^9.1.1"
},
"devDependencies": {
"eslint": "^3.4.0",
"eslint-config-airbnb-base": "^8.0.0",
"eslint-plugin-import": "^1.8.0",
"gulp": "^3.9.0",
"gulp-eslint": "^3.0.1",
"gulp-expect-file": "0.0.7",
"gulp-print": "^2.0.1",
"gulp-tape": "0.0.7",
"hapi": "^15.0.3",
"tape": "4.6.0",
"tape-catch": "^1.0.6"
},
"author": {
"name": "danactive",
"url": "http://twitter.com/danactive"
},
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/danactive/history.git"
},
"engines": {
"npm": ">3",
"node": ">4"
}
}
Loading

0 comments on commit 1cccf0b

Please sign in to comment.