From 5c9ba0770674ecacfb657b1b19bdefa8698b9a20 Mon Sep 17 00:00:00 2001 From: "David Humphrey (:humph) david.humphrey@senecacollege.ca" Date: Wed, 11 Jun 2014 10:54:43 -0400 Subject: [PATCH 1/3] Test for Filer as AMD module use in require.js with Buffer, regression issue 225 --- .gitignore | 1 + gruntfile.js | 23 +++++++++++++++++++---- package.json | 3 ++- tests/bugs/issue225.js | 41 +++++++++++++++++++++++++++++++++++++++++ tests/index.js | 3 ++- 5 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 tests/bugs/issue225.js 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"); From a38a32d5fb0ea01080fd4b5b11f07b22c93b1361 Mon Sep 17 00:00:00 2001 From: "David Humphrey (:humph) david.humphrey@senecacollege.ca" Date: Wed, 11 Jun 2014 11:34:10 -0400 Subject: [PATCH 2/3] Make browser-request happy and provide a global shim for XHR in issue225 test --- gruntfile.js | 2 +- tests/bugs/issue225.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/gruntfile.js b/gruntfile.js index a57b683..316e21b 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -88,7 +88,7 @@ module.exports = function(grunt) { mocha: { // 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' + command: './node_modules/.bin/mocha --reporter list tests/index.js && ./node_modules/.bin/mocha --reporter list tests/bugs/issue225.js' } }, diff --git a/tests/bugs/issue225.js b/tests/bugs/issue225.js index 15a0803..f595c97 100644 --- a/tests/bugs/issue225.js +++ b/tests/bugs/issue225.js @@ -7,6 +7,7 @@ var requirejs = require('requirejs'); var expect = require('chai').expect; +// browser-request assumes access to XHR GLOBAL.XMLHttpRequest = {}; describe('require.js should be able to use built Filer, issue 225', function() { From fdfd643d439dc35f8785ae80ca9e845d11f0277e Mon Sep 17 00:00:00 2001 From: "David Humphrey (:humph) david.humphrey@senecacollege.ca" Date: Wed, 11 Jun 2014 11:39:45 -0400 Subject: [PATCH 3/3] Add link to issue --- tests/bugs/issue225.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/bugs/issue225.js b/tests/bugs/issue225.js index f595c97..1bf1d09 100644 --- a/tests/bugs/issue225.js +++ b/tests/bugs/issue225.js @@ -1,4 +1,6 @@ /** + * https://github.com/js-platform/filer/pull/225 + * * 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.