本文整理汇总了TypeScript中proxyquire.default方法的典型用法代码示例。如果您正苦于以下问题:TypeScript proxyquire.default方法的具体用法?TypeScript proxyquire.default怎么用?TypeScript proxyquire.default使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类proxyquire
的用法示例。
在下文中一共展示了proxyquire.default方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('should by default error when workingDirectory is a root directory with a package.json', done => {
const debug = new Debug({}, packageInfo);
/*
* `path.sep` represents a root directory on both Windows and Unix.
* On Windows, `path.sep` resolves to the current drive.
*
* That is, after opening a command prompt in Windows, relative to the
* drive C: and starting the Node REPL, the value of `path.sep`
* represents `C:\\'.
*
* If `D:` is entered at the prompt to switch to the D: drive before
* starting the Node REPL, `path.sep` represents `D:\\`.
*/
const root = path.sep;
const mockedDebuglet = proxyquire('../src/agent/debuglet', {
/*
* Mock the 'fs' module to verify that if the root directory is used,
* and the root directory is reported to contain a `package.json`
* file, then the agent still produces an `initError` when the
* working directory is the root directory.
*/
fs: {
stat: (
filepath: string | Buffer,
cb: (err: Error | null, stats: {}) => void
) => {
if (filepath === path.join(root, 'package.json')) {
// The key point is that looking for `package.json` in the
// root directory does not cause an error.
return cb(null, {});
}
fs.stat(filepath, cb);
},
},
});
const config = extend({}, defaultConfig, {workingDirectory: root});
const debuglet = new mockedDebuglet.Debuglet(debug, config);
let text = '';
debuglet.logger.error = (str: string) => {
text += str;
};
debuglet.on('initError', (err: Error) => {
const errorMessage =
'The working directory is a root ' +
'directory. Disabling to avoid a scan of the entire filesystem ' +
'for JavaScript files. Use config `allowRootAsWorkingDirectory` ' +
'if you really want to do this.';
assert.ok(err);
assert.strictEqual(err.message, errorMessage);
assert.ok(text.includes(errorMessage));
done();
});
debuglet.once('started', () => {
assert.fail('Should not start if workingDirectory is a root directory');
});
debuglet.start();
});
示例2: beforeEach
beforeEach(() => {
serverStub = sinon.stub({
get: () => this,
registerServiceClass: (target: any) => this,
registerServiceMethod: (target: any, propertyKey: string) => this
});
propertyType = sinon.stub();
reflectGetMetadata = sinon.stub(Reflect, 'getMetadata');
reflectGetOwnMetadata = sinon.stub(Reflect, 'getOwnMetadata');
serviceDecorators = proxyquire('../../src/decorators/services', {
'../server/server-container': { ServerContainer: serverStub }
});
parameterDecorators = proxyquire('../../src/decorators/parameters', {
'../server/server-container': { ServerContainer: serverStub }
});
methodDecorators = proxyquire('../../src/decorators/methods', {
'../server/server-container': { ServerContainer: serverStub }
});
serviceClass = new ServiceClass(TestService);
serviceMethod = new ServiceMethod();
serverStub.registerServiceMethod.returns(serviceMethod);
serverStub.registerServiceClass.returns(serviceClass);
serverStub.get.returns(serverStub);
reflectGetMetadata.returns(propertyType);
reflectGetOwnMetadata.returns(propertyType);
});
示例3: beforeEach
beforeEach(() => {
consoleLogSpy.reset();
consoleWarnSpy.reset();
const logger = proxyquire("./logger", { "./config": { config: { logging: false } } }).logger;
logger.info("this will be ignored");
logger.warn("this will be ignored at warn");
});
示例4: before
before(function () {
proxyq.noCallThru();
CompositionRootService = proxyq(
'../../src/services/compositionRootService',
{ vscode },
).CompositionRootService;
});
示例5: it
it("check main flow", () => {
const AppProxy = Proxyquire("../app", {
express: Sinon.stub().returns(express),
});
const application = new AppProxy.Application();
const stubInitSessionManagement = Sinon.stub(application, "initSessionManagement");
const stubInitPassport = Sinon.stub(application, "initPassport");
const stubInitSessionFiltering = Sinon.stub(application, "initSessionFiltering");
const stubInitRestEndpoints = Sinon.stub(application, "initRestEndpoints");
const stubInitStaticContent = Sinon.stub(application, "initStaticContent");
const stubStartServer = Sinon.stub(application, "startServer");
application.initExpress();
stubInitSessionManagement.restore();
stubInitPassport.restore();
stubInitSessionFiltering.restore();
stubInitRestEndpoints.restore();
stubInitStaticContent.restore();
stubStartServer.restore();
Sinon.assert.callOrder(
stubInitSessionManagement.withArgs(express),
stubInitPassport.withArgs(express),
stubInitSessionFiltering.withArgs(express),
stubInitRestEndpoints.withArgs(express),
stubInitStaticContent.withArgs(express),
stubStartServer.withArgs(express),
);
});
示例6: before
before(() => {
GrpcOperation =
proxyquire('../src/operation', {
'./service-object': {GrpcServiceObject: FakeGrpcServiceObject},
'./service': {GrpcService: FakeGrpcService}
}).GrpcOperation;
});
示例7: proxyquire
o.test('should return only directories', t => {
let directories = ['dir1', 'another-dir', 'test'];
t.plan(directories.length);
let files = ['test.jpg', 'another-test.docx'];
let nodeFsStub = {
readdirSync: (path: string) => directories.concat(files),
statSync: (path: string) => {
return {
isDirectory: () => {
return directories.indexOf(path) !== -1;
}
};
}
};
let FileSystem = proxyquire('tidyfolders/src/file-system', {'fs': nodeFsStub}).FileSystem;
let fileSystem = new FileSystem(moveDirStub);
let returnedDirectories: Array<DirectoryModel> = fileSystem.getAllDirectories('');
let returnedDirectoriesNames = returnedDirectories.map(d => d.getName());
for (let i = 0; i < directories.length; i++) {
t.equal(returnedDirectoriesNames[i], directories[i]);
}
});
示例8: beforeEach
beforeEach(() => {
authenticator = sinon.stub();
initializer = sinon.stub();
sessionHandler = sinon.stub();
expressStub = sinon.stub({
use: (...handlers: Array<RequestHandler>) => this
});
passportStub = sinon.stub({
authenticate: (strategy: string | Array<string>, options: AuthenticateOptions,
callback?: (...args: Array<any>) => any) => true,
deserializeUser: (user: string, done: (a: any, b: any) => void) => this,
initialize: () => this,
serializeUser: (user: any, done: (a: any, b: string) => void) => this,
session: () => this,
use: (name: string, strategy: Strategy) => this
});
passportStub.authenticate.returns(authenticator);
passportStub.initialize.returns(initializer);
passportStub.session.returns(sessionHandler);
PassportAuthenticator = proxyquire('../../src/authenticator/passport', {
'passport': passportStub
}).PassportAuthenticator;
});
示例9: i18n
function i18n(lang) {
return proxyquire('./i18n', {
'os-locale': {
sync: () => lang,
},
});
}