Wrap code in module wrapper to support both Browser and CommonJS environment
fixes #95
This commit is contained in:
parent
920f8e7771
commit
5dc127d492
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
.idea/
|
.idea/
|
||||||
|
.tmp/
|
||||||
.rvmrc
|
.rvmrc
|
||||||
*.swp
|
*.swp
|
||||||
bower_components
|
bower_components
|
||||||
|
46
Gruntfile.js
46
Gruntfile.js
@ -26,6 +26,7 @@ module.exports = function( grunt ) {
|
|||||||
sub: true,
|
sub: true,
|
||||||
undef: true,
|
undef: true,
|
||||||
globals: {
|
globals: {
|
||||||
|
global: true,
|
||||||
jasmine: false,
|
jasmine: false,
|
||||||
module: false,
|
module: false,
|
||||||
exports: true,
|
exports: true,
|
||||||
@ -53,21 +54,34 @@ module.exports = function( grunt ) {
|
|||||||
].join('&&')
|
].join('&&')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
concat: {
|
template: {
|
||||||
options: {
|
options: {
|
||||||
process: true
|
data: function() {
|
||||||
},
|
return {
|
||||||
mockAjax: {
|
packageVersion: packageVersion(),
|
||||||
src: [
|
files: grunt.file.expand([
|
||||||
'src/requireAjax.js',
|
'src/requireAjax.js',
|
||||||
'src/**/*.js',
|
'src/**/*.js',
|
||||||
'!src/boot.js',
|
'!src/boot.js'
|
||||||
'src/boot.js'
|
])
|
||||||
],
|
};
|
||||||
dest: 'lib/mock-ajax.js'
|
}
|
||||||
}
|
},
|
||||||
|
lib: {
|
||||||
|
src: 'src/boot.js',
|
||||||
|
dest: '.tmp/mock-ajax.js'
|
||||||
|
}
|
||||||
},
|
},
|
||||||
packageVersion: packageVersion()
|
includes: {
|
||||||
|
options: {
|
||||||
|
includeRegexp: /\/\/\s*include "(\S+)";/,
|
||||||
|
includePath: '.'
|
||||||
|
},
|
||||||
|
lib: {
|
||||||
|
src: '.tmp/mock-ajax.js',
|
||||||
|
dest: 'lib/mock-ajax.js'
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
grunt.registerTask('versionCheck', function() {
|
grunt.registerTask('versionCheck', function() {
|
||||||
@ -81,10 +95,12 @@ module.exports = function( grunt ) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
grunt.loadNpmTasks('grunt-contrib-jshint');
|
grunt.loadNpmTasks('grunt-contrib-jshint');
|
||||||
grunt.loadNpmTasks('grunt-contrib-concat');
|
grunt.loadNpmTasks('grunt-template');
|
||||||
|
grunt.loadNpmTasks('grunt-includes');
|
||||||
grunt.loadNpmTasks('grunt-shell');
|
grunt.loadNpmTasks('grunt-shell');
|
||||||
|
|
||||||
grunt.registerTask('default', ['jshint']);
|
grunt.registerTask('default', ['jshint']);
|
||||||
|
grunt.registerTask('build', ['template:lib', 'includes:lib']);
|
||||||
grunt.registerTask('ctags', 'Generate ctags', ['shell:ctags']);
|
grunt.registerTask('ctags', 'Generate ctags', ['shell:ctags']);
|
||||||
grunt.registerTask('release', 'Release ' + packageVersion() + ' to npm', ['versionCheck', 'shell:release']);
|
grunt.registerTask('release', 'Release ' + packageVersion() + ' to npm', ['versionCheck', 'shell:release']);
|
||||||
};
|
};
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
"version": "3.2.0",
|
"version": "3.2.0",
|
||||||
"main": "lib/mock-ajax.js",
|
"main": "lib/mock-ajax.js",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|
||||||
"url": "https://github.com/jasmine/jasmine-ajax",
|
"url": "https://github.com/jasmine/jasmine-ajax",
|
||||||
"contributors": [
|
"contributors": [
|
||||||
"Gregg Van Hove <gregg@slackersoft.net>",
|
"Gregg Van Hove <gregg@slackersoft.net>",
|
||||||
@ -17,10 +16,11 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {},
|
"dependencies": {},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"grunt": "0.4.0",
|
"grunt": "~0.4.0",
|
||||||
"grunt-cli": "~0.1.13",
|
"grunt-cli": "~0.1.13",
|
||||||
"grunt-contrib-concat": "~0.5.0",
|
|
||||||
"grunt-contrib-jshint": "~0.1.1",
|
"grunt-contrib-jshint": "~0.1.1",
|
||||||
"grunt-shell": "~0.2.1"
|
"grunt-includes": "^0.5.1",
|
||||||
|
"grunt-shell": "~0.2.1",
|
||||||
|
"grunt-template": "^0.2.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
66
src/boot.js
66
src/boot.js
@ -1,11 +1,55 @@
|
|||||||
(function() {
|
/*
|
||||||
var jRequire = getJasmineRequireObj(),
|
|
||||||
MockAjax = jRequire.ajax(jRequire);
|
Jasmine-Ajax - v<%= packageVersion %>: a set of helpers for testing AJAX requests under the Jasmine
|
||||||
if (typeof window === "undefined" && typeof exports === "object") {
|
BDD framework for JavaScript.
|
||||||
exports.MockAjax = MockAjax;
|
|
||||||
jasmine.Ajax = new MockAjax(exports);
|
http://github.com/jasmine/jasmine-ajax
|
||||||
} else {
|
|
||||||
window.MockAjax = MockAjax;
|
Jasmine Home page: http://jasmine.github.io/
|
||||||
jasmine.Ajax = new MockAjax(window);
|
|
||||||
}
|
Copyright (c) 2008-2015 Pivotal Labs
|
||||||
}());
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Module wrapper to support both browser and CommonJS environment
|
||||||
|
(function (root, factory) {
|
||||||
|
if (typeof exports === 'object' && typeof exports.nodeName !== 'string') {
|
||||||
|
// CommonJS
|
||||||
|
var jasmineRequire = require('jasmine-core');
|
||||||
|
module.exports = factory(root, function() {
|
||||||
|
return jasmineRequire;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Browser globals
|
||||||
|
window.MockAjax = factory(root, getJasmineRequireObj);
|
||||||
|
}
|
||||||
|
}(typeof window !== 'undefined' ? window : global, function (global, getJasmineRequireObj) {
|
||||||
|
|
||||||
|
// <% files.forEach(function(filename) { %>
|
||||||
|
// include "<%= filename %>";<% }); %>
|
||||||
|
|
||||||
|
var jRequire = getJasmineRequireObj();
|
||||||
|
var MockAjax = jRequire.ajax(jRequire);
|
||||||
|
jasmine.Ajax = new MockAjax(global);
|
||||||
|
|
||||||
|
return MockAjax;
|
||||||
|
}));
|
||||||
|
@ -1,35 +1,3 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
Jasmine-Ajax - v<%= packageVersion %>: a set of helpers for testing AJAX requests under the Jasmine
|
|
||||||
BDD framework for JavaScript.
|
|
||||||
|
|
||||||
http://github.com/jasmine/jasmine-ajax
|
|
||||||
|
|
||||||
Jasmine Home page: http://jasmine.github.io/
|
|
||||||
|
|
||||||
Copyright (c) 2008-2015 Pivotal Labs
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
getJasmineRequireObj().ajax = function(jRequire) {
|
getJasmineRequireObj().ajax = function(jRequire) {
|
||||||
var $ajax = {};
|
var $ajax = {};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user