Skip to content

File and FileTransfer mocks not working as expected #28

@etichenor

Description

@etichenor

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions