当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript proxyquire.default函数代码示例

本文整理汇总了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;未经允许,请勿转载。