diff --git a/.gitignore b/.gitignore index 7fd5ccb..8e6baf7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ bower_components .env *~ dist/filer-test.js +dist/filer-issue225.js diff --git a/gruntfile.js b/gruntfile.js index 4f16804..a57b683 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -15,7 +15,7 @@ module.exports = function(grunt) { grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), - clean: ['dist/filer-test.js', 'dist/filer_node-test.js'], + clean: ['dist/filer-test.js', 'dist/filer-issue225.js'], uglify: { options: { @@ -68,12 +68,27 @@ module.exports = function(grunt) { filerTest: { src: "./tests/index.js", dest: "./dist/filer-test.js" + }, + // See tests/bugs/issue225.js + filerIssue225: { + src: "./src/index.js", + dest: "./dist/filer-issue225.js", + options: { + browserifyOptions: { + commondir: false + }, + bundleOptions: { + standalone: 'Filer' + } + } } }, shell: { mocha: { - command: './node_modules/.bin/mocha --reporter list tests/index.js' + // Run all tests (e.g., tests require()'ed in tests/index.js) and also tests/bugs/issue225.js + // separately, since it can't be included in a browserify build. + command: './node_modules/.bin/mocha --reporter list tests/index.js tests/bugs/issue225.js' } }, @@ -208,9 +223,9 @@ module.exports = function(grunt) { 'npm-publish' ]); }); - grunt.registerTask('test-node', ['jshint', 'connect:serverForNode', 'shell:mocha']); + grunt.registerTask('test-node', ['jshint', 'browserify:filerIssue225', 'connect:serverForNode', 'shell:mocha']); grunt.registerTask('test-browser', ['jshint', 'build-tests', 'connect:serverForBrowser']); - grunt.registerTask('test', ['test-node']); + grunt.registerTask('test', ['clean', 'test-node']); grunt.registerTask('default', ['test']); }; diff --git a/package.json b/package.json index b518b75..64db0cc 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,8 @@ "grunt-shell": "~0.7.0", "habitat": "^1.1.0", "mocha": "~1.18.2", - "semver": "^2.3.0" + "semver": "^2.3.0", + "requirejs": "^2.1.14" }, "main": "./src/index.js" } diff --git a/tests/bugs/issue225.js b/tests/bugs/issue225.js new file mode 100644 index 0000000..15a0803 --- /dev/null +++ b/tests/bugs/issue225.js @@ -0,0 +1,41 @@ +/** + * NOTE: this test has to be run outside the browserify step, + * since combinining require for node.js/browserify builds with + * r.js doesn't work. + */ + +var requirejs = require('requirejs'); +var expect = require('chai').expect; + +GLOBAL.XMLHttpRequest = {}; + +describe('require.js should be able to use built Filer, issue 225', function() { + + it('should properly load Filer as an AMD module, with Buffer included', function(done) { + requirejs.config({ + baseUrl: __dirname, + paths: { + "filer": "../../dist/filer-issue225" + }, + nodeRequire: require + }); + + requirejs(["filer"], function(Filer) { + expect(Filer).to.exist; + expect(Filer.Buffer).to.exist; + + var fs = new Filer.FileSystem({provider: new Filer.FileSystem.providers.Memory()}); + + var buf = new Filer.Buffer([1, 2, 3]); + fs.writeFile('/file', buf, function(err) { + expect(err).not.to.exist; + + fs.readFile('/file', function(err, data) { + expect(err).not.to.exist; + expect(data).to.deep.equal(buf); + done(); + }); + }); + }); + }); +}); diff --git a/tests/index.js b/tests/index.js index 5bf4b58..1a59c8c 100644 --- a/tests/index.js +++ b/tests/index.js @@ -62,6 +62,7 @@ require("./spec/node-js/simple/test-fs-null-bytes"); require("./spec/node-js/simple/test-fs-watch"); require("./spec/node-js/simple/test-fs-watch-recursive"); -// Regressions; Bugs +// Regressions, Bugs +// NOTE: bugs/issue225.js has to be run outside this step, see gruntfile.js require("./bugs/issue105"); require("./bugs/issue106");