diff --git a/.gitignore b/.gitignore index 2ccbe46..d49756d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /node_modules/ +/build/ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..c04a207 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: node_js +node_js: + - "0.10" +before_script: + - npm install -g grunt-cli +script: + - grunt + - grunt coverage + - node node_modules/coveralls/bin/coveralls.js < build/reports/coverage/lcov.info diff --git a/Gruntfile.js b/Gruntfile.js index 6f4de4d..f522bb5 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -2,11 +2,14 @@ var path = require("path"); module.exports = function(grunt) { "use strict"; - var jsFiles = ["Gruntfile.js", "src/**/*.js"]; + var jsFiles = ["Gruntfile.js", "src/**/*.js", "test/**/*.js"]; grunt.initConfig({ pkg: grunt.file.readJSON("package.json"), + // cleaning output directories + clean: ["build", "lib"], + // Run JSHint on all sources jshint: { options: { @@ -27,7 +30,7 @@ module.exports = function(grunt) { // browserify for packing all commonjs files browserify: { - client: { + lib: { src: ["src/QRCode.js"], dest: "lib/qrcode.js", options: { @@ -43,16 +46,61 @@ module.exports = function(grunt) { "lib/qrcode.min.js": ["lib/qrcode.js"] } } + }, + + // Run tests using mocha + mochaTest: { + libRaw: { + options: { + require: ["./test/testStandard.js"], + reporter: "spec" + }, + src: ["test/**/*Test.js"] + }, + coverage: { + options: { + require: ["./test/testCoverage.js"], + reporter: "min" + }, + src: ["test/**/*Test.js"] + } + }, + + // tasks for coverage analysis (istanbul) + instrument: { + files: ["src/**/*.js"], + options: { + basePath: "build/instrumented/" + } + }, + storeCoverage: { + options: { + dir: "build/reports/coverage/" + } + }, + makeReport: { + src: "build/reports/coverage/**/*.json", + options: { + type: "lcov", + dir: "build/reports/coverage/", + print: "text-summary" + } } }); grunt.loadNpmTasks("grunt-browserify"); + grunt.loadNpmTasks("grunt-contrib-clean"); grunt.loadNpmTasks("grunt-contrib-jshint"); grunt.loadNpmTasks("grunt-contrib-uglify"); + grunt.loadNpmTasks("grunt-istanbul"); grunt.loadNpmTasks("grunt-jsbeautifier"); + grunt.loadNpmTasks("grunt-mocha-test"); grunt.registerTask("lint", ["jshint", "jsbeautifier"]); + grunt.registerTask("test", ["mochaTest:libRaw"]); grunt.registerTask("compile", ["browserify", "uglify"]); - grunt.registerTask("default", ["lint", "compile"]); + grunt.registerTask("coverage", ["instrument", "mochaTest:coverage", "storeCoverage", "makeReport"]); + + grunt.registerTask("default", ["clean", "lint", "test", "compile"]); }; diff --git a/README.md b/README.md index 5ab79d5..6fade10 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Build Status](https://secure.travis-ci.org/janantala/qrcode.js.png?branch=master)](http://travis-ci.org/janantala/qrcode.js) [![Coverage Status](https://coveralls.io/repos/janantala/qrcode.js/badge.png?branch=master)](https://coveralls.io/r/janantala/qrcode.js?branch=master) + # qrcode.js v1.0.0 QR code generator, supports Numeric, Alphanumeric and Binary inputMode up to lvl 40. diff --git a/package.json b/package.json index 8c209a6..9629cd1 100644 --- a/package.json +++ b/package.json @@ -18,11 +18,17 @@ }, "dependencies": {}, "devDependencies": { + "coveralls": "~2.2.0", + "expect.js": "~0.2.0", "grunt": "~0.4.1", "grunt-browserify": "~1.2.4", + "grunt-contrib-clean": "~0.5.0", "grunt-contrib-jshint": "~0.4.3", "grunt-contrib-uglify": "~0.2.2", - "grunt-jsbeautifier": "~0.2.0" + "grunt-contrib-yuidoc": "~0.4.0", + "grunt-istanbul": "~0.2.2", + "grunt-jsbeautifier": "~0.2.0", + "grunt-mocha-test": "~0.6.3" }, "engines": { "node": ">=0.10.x" diff --git a/test/QRMathTest.js b/test/QRMathTest.js new file mode 100644 index 0000000..4a7add4 --- /dev/null +++ b/test/QRMathTest.js @@ -0,0 +1,23 @@ +/* global describe, it, global */ +var expect = require("expect.js"); + +var QRMath = require(global.resolveSource("QRMath.js")); + +describe("QRMath", function() { + "use strict"; + + describe("glog", function() { + it("should return 1 for 2", function() { + var result = QRMath.glog(2); + + expect(result).to.be(1); + }); + + it("should return 53 for 40", function() { + var result = QRMath.glog(40); + + expect(result).to.be(53); + }); + + }); +}); diff --git a/test/testCoverage.js b/test/testCoverage.js new file mode 100644 index 0000000..f55fa8d --- /dev/null +++ b/test/testCoverage.js @@ -0,0 +1,10 @@ +/* global global, __dirname */ +var path = require("path"); + +var testSourceBase = path.resolve(path.join(__dirname, "..", "build", "instrumented", "src")); + +global.resolveSource = function(file) { + "use strict"; + + return path.join(testSourceBase, file); +}; diff --git a/test/testStandard.js b/test/testStandard.js new file mode 100644 index 0000000..bb37c6d --- /dev/null +++ b/test/testStandard.js @@ -0,0 +1,10 @@ +/* global global, __dirname */ +var path = require("path"); + +var testSourceBase = path.resolve(path.join(__dirname, "..", "src")); + +global.resolveSource = function(file) { + "use strict"; + + return path.join(testSourceBase, file); +};