本文整理汇总了TypeScript中proxyquire.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: makeMockedGcDriver
export function makeMockedGcDriver() {
let config = {
"bucket": "spokes"
}
const dataMap: DataMap = []
let myName = ''
const file = function (filename) {
const createWriteStream = function() {
return new MockWriteStream(dataMap, filename)
}
return {
createWriteStream,
delete: () => {
return Promise.resolve().then(() => {
const newDataMap = dataMap.filter((d) => d.key !== filename)
if (newDataMap.length === dataMap.length) {
const err: any = new Error()
err.code = 404
throw err
}
dataMap.length = 0
dataMap.push(...newDataMap)
})
}
}
}
const exists = function () {
return Promise.resolve([true])
}
const StorageClass = class {
bucket(bucketName) {
if (myName === '') {
myName = bucketName
} else {
if (myName !== bucketName) {
throw new Error(`Unexpected bucket name: ${bucketName}. Expected ${myName}`)
}
}
return { file, exists, getFiles: this.getFiles }
}
getFiles(options, cb) {
const files = dataMap
.filter(entry => entry.key.startsWith(options.prefix))
.map(entry => { return { name: entry.key } })
cb(null, files, null)
}
}
const driverClass = proxyquire('../../../src/server/drivers/GcDriver', {
'@google-cloud/storage': { Storage: StorageClass }
}).default
return { driverClass, dataMap, config }
}
示例2: mockXMLParse
function mockXMLParse(func) {
return prequire("../../src/Node/GomlLoader", {
"../Base/XMLReader": {
default: {
parseXML: (srcHtml) => {
func(srcHtml);
return XMLReader.parseXML(srcHtml);
}
}
}
}).default;
}
示例3: makeMockedS3Driver
export function makeMockedS3Driver() {
let config : any = {
"bucket": "spokes"
}
const dataMap: DataMap = []
let bucketName = ''
const S3Class = class {
headBucket(options) {
bucketName = options.Bucket
return { promise: () => Promise.resolve() }
}
upload(options) {
return {
promise: async () => {
if (options.Bucket != bucketName) {
throw new Error(`Unexpected bucket name: ${options.Bucket}. Expected ${bucketName}`)
}
const buffer = await readStream(options.Body)
dataMap.push({ data: buffer.toString(), key: options.Key })
}
}
}
headObject(options) {
return {
promise: () => {
return Promise.resolve().then(() => {
if (!dataMap.find((d) => d.key === options.Key)) {
const err: any = new Error()
err.statusCode = 404
throw err
}
})
}
}
}
deleteObject(options) {
return {
promise: () => {
return Promise.resolve().then(() => {
const newDataMap = dataMap.filter((d) => d.key !== options.Key)
dataMap.length = 0
dataMap.push(...newDataMap)
})
}
}
}
listObjectsV2(options) {
return {
promise: async () => {
const contents = dataMap
.filter((entry) => {
return (entry.key.slice(0, options.Prefix.length) === options.Prefix)
})
.map((entry) => {
return { Key: entry.key }
})
return { Contents: contents, IsTruncated: false }
}
}
}
listObjects(options) {
return {
promise: async () => {
const contents = dataMap
.filter((entry) => {
return (entry.key.slice(0, options.Prefix.length) === options.Prefix)
})
.map((entry) => {
return { Key: entry.key }
})
return { Contents: contents, IsTruncated: false }
}
}
}
}
const driverClass = proxyquire('../../../src/server/drivers/S3Driver', {
'aws-sdk/clients/s3': S3Class
}).default
return { driverClass, dataMap, config }
}
示例4: makeMockedAzureDriver
export function makeMockedAzureDriver() {
let config = {
"azCredentials": {
"accountName": "mock-azure",
"accountKey": "mock-azure-key"
},
"bucket": "spokes"
}
const dataMap: DataMap = []
const uploadStreamToBlockBlob = async (aborter, stream, blockBlobURL, bufferSize, maxBuffers, options) => {
const buffer = await readStream(stream)
dataMap.push({data: buffer.toString(), key: blockBlobURL.blobName })
}
const listBlobFlatSegment = (_, __, { prefix }) => {
const items = dataMap
.map(x => x.key)
.filter(key => key.startsWith(prefix))
.map(key => { return {
name: key
}})
return { segment: { blobItems: items } }
}
const ContainerURL = {
fromServiceURL: () => {
return {
create: () => null,
listBlobFlatSegment: listBlobFlatSegment,
}
}
}
const fromBlobURL = (blobName: string) => {
return {
blobName,
delete: () => {
return Promise.resolve().then(() => {
const newDataMap = dataMap.filter((d) => d.key !== blobName)
if (newDataMap.length === dataMap.length) {
const err: any = new Error()
err.statusCode = 404
throw err
}
dataMap.length = 0
dataMap.push(...newDataMap)
})
}
}
}
const driverClass = proxyquire('../../../src/server/drivers/AzDriver', {
'@azure/storage-blob': {
SharedKeyCredential: class { },
ContainerURL: ContainerURL,
StorageURL: { newPipeline: () => null },
ServiceURL: class { },
BlobURL: { fromContainerURL: (_, blobName) => blobName },
BlockBlobURL: { fromBlobURL: fromBlobURL },
Aborter: { none: null },
uploadStreamToBlockBlob: uploadStreamToBlockBlob
}
}).default
return { driverClass, dataMap, config }
}
示例5: Error
test('catches error in mimicResponse', withServer, async (t, server) => {
server.get('/', (_request, response) => {
response.end('ok');
});
const mimicResponse = () => {
throw new Error('Error in mimic-response');
};
mimicResponse['@global'] = true;
const proxiedGot = proxyquire('../source', {
'mimic-response': mimicResponse
});
// @ts-ignore
await t.throwsAsync(proxiedGot(server.url), {message: 'Error in mimic-response'});
});
示例6: proxyquire
it.only('mocks class', () => {
const ToolStub = sinon.spy(() => {
return {
test: () => {
console.log('ToolStub.test() fake call')
}
}
})
const mdl2 = proxyquire(path.join(
process.cwd(), '/src/main',
'helpers/main.helper'
),
{
'classes/index': { Tool: ToolStub }
}
)
mdl2.mainHelper.help()
expect(ToolStub.calledOnce).to.eq(true)
})
示例7: require
const proxyquire = require('proxyquire');
const { getIn: getInWithImmutable } = proxyquire('../../utils/get-in', {
immutable: {
Iterable: {
isIterable: value => typeof value.getIn === 'function',
},
'@noCallThru': true,
},
});
const { getIn: getInWithNoImmutable } = require('../../utils/get-in');
import { expect } from 'chai';
describe('getIn', () => {
it('should make use of immutable when available in host project', () => {
const getIn =
path => {
expect(path.length).to.equal(1);
expect(path[0]).to.equal('foo');
return 't';
};
const fakeImmutable = { getIn: getIn };
expect(getInWithImmutable(fakeImmutable, [ 'foo' ])).to.equal('t');
});
it('should work on regular objects even when immutable is available', () => {
const test = { foo: 1 };