From 79f8f811050ae9fb575a0394d7dd9ebef843d1da Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Wed, 9 Apr 2014 14:53:57 +0200 Subject: [PATCH] [WO-307] add node support, activate unit tests --- .travis.yml | 1 - Gruntfile.js | 23 ++++++++++++++++++++--- package.json | 8 ++++---- src/mailbuild.js | 2 ++ test/index.html | 4 ---- test/index.js | 5 +++-- test/mailbuild-unit.js | 9 +++++++-- 7 files changed, 36 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0156156..b9e5bbc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: node_js node_js: - - "0.8" - "0.10" - "0.11" before_install: diff --git a/Gruntfile.js b/Gruntfile.js index fb4a094..8110107 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -17,15 +17,32 @@ module.exports = function(grunt) { base: '.', keepalive: true } + }, + test: { + options: { + port: 12346, + base: '.' + } } }, - mocha_phantomjs: { + mochaTest: { all: { options: { reporter: 'spec' }, - src: ['test/index.html'] + src: ['test/*-unit.js'] + } + }, + + mocha_phantomjs: { + all: { + options: { + reporter: 'spec', + urls: [ + 'http://localhost:12346/test/index.html' + ] + } } } }); @@ -38,5 +55,5 @@ module.exports = function(grunt) { // Tasks grunt.registerTask('dev', ['connect:dev']); - grunt.registerTask('default', ['jshint', 'mocha_phantomjs']); + grunt.registerTask('default', ['jshint', 'mochaTest', 'connect:test', 'mocha_phantomjs']); }; \ No newline at end of file diff --git a/package.json b/package.json index 9c17367..177d768 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mailbuild", - "version": "0.1.0", + "version": "0.2.0", "homepage": "https://github.com/whiteout-io/mailbuild", "description": "mailbuild is a low level rfc2822 message composer. Define your own mime tree, no magic included.", "author": "Andris Reinman ", @@ -18,7 +18,7 @@ }, "main": "src/mailbuild", "dependencies": { - "mimefuncs": "https://github.com/whiteout-io/mimefuncs/tarball/v0.1.5", + "mimefuncs": "https://github.com/whiteout-io/mimefuncs/tarball/v0.2.0", "mimetypes": " https://github.com/whiteout-io/mimetypes/tarball/v0.1.1", "addressparser": "https://github.com/whiteout-io/addressparser/tarball/v0.1.2", "punycode": "~1.2.4" @@ -29,12 +29,12 @@ "grunt-mocha-phantomjs": "~0.4.0", "grunt-contrib-connect": "~0.6.0", "grunt-contrib-jshint": "~0.8.0", - "grunt-mocha-test": "~0.8.1", + "grunt-mocha-test": "~0.10.0", "mocha": "~1.16.2", "phantomjs": "~1.9.7-1", "requirejs": "~2.1.10", "arraybuffer-slice": "~0.0.2", - "stringencoding": "https://github.com/whiteout-io/stringencoding/tarball/v0.1.0" + "amdefine": "^0.1.0" }, "volo": {} } \ No newline at end of file diff --git a/src/mailbuild.js b/src/mailbuild.js index bbea51e..1f42b06 100644 --- a/src/mailbuild.js +++ b/src/mailbuild.js @@ -23,6 +23,8 @@ if (typeof define === 'function' && define.amd) { define(['mimefuncs', 'mimetypes', 'punycode', 'addressparser'], factory); + } else if (typeof exports === 'object') { + module.exports = factory(require('mimefuncs'), require('mimetypes'), require('punycode'), require('addressparser')); } else { root.mailbuild = factory(mimefuncs, mimetypes, punycode, addressparser); } diff --git a/test/index.html b/test/index.html index e76dc5f..f0410ed 100644 --- a/test/index.html +++ b/test/index.html @@ -10,10 +10,6 @@ - - - - diff --git a/test/index.js b/test/index.js index 3233e1c..a961808 100644 --- a/test/index.js +++ b/test/index.js @@ -1,14 +1,15 @@ 'use strict'; require.config({ - baseUrl: '../src', + baseUrl: '../', paths: { 'test': '../test', 'chai': '../node_modules/chai/chai', 'addressparser': '../node_modules/addressparser/src/addressparser', 'mimetypes': '../node_modules/mimetypes/src/mimetypes', 'mimefuncs': '../node_modules/mimefuncs/src/mimefuncs', - 'punycode': '../node_modules/punycode/punycode.min' + 'punycode': '../node_modules/punycode/punycode.min', + 'stringencoding': '../node_modules/mimefuncs/node_modules/stringencoding/dist/stringencoding' } }); diff --git a/test/mailbuild-unit.js b/test/mailbuild-unit.js index 31d267b..0e9cfbd 100644 --- a/test/mailbuild-unit.js +++ b/test/mailbuild-unit.js @@ -1,5 +1,10 @@ -define(['chai', 'mailbuild'], function(chai, mailbuild) { - 'use strict'; +'use strict'; + +if (typeof define !== 'function') { + var define = require('amdefine')(module); +} + +define(['chai', '../src/mailbuild'], function(chai, mailbuild) { var expect = chai.expect; chai.Assertion.includeStack = true;