• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript proxyquire.default函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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 }
}
开发者ID:blockstack,项目名称:blockstack-registrar,代码行数:56,代码来源:mockTestDrivers.ts


示例2: mockXMLParse

function mockXMLParse(func) {
  return prequire("../../src/Node/GomlLoader", {
    "../Base/XMLReader": {
      default: {
        parseXML: (srcHtml) => {
          func(srcHtml);
          return XMLReader.parseXML(srcHtml);
        }
      }
    }
  }).default;
}
开发者ID:emadurandal,项目名称:GrimoireJS,代码行数:12,代码来源:GomlLoaderTest.ts


示例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 }
}
开发者ID:blockstack,项目名称:blockstack-registrar,代码行数:82,代码来源:mockTestDrivers.ts


示例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 }
}
开发者ID:blockstack,项目名称:blockstack-registrar,代码行数:67,代码来源:mockTestDrivers.ts


示例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'});
});
开发者ID:sindresorhus,项目名称:got,代码行数:18,代码来源:error.ts


示例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)
  })
开发者ID:oleksii-honchar,项目名称:ts-es6-node-mocha-playground,代码行数:22,代码来源:is-works.spec.ts


示例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 };
开发者ID:9590,项目名称:ng2-redux,代码行数:31,代码来源:get-in.immutable.spec.ts



注:本文中的proxyquire.default函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript proxyquire.load函数代码示例发布时间:2022-05-25
下一篇:
TypeScript proxy-middleware.default函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap