diff --git a/.coveralls-dist.yml b/.coveralls-dist.yml new file mode 100644 index 0000000..68a9d46 --- /dev/null +++ b/.coveralls-dist.yml @@ -0,0 +1 @@ +repo_token: diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..93968aa --- /dev/null +++ b/.gitignore @@ -0,0 +1,37 @@ +# Logs +logs +*.log + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +.coveralls.yml + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directory +# Commenting this out is preferred by some people, see +# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- +node_modules + +# Users Environment Variables +.lock-wscript + +# Skip idea files +.idea + +dev/ +config/config.js +artifact/ +.DS_Store diff --git a/.jscsrc b/.jscsrc new file mode 100644 index 0000000..4d182fe --- /dev/null +++ b/.jscsrc @@ -0,0 +1,118 @@ +{ + "requireCurlyBraces": [ + "if", + "else", + "for", + "while", + "do" + ], + "requireSpaceAfterKeywords": [ + "if", + "else", + "for", + "while", + "do", + "switch", + "return", + "catch" + ], + "requireSpacesInFunctionExpression": { + "beforeOpeningCurlyBrace": true + }, +// "disallowSpacesInFunctionExpression": { +// "beforeOpeningRoundBrace": true +// }, + "disallowKeywords": [ + "with" + ], + "disallowKeywordsOnNewLine": [ + "else", + "catch" + ], + + "disallowSpaceAfterPrefixUnaryOperators": true, + "disallowSpaceBeforePostfixUnaryOperators": [ + "++", + "--" + ], + "requireSpaceBeforeBinaryOperators": true, + "requireSpaceAfterBinaryOperators": true, + + "disallowSpacesInsideParentheses": true, + "disallowEmptyBlocks": true, + + "requireParenthesesAroundIIFE": true, + "requireSpacesInFunctionDeclaration": { + "beforeOpeningCurlyBrace": true + }, + "disallowSpacesInFunctionDeclaration": { + "beforeOpeningRoundBrace": true + }, + "requireSpacesInAnonymousFunctionExpression": { + "beforeOpeningCurlyBrace": true + }, + "disallowSpacesInNamedFunctionExpression": { + "beforeOpeningRoundBrace": true + }, + "requireSpacesInNamedFunctionExpression": { + "beforeOpeningCurlyBrace": true + }, + + "requireSpacesInConditionalExpression": { + "afterTest": true, + "beforeConsequent": true, + "afterConsequent": true, + "beforeAlternate": true + }, + + "disallowSpaceBeforeBinaryOperators": [ + "," + ], + "requireCommaBeforeLineBreak": true, + + "validateQuoteMarks": { + "escape": true, + "mark": "'" + }, + "disallowMultipleLineStrings": true, + + "disallowImplicitTypeConversion": [ + "numeric", + "boolean", + "binary", + "string" + ], + "disallowYodaConditions": true, + + "disallowSpacesInsideArrayBrackets": true, + + "requireDotNotation": true, + "disallowSpaceAfterObjectKeys": true, + "disallowQuotedKeysInObjects": "allButReserved", + + "jsDoc": { + "checkParamNames": true, + "requireParamTypes": true + }, + + "maximumLineLength": { + "value": 120, + "allowUrlComments": true + }, +// "requireSpaceAfterLineComment": true, + "requireLineFeedAtFileEnd": true, + "disallowMultipleLineBreaks": true, + "disallowMixedSpacesAndTabs": true, + "disallowTrailingWhitespace": true, + "validateLineBreaks": "LF", + + "disallowTrailingComma": true, +// "requireMultipleVarDecl": true, +// "requireSpacesInsideObjectBrackets": "all", +// "requireSpacesInsideArrayBrackets": "all", + + "requireCamelCaseOrUpperCaseIdentifiers": true, +// "requireCapitalizedConstructors": true, + + "excludeFiles": ["node_modules/**"] +} \ No newline at end of file diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..efe65ec --- /dev/null +++ b/.jshintrc @@ -0,0 +1,48 @@ +// http://www.jshint.com/docs/options/ +{ + // This option prohibits the use of bitwise operators such as ^ (XOR), | (OR) and others. Bitwise operators are very rare in JavaScript programs and quite often & is simply a mistyped &&. + "bitwise": true, + // "camelcase": false, + // This option requires you to always put curly braces around blocks in loops and conditionals. JavaScript allows you to omit curly braces when the block consists of only one statement. + "curly": true, + // This options prohibits the use of == and != in favor of === and !==. The former try to coerce values before comparing them which can lead to some unexpected results. The latter don't do any coercion so they are generally safer. + "eqeqeq": true, + // This option enables syntax first defined in the ECMAScript 5.1 specification. This includes allowing reserved keywords as object properties. +// "es5": true, + // This options prohibits overwriting prototypes of native objects such as Array, Date and so on. + "freeze": true, + // This option enables warnings about the use of identifiers which are defined in future versions of JavaScript. Although overwriting them has no effect in contexts where they are not implemented, this practice can cause issues when migrating codebases to newer versions of the language. + "futurehostile": true, + // This option requires all for in loops to filter object's items. The for in statement allows for looping through the names of all of the properties of an object including those inherited through the prototype chain. This behavior can lead to unexpected items in your object so it is generally safer to always filter inherited properties out. + "forin": true, + // This option prohibits the use of a variable before it was defined. JavaScript has function scope only and, in addition to that, all variables are always moved—or hoisted— to the top of the function. + "latedef": "nofunc", + // This option lets you control how nested do you want your blocks to be. + "maxdepth": 5, + // This option lets you set the max number of formal parameters allowed per function. + "maxparams": 5, + // This option lets you set the max number of statements allowed per function. +// "maxstatements": 5, + // This option prohibits the use of arguments.caller and arguments.callee. Both .caller and .callee make quite a few optimizations impossible so they were deprecated in future versions of JavaScript. In fact, ECMAScript 5 forbids the use of arguments.callee in strict mode. + "noarg": true, + // This option prohibits the use of constructor functions for side-effects. Some people like to call constructor functions without assigning its result to any variable. + "nonew": true, + // This option prohibits the use of the comma operator. When misused, the comma operator can obscure the value of a statement and promote incorrect code. + "nocomma": true, + // This option warns about "non-breaking whitespace" characters. These characters can be entered with option-space on Mac computers and have a potential of breaking non-UTF8 web pages. + "nonbsp": true, + // This option requires all functions to run in ECMAScript 5's strict mode. Strict mode is a way to opt in to a restricted variant of JavaScript. Strict mode eliminates some JavaScript pitfalls that didn't cause errors by changing them to produce errors. It also fixes mistakes that made it difficult for the JavaScript engines to perform certain optimizations. + "strict": true, + // This option prohibits the use of explicitly undeclared variables. This option is very useful for spotting leaking and mistyped variables. + "undef": true, + // This option warns when you define and never use your variables. It is very useful for general code cleanup, especially when used in addition to undef. + "unused": true, + // This option suppresses warnings about the use of assignments in cases where comparisons are expected. More often than not, code like if (a = 10) {} is a typo. + "boss": true, + // This option suppresses warnings about == null comparisons. Such comparisons are often useful when you want to check if a variable is null or undefined. + "eqnull": true, + // This option tells JSHint that your code uses ECMAScript 6 specific syntax. Note that these features are not finalized yet and not all browsers implement them. + "esnext": true, + // This option defines globals available when your code is running inside of the Node runtime environment. Node.js is a server-side JavaScript environment that uses an asynchronous event-driven model. + "node": true +} \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..0a0415b --- /dev/null +++ b/.travis.yml @@ -0,0 +1,16 @@ +language: node_js +node_js: + - '4.3' + - '5.11' + - '6.2' +matrix: +# allow_failures: +# - node_js: "4.3" + fast_finish: true +before_install: npm install -g grunt-cli +install: + - npm install + - npm install -g npm +notifications: + email: + on_failure: always diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..9b4b3e5 --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,117 @@ +/* + * https://github.com/5orenso + * + * Copyright (c) 2016 Øistein Sørensen + * Licensed under the MIT license. + */ +'use strict'; + +module.exports = function (grunt) { + // Project configuration. + grunt.initConfig({ + pkg: grunt.file.readJSON('package.json'), + + jshint: { + options: { + jshintrc: '.jshintrc' + }, + gruntfile: { + src: 'Gruntfile.js' + }, + lib: { + src: ['app/**/*.js', 'lib/**/*.js'] + }, + test: { + src: ['test/**/*.js'] + } + }, + + jscs: { + main: ['app/**/*.js', 'lib/**/*.js', 'test/**/*.js'], + options: { + config: ".jscsrc" + } + }, + + watch: { + all: { + files: ['app/**/*.js', 'lib/**/*.js', 'test/**/*.js', 'config/*.js'], + tasks: ['lint', 'buster:unit'] + } + }, + + buster: { + unit: { + } + }, + + nodemon: { + dev: { + options: { + file: 'app/app.js', + args: ['-c', 'config/config-dist.js'] + }, + tasks: ['lint', 'buster:unit'] + } + }, + + shell: { + getLatestTag: { + command: 'git describe --abbrev=0 --tags', + options: { + callback: function (err, stdout, stderr, cb) { + stdout = stdout.trim(); + // If we have a leading 'v' in the version, remove it + if (stdout.substring(0, 1) === 'v') { + stdout = stdout.substring(1); + } + console.log('Latest tag: ' + stdout); + grunt.config.set('latestTag', stdout); + console.log('s3cmd put artifact/' + stdout + '.tar.gz s3://geo-lib-releases/'); + console.log(''); + console.log('PS! Remember to upload a corresponding config tar-ball to s3://geo-lib--configs'); + cb(); + } + } + }, + multiple: { + command: [ + 'mkdir -p artifact', + 'mv ./node_modules ./node_modules2', + 'npm install --production', + 'tar --exclude "./.git*" --exclude "./node_modules2" --exclude "./test*" --exclude "./coverage" --exclude "./artifact" --exclude "./app/config/config*" --exclude "./.idea" --exclude "./dev" -zcf artifact/<%= latestTag %>.tar.gz .', + 'rm -rf node_modules', + 'mv ./node_modules2 ./node_modules', + 'bash changelog.sh' + ].join('&&') + } + }, + + coveralls: { + real_coverage: { + src: 'coverage/lcov.info' + } + } + + }); + + // These plugins provide necessary tasks. + grunt.loadNpmTasks('grunt-contrib-nodeunit'); + grunt.loadNpmTasks('grunt-contrib-jshint'); + grunt.loadNpmTasks('grunt-contrib-watch'); + grunt.loadNpmTasks('grunt-nodemon'); + grunt.loadNpmTasks('grunt-shell'); + grunt.loadNpmTasks('grunt-buster'); + grunt.loadNpmTasks("grunt-jscs"); + grunt.loadNpmTasks('grunt-coveralls'); + + // Default task. + grunt.registerTask( "lint", [ "jshint", "jscs" ] ); + grunt.registerTask('default', ['lint', 'buster:unit']); + grunt.registerTask('test', 'buster:unit'); + grunt.registerTask('check', ['watch']); + grunt.registerTask('run', ['buster:unit', 'nodemon:dev']); + grunt.registerTask('artifact', ['shell', 'coveralls:real_coverage']); + grunt.registerTask('report', ['coveralls:real_coverage']); + +}; diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..acf3bde --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2014 Øistein Sørensen + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..e4e7dca --- /dev/null +++ b/README.md @@ -0,0 +1,66 @@ +# Boilerplate for your brand new Node.js module - NPM ready + +[![Build Status](https://travis-ci.org/5orenso/geo-lib.svg?branch=master)](https://travis-ci.org/5orenso/geo-lib) +[![Coverage Status](https://coveralls.io/repos/github/5orenso/geo-lib/badge.svg?branch=master)](https://coveralls.io/github/5orenso/geo-lib?branch=master) + +Placeholder for my new geo-lib module. This is going to be a useful Node.js module built with performance and speed as +priority one. + +### Howto to get started +```bash +git clone git@github.com:5orenso/geo-lib.git +cd geo-lib/ +npm install +``` + +Start developing. Remember to start watching your files: +```bash +grunt watch +``` + +### Howto contribute + +```bash +git clone git@github.com:5orenso/geo-lib.git +``` +Do your magic and create a pull request. + + +### Howto report issues +Use the [Issue tracker](https://github.com/5orenso/geo-lib/issues) + + +### Howto update CHANGELOG.md +```bash +$ bash ./changelog.sh +``` + +### Howto upgrade modules +```bash +$ npm install -g npm-check-updates +$ ncu -u +$ npm install --save --no-optional +``` + + +### HOWTO upgrade dev environment +```bash +npm install buster --save-dev +npm install buster-istanbul --save-dev +npm install grunt --save-dev +npm install grunt-buster --save-dev +npm install grunt-contrib-jshint --save-dev +npm install grunt-contrib-nodeunit --save-dev +npm install grunt-contrib-watch --save-dev +npm install grunt-coveralls --save-dev +npm install grunt-jscs --save-dev +npm install grunt-nodemon --save-dev +npm install grunt-shell --save-dev +``` + + +## More about the author + +- Twitter: [@sorenso](https://twitter.com/sorenso) +- Instagram: [@sorenso](https://instagram.com/sorenso) +- Facebook: [@sorenso](https://facebook.com/sorenso) diff --git a/app/app.js b/app/app.js new file mode 100644 index 0000000..1de34f8 --- /dev/null +++ b/app/app.js @@ -0,0 +1,15 @@ +/* + * https://github.com/5orenso + * + * Copyright (c) 2016 Øistein Sørensen + * Licensed under the MIT license. + */ +'use strict'; + +var path = require('path'), + appPath = path.normalize(__dirname + '/../'); + +var App = require(appPath + 'lib/my-app'); +var app = new App(); + +module.exports = app; diff --git a/changelog.sh b/changelog.sh new file mode 100644 index 0000000..37d76b7 --- /dev/null +++ b/changelog.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +# Get repo base and name. +REPO=`git remote show origin | perl -ne 'if (/Fetch URL:/) { $_=~s/^.+Fetch URL:\s*.+?:(.+)(\.git)$/$1/; print $_ }'` + +# Make changelog based on commit history. +git log --date=short --pretty=format:'* _%ad_: %s%d [%an] view commit' > CHANGELOG.md diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..c49aa6f --- /dev/null +++ b/install.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +echo 'You should probably do this first:' +echo '1. Generate a new repo on github.com.' +echo '2. Clone repo to you project home dir.' +echo '3. Enter path of new repo without trailing slash: ' +read PATH + +# Make paths we need +/bin/mkdir -p $PATH/logs + +# Copying paths +/bin/cp -Rv app $PATH/. +/bin/cp -Rv lib $PATH/. +/bin/cp -Rv test $PATH/. + +# Copying files +/bin/cp -v .coveralls-dist.yml $PATH/. +/bin/cp -v .gitignore $PATH/. +/bin/cp -v .jscsrc $PATH/. +/bin/cp -v .jshintrc $PATH/. +/bin/cp -v .travis.yml $PATH/. +/bin/cp -v Gruntfile.js $PATH/. +/bin/cp -v LICENSE $PATH/. +/bin/cp -v README.md $PATH/. +/bin/cp -v changelog.sh $PATH/. +/bin/cp -v install.sh $PATH/. +/bin/cp -v package.json $PATH/. +/bin/cp -v run-app.sh $PATH/. +/bin/cp -v run-tests.sh $PATH/. +/bin/cp -v run-watch.sh $PATH/. +/bin/cp -v npm-release.sh $PATH/. + +cd $PATH +/bin/cp -v ./.coveralls-dist.yml ./.coveralls.yml + +echo '' +echo 'Todo:' +echo '1. Update coveralls.yml with the correct token.' +echo '2. Run `npm install`' +echo '3. Run you app `./run-app.sh`.' +echo '' +echo 'All set :)' +echo '' diff --git a/lib/date.js b/lib/date.js new file mode 100644 index 0000000..3677433 --- /dev/null +++ b/lib/date.js @@ -0,0 +1,53 @@ +/* + * https://github.com/5orenso + * + * Copyright (c) 2016 Øistein Sørensen + * Licensed under the MIT license. + */ +'use strict'; + +function MyDate(opt) { + var opts = opt || {}; + if (opts.debug) { + console.log(opts); + } +} + +function pad(number) { + let r = String(number); + if (r.length === 1) { + r = '0' + r; + } + return r; +} + +MyDate.prototype.isoDate = (date) => { + // http://en.wikipedia.org/wiki/ISO_8601 + let now; + if (date) { + now = new Date(0); // The 0 there is the key, which sets the date to the epoch + now.setUTCSeconds(date); + } else { + now = new Date(); + } + let mm = now.getMonth() + 1; + let dd = now.getDate(); + let yy = now.getFullYear(); + let hh = now.getHours(); + let mi = now.getMinutes(); + let ss = now.getSeconds(); + let tzo = -now.getTimezoneOffset(), + dif = tzo >= 0 ? '+' : '-'; + + return pad(yy) + '-' + + pad(mm) + '-' + + pad(dd) + 'T' + + pad(hh) + ':' + + pad(mi) + ':' + + pad(ss) + + dif + + pad(tzo / 60) + ':' + + pad(tzo % 60); +}; + +module.exports = MyDate; diff --git a/lib/my-app.js b/lib/my-app.js new file mode 100644 index 0000000..fe75a84 --- /dev/null +++ b/lib/my-app.js @@ -0,0 +1,25 @@ +/* + * https://github.com/5orenso + * + * Copyright (c) 2016 Øistein Sørensen + * Licensed under the MIT license. + */ +'use strict'; + +function MyApp(opt) { + let opts = opt || {}; + if (opts.debug) { + console.log(opts); + } +} + +MyApp.prototype.run = () => { + // Start my application and do all your stuff. + return MyApp.prototype.say('Yo!'); +}; + +MyApp.prototype.say = (text) => { + return text; +}; + +module.exports = MyApp; diff --git a/npm-release.sh b/npm-release.sh new file mode 100644 index 0000000..4c8685e --- /dev/null +++ b/npm-release.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +# To be able to run this script you need jq +# $ brew install jq + +NPM_VERSION=$(jq -r '.version' package.json) +GITHUB_TOKEN=$(perl -ne '/^\s*token\s*=\s*([\s\w@\d,\._-]+)/ && do {print $1; exit;}' ~/.gitconfig) + +JSON=$(cat </dev/null) +echo $GITHUB_RESPONSE | jq '.' + +echo "+ Doing a npm release of version ${NPM_VERSION}" +npm publish diff --git a/package.json b/package.json new file mode 100644 index 0000000..bacb8a7 --- /dev/null +++ b/package.json @@ -0,0 +1,43 @@ +{ + "name": "geo-lib", + "description": "A Node.js module with useful geo functions. Made with performance in mind.", + "version": "0.0.1", + "homepage": "https://github.com/5orenso/geo-lib", + "repository": { + "type": "git", + "url": "https://github.com/5orenso/geo-lib" + }, + "bugs": { + "url": "https://github.com/5orenso/geo-lib/issues" + }, + "author": { + "name": "Øistein Sørensen", + "email": "sorenso@gmail.com" + }, + "main": "app/app.js", + "engines": { + "node": ">=4.3" + }, + "scripts": { + "test": "grunt" + }, + "bin": { + "geo-lib": "./bin/geo-lib" + }, + "devDependencies": { + "buster": "^0.7.18", + "buster-istanbul": "^0.1.13", + "grunt": "^1.0.1", + "grunt-buster": "^0.4.2", + "grunt-contrib-jshint": "^1.0.0", + "grunt-contrib-nodeunit": "^1.0.0", + "grunt-contrib-watch": "^1.0.0", + "grunt-coveralls": "^1.0.0", + "grunt-jscs": "^3.0.0", + "grunt-nodemon": "^0.4.0", + "grunt-shell": "^1.1.2" + }, + "keywords": [], + "dependencies": { + } +} diff --git a/run-app.sh b/run-app.sh new file mode 100755 index 0000000..2ea45eb --- /dev/null +++ b/run-app.sh @@ -0,0 +1,9 @@ +#!/bin/bash +# +# https://github.com/5orenso +# +# Copyright (c) 2016 Øistein Sørensen +# Licensed under the MIT license. +# + +grunt run diff --git a/run-tests.sh b/run-tests.sh new file mode 100755 index 0000000..6306e5b --- /dev/null +++ b/run-tests.sh @@ -0,0 +1,9 @@ +#!/bin/bash +# +# https://github.com/5orenso +# +# Copyright (c) 2016 Øistein Sørensen +# Licensed under the MIT license. +# + +grunt diff --git a/run-watch.sh b/run-watch.sh new file mode 100755 index 0000000..b81bb90 --- /dev/null +++ b/run-watch.sh @@ -0,0 +1,9 @@ +#!/bin/bash +# +# https://github.com/5orenso +# +# Copyright (c) 2016 Øistein Sørensen +# Licensed under the MIT license. +# + +grunt watch diff --git a/test/app-test.js b/test/app-test.js new file mode 100644 index 0000000..2e3e985 --- /dev/null +++ b/test/app-test.js @@ -0,0 +1,28 @@ +/* + * https://github.com/5orenso + * + * Copyright (c) 2016 Øistein Sørensen + * Licensed under the MIT license. + */ +'use strict'; + +var buster = require('buster'), + assert = buster.assert, + path = require('path'), + appPath = path.normalize(__dirname + '/../'); + +buster.testCase('lib/my-app', { + setUp: () => { + }, + tearDown: () => { + delete require.cache[require.resolve(appPath + 'lib/my-app')]; + }, + 'Test module:': { + 'exposed run function w/options': () => { + let app = require(appPath + 'app/app'); + let result = app.run(); + assert.equals(result, 'Yo!'); + } + + } +}); diff --git a/test/buster.js b/test/buster.js new file mode 100644 index 0000000..ce1f70d --- /dev/null +++ b/test/buster.js @@ -0,0 +1,26 @@ +/* + * https://github.com/5orenso + * + * Copyright (c) 2016 Øistein Sørensen + * Licensed under the MIT license. + */ +var config = module.exports; + +config['My tests'] = { + environment: 'node', + rootPath: '../', + tests: [ + 'test/**/*-test.js' + ], + 'buster-istanbul': { + outputDirectory: 'coverage', + format: 'lcov' + }, + sources: [ + 'lib/**/**/*.js', + 'app/**/*.js' + ], + extensions: [ + require('buster-istanbul') + ] +}; diff --git a/test/lib/date-test.js b/test/lib/date-test.js new file mode 100644 index 0000000..b30a40d --- /dev/null +++ b/test/lib/date-test.js @@ -0,0 +1,34 @@ +/* + * https://github.com/5orenso + * + * Copyright (c) 2016 Øistein Sørensen + * Licensed under the MIT license. + */ +'use strict'; + +var buster = require('buster'), + assert = buster.assert, + path = require('path'), + appPath = path.normalize(__dirname + '/../../'), + libDate = require(appPath + 'lib/date'), + date = new libDate(); + +buster.testCase('lib/logger', { + setUp: () => { + }, + tearDown: () => { + }, + 'Date module:': { + 'isoDate wo/input': () => { + let isoDateFormat = date.isoDate(); + assert.match(isoDateFormat, /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[\+\-]\d{2}:\d{2}/); + }, + 'isoDate w/input': () => { + let msec = Date.parse('March 21, 2012') / 1000; + let d = new Date(msec); + let isoDateFormat = date.isoDate(d); + assert.match(isoDateFormat, /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[\+\-]\d{2}:\d{2}/); + assert.match(isoDateFormat, /2012-03-21T00:00:00\+\d{2}:\d{2}/); + } + } +}); diff --git a/test/lib/my-app-test.js b/test/lib/my-app-test.js new file mode 100644 index 0000000..90494b6 --- /dev/null +++ b/test/lib/my-app-test.js @@ -0,0 +1,60 @@ +/* + * https://github.com/5orenso + * + * Copyright (c) 2016 Øistein Sørensen + * Licensed under the MIT license. + */ +'use strict'; + +let buster = require('buster'), + assert = buster.assert, + path = require('path'), + appPath = path.normalize(__dirname + '/../../'); + +buster.testCase('lib/my-app', { + setUp: () => { + }, + tearDown: () => { + delete require.cache[require.resolve(appPath + 'lib/my-app')]; + }, + 'Test module:': { + 'dummy sync test': () => { + assert(true); + }, + + 'dummy async test': (done) => { + // Do some async stuff and call done. + assert(true); + done(); + }, + + 'dummy async w/promises test': (done) => { + function promiseTest(input) { + return new Promise((resolve, reject) => { + if (input) { + resolve(input); + } else { + reject(new Error(input)); + } + }); + } + promiseTest(true) + .then(() => { + assert(true); + done(); + }) + .catch((error) => { + console.log(error); + assert(false); + }); + }, + + 'exposed run function w/options': () => { + let MyApp = require(appPath + 'lib/my-app'); + let myApp = new MyApp(); + let result = myApp.run(); + assert.equals(result, 'Yo!'); + } + + } +});