2014-03-25 15:47:08 +00:00
|
|
|
define(["Filer", "util"], function(Filer, util) {
|
|
|
|
|
|
|
|
describe('FileSystemShell.wget', function() {
|
|
|
|
beforeEach(util.setup);
|
|
|
|
afterEach(util.cleanup);
|
|
|
|
|
|
|
|
it('should be a function', function() {
|
|
|
|
var shell = util.shell();
|
|
|
|
expect(shell.wget).to.be.a('function');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should fail when url argument is absent', function(done) {
|
|
|
|
var fs = util.fs();
|
|
|
|
var shell = fs.Shell();
|
|
|
|
|
|
|
|
shell.wget(null, function(err, data) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(data).not.to.exist;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-03-26 23:34:32 +00:00
|
|
|
it('should fail when the url does not exist (404)', function(done) {
|
|
|
|
var fs = util.fs();
|
|
|
|
var shell = fs.Shell();
|
|
|
|
|
|
|
|
shell.wget("no-such-url", function(err, data) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(data).not.to.exist;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-03-25 15:47:08 +00:00
|
|
|
it('should download the contents of a file from a url to default filename', function(done) {
|
|
|
|
var fs = util.fs();
|
|
|
|
var shell = fs.Shell();
|
2014-05-21 17:07:31 +00:00
|
|
|
var url = typeof XMLHttpRequest === "undefined" ? "http://localhost:1234/tests/test-file.txt" : "/tests/test-file.txt";
|
2014-03-25 15:47:08 +00:00
|
|
|
var contents = "This is a test file used in some of the tests.\n";
|
|
|
|
|
|
|
|
shell.wget(url, function(err, path) {
|
|
|
|
if(err) throw err;
|
|
|
|
|
2014-03-28 14:56:04 +00:00
|
|
|
expect(path).to.equal('/test-file.txt');
|
2014-03-25 15:47:08 +00:00
|
|
|
|
|
|
|
fs.readFile(path, 'utf8', function(err, data) {
|
|
|
|
if(err) throw err;
|
|
|
|
|
|
|
|
expect(data).to.equal(contents);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should download the contents of a file from a url to specified filename', function(done) {
|
|
|
|
var fs = util.fs();
|
|
|
|
var shell = fs.Shell();
|
2014-05-21 17:07:31 +00:00
|
|
|
var url = typeof XMLHttpRequest === "undefined" ? "http://localhost:1234/tests/test-file.txt" : "/tests/test-file.txt";
|
2014-03-25 15:47:08 +00:00
|
|
|
var contents = "This is a test file used in some of the tests.\n";
|
|
|
|
|
|
|
|
shell.wget(url, { filename: 'test-file.txt' }, function(err, path) {
|
|
|
|
if(err) throw err;
|
|
|
|
|
|
|
|
expect(path).to.equal('/test-file.txt');
|
|
|
|
|
|
|
|
fs.readFile(path, 'utf8', function(err, data) {
|
|
|
|
if(err) throw err;
|
|
|
|
|
|
|
|
expect(data).to.equal(contents);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-05-14 17:24:24 +00:00
|
|
|
it('should download the contents of a file from a url with query string', function(done) {
|
|
|
|
var fs = util.fs();
|
|
|
|
var shell = fs.Shell();
|
2014-05-21 17:07:31 +00:00
|
|
|
var url = typeof XMLHttpRequest === "undefined" ? "http://localhost:1234/tests/test-file.txt?foo" : "/tests/test-file.txt?foo";
|
2014-05-14 17:24:24 +00:00
|
|
|
var contents = "This is a test file used in some of the tests.\n";
|
|
|
|
|
|
|
|
shell.wget(url, function(err, path) {
|
|
|
|
if(err) throw err;
|
|
|
|
|
|
|
|
expect(path).to.equal('/test-file.txt?foo');
|
|
|
|
|
|
|
|
fs.readFile(path, 'utf8', function(err, data) {
|
|
|
|
if(err) throw err;
|
|
|
|
|
|
|
|
expect(data).to.equal(contents);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-03-25 15:47:08 +00:00
|
|
|
});
|
|
|
|
});
|