當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。