diff --git a/Makefile b/Makefile index e55e6eb..79c9a79 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,14 @@ bin = $(shell npm bin) browserify = $(bin)/browserify +node_modules = $(shell pwd)/node_modules +karma = $(node_modules)/karma/bin/karma +karma_conf = $(shell pwd)/spec/karma.conf.js + +.PHONY: example test + example: $(browserify) examples/app.js -r ./src/main.js:'rocket-launcher' > examples/app.bundle.js + +test: + $(karma) start $(karma_conf) --single-run diff --git a/package.json b/package.json index 990bad6..5c4fc3c 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "example": "examples" }, "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "make test" }, "repository": { "type": "git", @@ -31,6 +31,12 @@ }, "homepage": "https://github.com/seedofjoy/rocket-launcher", "devDependencies": { - "browserify": "^9.0.3" + "browserify": "^9.0.3", + "karma": "^0.12.31", + "karma-browserify": "^4.0.0", + "karma-jasmine": "^0.3.5", + "karma-phantomjs-launcher": "^0.1.4", + "phantomjs": "^1.9.16", + "proxyquireify": "^1.2.2" } } diff --git a/spec/karma.conf.js b/spec/karma.conf.js new file mode 100644 index 0000000..dec7dc6 --- /dev/null +++ b/spec/karma.conf.js @@ -0,0 +1,42 @@ +module.exports = function(config) { + config.set({ + basePath: '', + + frameworks: ['browserify', 'jasmine'], + + files: [ + '**/*Spec.js' + ], + + exclude: [], + + preprocessors: { + '**/*Spec.js': ['browserify'] + }, + + reporters: ['progress'], + + port: 9876, + + colors: true, + + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG + logLevel: config.LOG_INFO, + + autoWatch: false, + + browsers: ['PhantomJS'], + + plugins: [ + 'karma-browserify', + 'karma-jasmine', + 'karma-phantomjs-launcher' + ], + + browserify: { + plugin: ['proxyquireify/plugin'] + }, + + singleRun: false + }); +}; diff --git a/spec/main/mainSpec.js b/spec/main/mainSpec.js new file mode 100644 index 0000000..85d396e --- /dev/null +++ b/spec/main/mainSpec.js @@ -0,0 +1,35 @@ +function appendDiv() { + var node = document.createElement('div'); + node.setAttribute('test-node', ''); + document.body.appendChild(node); + return node; +} + +describe("main", function() { + var launcher = require('../../src/main.js'); + + beforeEach(function() { + }); + + afterEach(function() { + // Array.prototype.forEach.call( + // document.querySelectorAll('[test-node]'), + // function (el) { + // el.remove(); + // } + // ); + }); + + it("should run component function", function(done) { + var node = appendDiv(); + node.setAttribute('data-launcher', 'testComponent'); + + var component = function (element, opts) { + done(); + }; + + launcher({ + 'testComponent': component + }); + }); +}); diff --git a/spec/support/jasmine.json b/spec/support/jasmine.json new file mode 100644 index 0000000..a5f2932 --- /dev/null +++ b/spec/support/jasmine.json @@ -0,0 +1,9 @@ +{ + "spec_dir": "spec", + "spec_files": [ + "**/*[sS]pec.js" + ], + "helpers": [ + "helpers/**/*.js" + ] +}