Skip to content

Commit

Permalink
Refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
albertorestifo committed Aug 15, 2016
1 parent fa6e0b7 commit 339fc68
Show file tree
Hide file tree
Showing 10 changed files with 396 additions and 399 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
coverage/*
dist/*
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: node_js
node_js:
- "4.0"
- "6.0"
after_success:
- cat ./coverage/lcov.info | ./node_modules/codecov.io/bin/codecov.io.js
28 changes: 14 additions & 14 deletions Gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict'
/* eslint import/no-extraneous-dependencies: ["error", {"devDependencies": true}] */

const babel = require('gulp-babel')
const browserify = require('browserify')
const gulp = require('gulp')
const rename = require('gulp-rename')
const source = require('vinyl-source-stream')
const uglify = require('gulp-uglify')
const babel = require('gulp-babel');
const browserify = require('browserify');
const gulp = require('gulp');
const rename = require('gulp-rename');
const source = require('vinyl-source-stream');
const uglify = require('gulp-uglify');

/**
* Prepares the files for browser usage
Expand All @@ -14,19 +14,19 @@ const uglify = require('gulp-uglify')
* - Transpile with Babel
* - Minify with uglify
*/
gulp.task('build', [ 'bundle' ], function () {
gulp.task('build', ['bundle'], () => {
gulp.src('./dist/dijkstra.js')
.pipe(babel())
.pipe(gulp.dest('./dist'))
.pipe(uglify())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('./dist'))
})
.pipe(gulp.dest('./dist'));
});

gulp.task('bundle', function () {
let b = browserify({ entries: './libs/Graph.js' })
gulp.task('bundle', () => {
const b = browserify({ entries: './libs/Graph.js' });

return b.bundle()
.pipe(source('dijkstra.js'))
.pipe(gulp.dest('./dist'))
})
.pipe(gulp.dest('./dist'));
});
4 changes: 2 additions & 2 deletions libs/PriorityQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ class PriorityQueue {
this.queue.push({ key, priority });
} else {
// Update the priority of an existing key
this.queue.map(element => {
this.queue.map((element) => {
if (element.key === key) {
return Object.assing({}, element, { priority });
Object.assign(element, { priority });
}

return element;
Expand Down
19 changes: 11 additions & 8 deletions libs/toDeepMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,21 @@ function isValidNode(val) {
*/
function toDeepMap(source) {
const map = new Map();
const keys = Object.keys(source);

for (const key of source) {
keys.forEach((key) => {
const val = source[key];

if (val !== null && typeof value === 'object' && !Array.is(val)) {
map.set(key, toDeepMap(val));
} else if (isValidNode(val)) {
map.set(key, val);
} else {
throw new Error(`Could not add node at key "${key}", make sure it's a valid node`);
if (val !== null && typeof val === 'object' && !Array.isArray(val)) {
return map.set(key, toDeepMap(val));
}
}

if (!isValidNode(val)) {
throw new Error(`Could not add node at key "${key}", make sure it's a valid node`, val);
}

return map.set(key, Number(val));
});

return map;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"url": "https://github.com/albertorestifo/node-dijkstra"
},
"scripts": {
"test": "eslint * && istanbul cover _mocha -- --ui bdd -R spec -t 5000",
"test": "eslint . && istanbul cover _mocha -- --ui bdd -R spec -t 5000",
"compile": "gulp build"
},
"bugs": {
Expand Down
Loading

0 comments on commit 339fc68

Please sign in to comment.