Skip to content

feat: Now works when qrcode.js is availiable only as AMD #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var rename = require('gulp-rename');
var jshint = require('gulp-jshint');
var karma = require('gulp-karma');
var changelog = require('conventional-changelog');
var es = require('event-stream');

var now = new Date();
var year = dateformat(now, "yyyy");
Expand All @@ -25,7 +26,7 @@ var banner = [
].join('\n');

var codeFiles = ['src/*.js'];
var testFiles = ['bower_components/angular/angular.js', 'bower_components/angular-mocks/angular-mocks.js', 'lib/qrcode.js', 'src/*.js', 'test/*.spec.js'];
var testFiles = ['bower_components/angular/angular.js', 'bower_components/angular-mocks/angular-mocks.js', 'bower_components/qrcode/lib/qrcode.js', 'src/*.js', 'test/*.spec.js'];

gulp.task('lint', function(){
log('Linting Files');
Expand All @@ -34,7 +35,7 @@ gulp.task('lint', function(){
.pipe(jshint.reporter());
});

gulp.task('karma', function () {
gulp.task('karma-vanilla', function () {

var options = {
configFile: 'karma.conf.js',
Expand All @@ -49,6 +50,30 @@ gulp.task('karma', function () {
.pipe(karma(options));
});

gulp.task('karma-amd', function () {

var options = {
configFile: 'karma-amd.conf.js',
action: 'run'
};

if (process.env.TRAVIS) {
options.browsers = ['Firefox'];
}

return gulp.src(testFiles.concat('test/requirejs-main.js'))
.pipe(es.map(function(data, cb){
data.path = {
pattern: data.path,
included: /requirejs-main\.js$/.test(data.path),
};
cb(null, data);
}))
.pipe(karma(options));
});

gulp.task('karma', ['karma-vanilla', 'karma-amd']);

gulp.task('build', function() {
return gulp.src(codeFiles)
.pipe(uglify({'evil': true}))
Expand Down
10 changes: 10 additions & 0 deletions karma-amd.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = function(config) {
config.set({
basePath: '',
files: [
// set by gulp
],
frameworks: ['jasmine', 'requirejs'],
browsers: [ 'Chrome' ]
});
};
25 changes: 17 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,35 @@
"name": "angular-qr",
"version": "0.2.0",
"description": "QR code generator for AngularJS",
"keywords": ["qr", "qrcode", "angular"],
"authors": ["Jan Antala <[email protected]>"],
"keywords": [
"qr",
"qrcode",
"angular"
],
"authors": [
"Jan Antala <[email protected]>"
],
"license": "MIT",
"homepage": "https://github.com/janantala/angular-qr",
"main": "./src/angular-qr.js",
"dependencies": {},
"devDependencies": {
"conventional-changelog": "~0.0.11",
"event-stream": "^3.2.2",
"gulp": "~3.5.0",
"gulp-util": "~2.2.9",
"gulp-uglify": "~0.2.0",
"gulp-header": "~1.0.2",
"gulp-concat": "~2.1.7",
"gulp-rename": "~0.2.2",
"gulp-header": "~1.0.2",
"gulp-jshint": "~1.3.4",
"gulp-karma": "~0.0.2",
"gulp-rename": "~0.2.2",
"gulp-uglify": "~0.2.0",
"gulp-util": "~2.2.9",
"karma": "~0.12.1",
"karma-jasmine": "~0.2.2",
"karma-chrome-launcher": "~0.1.2",
"karma-firefox-launcher": "~0.1.3",
"conventional-changelog": "~0.0.11"
"karma-jasmine": "~0.2.2",
"karma-requirejs": "^0.2.2",
"requirejs": "^2.1.15"
},
"scripts": {},
"repository": {
Expand Down
6 changes: 2 additions & 4 deletions src/angular-qr.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
(function(QRCode){
'use strict';

((function(define){'use strict'; define(['angular', 'QRCode'], function(angular, QRCode){
angular.module('ja.qr', [])
.controller('QrCtrl', ['$scope', function($scope){
$scope.getTypeNumeber = function(){
Expand Down Expand Up @@ -178,4 +176,4 @@
};
}]);

})(window.QRCode);
});})(window.define?window.define:function(deps, module){'use strict'; return module(window.angular, window.QRCode);}));
39 changes: 39 additions & 0 deletions test/requirejs-main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* global requirejs */
'use strict';
var tests = [];
for (var file in window.__karma__.files) {
if (window.__karma__.files.hasOwnProperty(file)) {
if (/spec\.js$/i.test(file)) {
tests.push(file);
}
}
}

requirejs.config({
// Karma serves files from '/base'
baseUrl: '/base/',

paths: {
'angular': 'bower_components/angular/angular',
'angular-mocks': 'bower_components/angular-mocks/angular-mocks',
'QRCode': 'bower_components/qrcode/lib/qrcode',
},

shim: {
'angular': {
exports: 'angular'
},
'angular-mocks' : {
exports: 'angular.mock',
deps: ['angular'],
},
'/base/test/unit.spec.js' : {
deps: ['angular-mocks']
}
},

// ask Require.js to load these files (all our tests)
deps: tests,
// start test run, once Require.js is done
callback: window.__karma__.start
});
9 changes: 6 additions & 3 deletions test/unit.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* jshint jasmine: true */
((function(define){'use strict'; define(['angular', 'src/angular-qr'], function(angular){
describe('ja.qr', function() {

beforeEach(module('ja.qr'));
beforeEach(angular.mock.module('ja.qr'));

// var elm, scope, ctrl;

Expand All @@ -15,7 +17,7 @@ describe('ja.qr', function() {
describe('QrCtrl', function() {

var scope, ctrl;
beforeEach(inject(function($rootScope, $controller) {
beforeEach(angular.mock.inject(function($rootScope, $controller) {
scope = $rootScope.$new();
ctrl = $controller('QrCtrl', {$scope: scope });
}));
Expand Down Expand Up @@ -74,4 +76,5 @@ describe('ja.qr', function() {
});

});
});
});
});})(window.define?window.define:function(deps, module){'use strict'; return module(window.angular);}));