Merge pull request #226 from humphd/requirejs-test

Requirejs test - Going to land this so we don't regress. @modeswitch FYI in case you want to back it out, but since you're so busy I want to press ahead, and this is pretty low risk.
This commit is contained in:
David Humphrey 2014-07-02 15:25:21 -04:00
commit f9b3b69588
5 changed files with 68 additions and 6 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ bower_components
.env
*~
dist/filer-test.js
dist/filer-issue225.js

View File

@ -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 && ./node_modules/.bin/mocha --reporter list 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']);
};

View File

@ -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"
}

44
tests/bugs/issue225.js Normal file
View File

@ -0,0 +1,44 @@
/**
* 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.
*/
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() {
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();
});
});
});
});
});

View File

@ -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");