From 3a8e4b9d66716c3c99f88a723f609bad3fd2ac03 Mon Sep 17 00:00:00 2001 From: shuzhouhao Date: Thu, 30 Dec 2021 16:30:47 +0800 Subject: [PATCH 1/2] add statfs js api mock --- .../main/extend/systemplugin/napi/index.js | 3 ++ .../main/extend/systemplugin/napi/statfs.js | 31 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 runtime/main/extend/systemplugin/napi/statfs.js diff --git a/runtime/main/extend/systemplugin/napi/index.js b/runtime/main/extend/systemplugin/napi/index.js index 2b312cb2..ad16e98c 100644 --- a/runtime/main/extend/systemplugin/napi/index.js +++ b/runtime/main/extend/systemplugin/napi/index.js @@ -37,6 +37,7 @@ import { mockBundle } from './bundle' import { mockInnerBundle } from './innerBundleManager' import { mockUri } from './uri' import { mockXml } from './xml' +import { mockStatfs } from './statfs' export function mockRequireNapiFun() { global.requireNapi = function (...args) { @@ -119,6 +120,8 @@ export function mockRequireNapiFun() { return mockUri(); case "xml": return mockXml(); + case "statfs": + return mockStatfs(); default: return global.requireNapiPreview(...args); } diff --git a/runtime/main/extend/systemplugin/napi/statfs.js b/runtime/main/extend/systemplugin/napi/statfs.js new file mode 100644 index 00000000..11eb4cfd --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/statfs.js @@ -0,0 +1,31 @@ +import { paramMock } from "../utils" + +export function mockStatfs() { + const statfs = { + getFreeBytes: function (...args) { + console.warn("statfs.getFreeBytes interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + getTotalBytes: function (...args) { + console.warn("statfs.getTotalBytes interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + } + return statfs; +} -- Gitee From 617e8fea78b0f2e194d63755a6a8f520aa53c501 Mon Sep 17 00:00:00 2001 From: shuzhouhao Date: Thu, 30 Dec 2021 16:30:47 +0800 Subject: [PATCH 2/2] add statfs js api mock Signed-off-by: shuzhouhao --- .../main/extend/systemplugin/napi/index.js | 3 ++ .../main/extend/systemplugin/napi/statfs.js | 31 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 runtime/main/extend/systemplugin/napi/statfs.js diff --git a/runtime/main/extend/systemplugin/napi/index.js b/runtime/main/extend/systemplugin/napi/index.js index 2b312cb2..ad16e98c 100644 --- a/runtime/main/extend/systemplugin/napi/index.js +++ b/runtime/main/extend/systemplugin/napi/index.js @@ -37,6 +37,7 @@ import { mockBundle } from './bundle' import { mockInnerBundle } from './innerBundleManager' import { mockUri } from './uri' import { mockXml } from './xml' +import { mockStatfs } from './statfs' export function mockRequireNapiFun() { global.requireNapi = function (...args) { @@ -119,6 +120,8 @@ export function mockRequireNapiFun() { return mockUri(); case "xml": return mockXml(); + case "statfs": + return mockStatfs(); default: return global.requireNapiPreview(...args); } diff --git a/runtime/main/extend/systemplugin/napi/statfs.js b/runtime/main/extend/systemplugin/napi/statfs.js new file mode 100644 index 00000000..11eb4cfd --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/statfs.js @@ -0,0 +1,31 @@ +import { paramMock } from "../utils" + +export function mockStatfs() { + const statfs = { + getFreeBytes: function (...args) { + console.warn("statfs.getFreeBytes interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + getTotalBytes: function (...args) { + console.warn("statfs.getTotalBytes interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + } + return statfs; +} -- Gitee