Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File and FileTransfer mocks not working as expected #28

Open
etichenor opened this issue Jan 17, 2019 · 3 comments
Open

File and FileTransfer mocks not working as expected #28

etichenor opened this issue Jan 17, 2019 · 3 comments

Comments

@etichenor
Copy link

Chris,
Thanks for these mocks. I'm hoping I can get them functioning. We're on a really tight timeline.

I've implemented the mocks via npm and I just added some logic that uses File and FileTranfer plugins.
NOTE: This app should also be able to run in the browser when it goes public. Am I missing something there? We have another Cordova app that uses plugins and I don't see these issues in the browser. i.e. also using the File and FileTransfer plugins.

The problem I'm facing is that I still receive warnings in the chrome console after implementing the mocks:
Ionic Native: tried calling File.dataDirectory, but Cordova is not available. Make sure to a) run in a real device or simulator and b) include cordova.js in your index.html.
AND
Native: tried accessing the FileTransfer plugin but Cordova is not available. Make sure to a) run in a real device or simulator and b) include cordova.js in your index.html

Here is my app.module.ts:
import { File } from '@ionic-native/file';
import { FileMock } from '@ionic-native-mocks/file';
import { FileTransfer } from '@ionic-native/file-transfer';
import { FileTransferMock } from '@ionic-native-mocks/file-transfer';
...

providers: [
...
//// USE MOCK FOR CORDOVA PROVIDERS IF IN BROWSER
//File,
//FileTransfer,
(isBrowser ? { provide: File, useClass: FileMock } : File),
(isBrowser ? { provide: FileTransfer, useClass: FileTransferMock } : FileTransfer),
...

Next, I wrote my own provider (wrapper) for file related functions file-utils.ts:
...
import { File } from '@ionic-native/file'; << Seemed unusual that this doesn't import the MOCK?!
import { FileTransfer } from '@ionic-native/file-transfer'; << Seemed unusual that this doesn't import the MOCK?!
...
constructor(public http: HttpClient, public platform: Platform, public storage: Storage, public globals: Globals, public file: File, public transfer: FileTransfer, public zip: Zip) {
console.log('Construct FileUtils Provider');
//Determine device storage folder per OS
//if (this.platform.is('android'))
// globals.deviceStorageFolder = this.file.dataDirectory;
//else globals.deviceStorageFolder = this.file.documentsDirectory;
globals.deviceStorageFolder = this.file.dataDirectory;
console.log('Got File.dataDirectory = ' + globals.deviceStorageFolder);
}
...
So the question is, is the npm implementation enough in my case, or do I need to customize the file.dataDirectory? What would I return? Would be something like C:\Temp?
What about FileTransfer which is not available at all even with the mocks in place?

@chrisgriffith
Copy link
Owner

I will take a look. I assume you are coding against Ionic v3 and not Ionic v4 (working on the update to the mocks).

@etichenor
Copy link
Author

Ionic v4 actually.
In the meantime, I've resorted to: ionic cordova run browser
But of course, I no longer benefit from livereload and debugging features of VS Code

@chrisgriffith
Copy link
Owner

I think it might be a v4 issue actually. Ionic Native changed some, (ie the ngx), so I think they are broken at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants