It looks like there's an inconsistency in the File API in PhantomJS. Using the type File is not possible because PhantomJS reports it as an object, not a function.
On Chrome, Firefox and Safari:
>> typeof File
"function"
>> new File(['content'], 'name.txt');
File { name: "name.txt", lastModified: 1461986360442, lastModifiedDate: Date 2016-04-30T03:19:20.442Z, size: 7, type: "" }
On PhantomJS:
phantomjs> typeof File
"object"
phantomjs> new File(['content'], 'name.txt');
'new File(['content'], 'name.txt');' is a cyclic structure
phantomjs://repl-input:1 in global code
Is this a bug? Or am I doing something wrong?
phantomjs --version.% phantomjs --version
2.1.1
% uname -a
Darwin host 15.4.0 Darwin Kernel Version 15.4.0: Fri Feb 26 22:08:05 PST 2016; root:xnu-3248.40.184~3/RELEASE_X86_64 x86_64
Binay compiled by homebrew people (i.e. brew install phantomjs).
Our REPL is pretty dumb :-) Try to reproduce it via a script file.
Hi @Vitallium, the original failure came from a script file, I used the REPL to build the report.
I have test code that calls new File, and here's how it fails:
1) PipelineUploader should set the progress callback:
TypeError: '[object FileConstructor]' is not a constructor (evaluating 'new File(['this is definitely not a video'], 'input-file.txt', 'text/plan')')
This is the code for the test (using mocha):
(function() {
'use strict';
describe('PipelineUploader', function() {
it('should set the progress callback', function() {
var file = new File(['this is definitely not a video'], 'input-file.txt', 'text/plan');
var called = false;
uploader.upload(file, {
progressCallback: function(event, xhr) {
called = true;
}
});
should.exist(requests[0]);
requests[0].uploadProgress({loaded: false});
expect(called).to.equal(true);
});
});
})();
I've faced the same issue. It seems like the File constructor isn't supported.
@fsouza The workaround I've used is to create a blob first, then convert it into a file. There's more info on this in this stackoverflow thread.
Bump, this is still happening. Would be nice to have an actual solution instead of having to rely on that hackey fix of using a blob
Still a problem in 2.1.1 indeed.
I also encountered this problem, running phantomjs 2.1.1 with karma-mocha testings
It also occurs on Windows 7:
#phantomjs --version
2.1.1
with karma.
As mentioned by @kyleholzinger you need a Blob for your test setup, for instance:
let setupFile = (): File => {
let f: Blob = new Blob(["The content of your file"]);
f['name'] = '/home/user/file';
return <File> f;
}
Any news on that? Any polyfill we could use to handle File API under phantomJS?
Encountered the same issue while testing with PhantomJS (v2.1.1).
This is quite annoying.
Is there any other solution than waiting for bug fix? Some workaround? It's a problem in CI process... My error msg: TypeError: FileConstructor is not a constructor (evaluating 'new File(["s"], "tmp_1.txt")')
Due to our very limited maintenance capacity, we need to prioritize our development focus on other tasks. Therefore, this issue will be automatically closed (see #15395 for more details). In the future, if we see the need to attend to this issue again, then it will be reopened. Thank you for your contribution!
any update on this? CI process is also breaking coz phantomjs is not supporting the file constructor.
Most helpful comment
Still a problem in 2.1.1 indeed.