Test for Filer as AMD module use in require.js with Buffer, regression issue 225
This commit is contained in:
parent
acd806c7b8
commit
5c9ba07706
|
@ -3,3 +3,4 @@ bower_components
|
|||
.env
|
||||
*~
|
||||
dist/filer-test.js
|
||||
dist/filer-issue225.js
|
||||
|
|
23
gruntfile.js
23
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']);
|
||||
};
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue