Commit fa117122 authored by analog-nico's avatar analog-nico
Browse files

Added gulp for linting and testing

parent 7d9e1760
Loading
Loading
Loading
Loading

.editorconfig

0 → 100644
+21 −0
Original line number Diff line number Diff line
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true


[*]

# Change these settings to your own preference
indent_style = space
indent_size = 4

# We recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
+3 −0
Original line number Diff line number Diff line
.idea

coverage
lib-cov
*.seed
*.log

.jshintrc

0 → 100644
+102 −0
Original line number Diff line number Diff line
{
  // --------------------------------------------------------------------
  // Based on JSHint Configuration, Strict Edition
  // See https://gist.github.com/haschek/2595796
  // --------------------------------------------------------------------

  // == Enforcing Options ===============================================
  // http://www.jshint.com/docs/options/#enforcing-options
  //
  // These options tell JSHint to be more strict towards your code. Use
  // them if you want to allow only a safe subset of JavaScript, very
  // useful when your codebase is shared with a big number of developers
  // with different skill levels.

  "bitwise"       : true,     // Prohibit bitwise operators (&, |, ^, etc.).
  "curly"         : false,     // Require {} for every new block or scope.
  "eqeqeq"        : true,     // Require triple equals i.e. `===`.
  "forin"         : true,     // Tolerate `for in` loops without `hasOwnPrototype`.
  "immed"         : true,     // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
  "latedef"       : false,     // Prohibit variable use before definition.
  "newcap"        : true,     // Require capitalization of all constructor functions e.g. `new F()`.
  "noarg"         : true,     // Prohibit use of `arguments.caller` and `arguments.callee`.
  "noempty"       : true,     // Prohibit use of empty blocks.
  "nonew"         : true,     // Prohibit use of constructors for side-effects.
  "plusplus"      : true,     // Prohibit use of `++` & `--`.
  "regexp"        : true,     // Prohibit `.` and `[^...]` in regular expressions.
  "undef"         : true,     // Require all non-global variables be declared before they are used.
  "strict"        : false,     // Require `use strict` pragma in every file.
  "trailing"      : true,     // Prohibit trailing whitespaces.

  // == Relaxing Options ================================================
  // http://www.jshint.com/docs/options/#relaxing-options
  //
  // These options allow you to suppress certain types of warnings. Use
  // them only if you are absolutely positive that you know what you are
  // doing.

  "asi"           : true,    // Tolerate Automatic Semicolon Insertion (no semicolons).
  "boss"          : false,    // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments.
  "debug"         : false,    // Allow debugger statements e.g. browser breakpoints.
  "eqnull"        : false,    // Tolerate use of `== null`.
  "es5"           : false,    // Allow EcmaScript 5 syntax.
  "esnext"        : false,    // Allow ES.next specific features such as `const` and `let`.
  "evil"          : false,    // Tolerate use of `eval`.
  "expr"          : false,    // Tolerate `ExpressionStatement` as Programs.
  "funcscope"     : false,    // Tolerate declarations of variables inside of control structures while accessing them later from the outside.
  "globalstrict"  : false,    // Allow global "use strict" (also enables 'strict').
  "iterator"      : false,    // Allow usage of __iterator__ property.
  "lastsemic"     : false,    // Tolerate missing semicolons when the it is omitted for the last statement in a one-line block.
  "laxbreak"      : false,    // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons.
  "laxcomma"      : false,    // Suppress warnings about comma-first coding style.
  "loopfunc"      : false,    // Allow functions to be defined within loops.
  "multistr"      : false,    // Tolerate multi-line strings.
  "onecase"       : false,    // Tolerate switches with just one case.
  "proto"         : false,    // Tolerate __proto__ property. This property is deprecated.
  "regexdash"     : false,    // Tolerate unescaped last dash i.e. `[-...]`.
  "scripturl"     : false,    // Tolerate script-targeted URLs.
  "smarttabs"     : false,    // Tolerate mixed tabs and spaces when the latter are used for alignmnent only.
  "shadow"        : false,    // Allows re-define variables later in code e.g. `var x=1; x=2;`.
  "sub"           : true,     // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`.
  "supernew"      : false,    // Tolerate `new function () { ... };` and `new Object;`.
  "validthis"     : false,    // Tolerate strict violations when the code is running in strict mode and you use this in a non-constructor function.

  // == Environments ====================================================
  // http://www.jshint.com/docs/options/#environments
  //
  // These options pre-define global variables that are exposed by
  // popular JavaScript libraries and runtime environments—such as
  // browser or node.js.

  "browser"       : false,    // Standard browser globals e.g. `window`, `document`.
  "couch"         : false,    // Enable globals exposed by CouchDB.
  "devel"         : false,    // Allow development statements e.g. `console.log();`.
  "dojo"          : false,    // Enable globals exposed by Dojo Toolkit.
  "jquery"        : false,    // Enable globals exposed by jQuery JavaScript library.
  "mootools"      : false,    // Enable globals exposed by MooTools JavaScript framework.
  "node"          : true,     // Enable globals available when code is running inside of the NodeJS runtime environment.
  "nonstandard"   : false,    // Define non-standard but widely adopted globals such as escape and unescape.
  "prototypejs"   : false,    // Enable globals exposed by Prototype JavaScript framework.
  "rhino"         : false,    // Enable globals available when your code is running inside of the Rhino runtime environment.
  "wsh"           : false,    // Enable globals available when your code is running as a script for the Windows Script Host.

  // Additional globals introduced by Mocha
  "globals": {
    "describe"    : false,
    "it"          : false,
    "before"      : false,
    "after"       : false,
    "Promise"     : true      // See: https://github.com/jshint/jshint/issues/1747
  },

  // == JSLint Legacy ===================================================
  // http://www.jshint.com/docs/options/#legacy
  //
  // These options are legacy from JSLint. Aside from bug fixes they will
  // not be improved in any way and might be removed at any point.

  "nomen"         : false,    // Prohibit use of initial or trailing underbars in names.
  "onevar"        : false,    // Allow only one `var` statement per function.
  "passfail"      : false,    // Stop on first error.
  "white"         : false     // Check against strict whitespace and indentation rules.
}
 No newline at end of file
+13 −0
Original line number Diff line number Diff line
@@ -70,4 +70,17 @@ rp(options)
  .catch(console.error);
```

## Contributing

To set up your development environment:

1. clone the repo to your desktop,
2. in the shell `cd` to the main folder,
3. hit `npm install`, and
4. run `gulp dev`.

`gulp dev` watches all source files and if you save some changes it will lint the code and execute all tests. The test coverage report can be viewed from `./coverage/lcov-report/index.html`.

If you want to debug a test you should use `gulp test-without-coverage` to run all tests without obscuring the code by the test coverage instrumentation.

## MIT Licenced

gulpfile.js

0 → 100644
+85 −0
Original line number Diff line number Diff line
'use strict';

var gulp = require('gulp');
var runSequence = require('run-sequence');
var jshint = require('gulp-jshint');
var jshintStylish = require('jshint-stylish');
var istanbul = require('gulp-istanbul');
var mocha = require('gulp-mocha');
var chalk = require('chalk');
var rimraf = require('rimraf');


var paths = {
    libJsFiles: './lib/**/*.js',
    gulpfile: './gulpfile.js',
    specFiles: './test/**/*.js'
};


gulp.task('dev', ['watch', 'validate']);

gulp.task('watch', function () {

    return gulp.watch([
        paths.libJsFiles,
        paths.gulpfile,
        paths.specFiles
    ], [
        'validate'
    ]);

});

gulp.task('validate', function (done) {
    runSequence('lint', 'test', done);
});

gulp.task('lint', function () {

    return gulp.src([paths.libJsFiles, paths.gulpfile, paths.specFiles])
        .pipe(jshint())
        .pipe(jshint.reporter(jshintStylish))
        .pipe(jshint.reporter('fail'));

});

gulp.task('test', ['clean'], function (done) {

    var coverageVariable = '$$cov_' + new Date().getTime() + '$$';

    gulp.src(paths.libJsFiles)
        .pipe(istanbul({
            coverageVariable: coverageVariable
        }))
        .on('finish', function () {

            gulp.src(paths.specFiles)
                .pipe(mocha())
                .on('error', function () {
                    console.log(chalk.bold.bgRed(' TESTS FAILED '));
                    done();
                })
                .pipe(istanbul.writeReports({
                    reporters: ['lcov'],
                    coverageVariable: coverageVariable
                }))
                .on('end', done);

        });

});

gulp.task('test-without-coverage', function () {

    return gulp.src(paths.specFiles)
        .pipe(mocha())
        .on('error', function () {
            console.log(chalk.bold.bgRed(' TESTS FAILED '));
        });

});

gulp.task('clean', function (done) {
    rimraf('./coverage', done);
});
Loading