本文整理汇总了TypeScript中mocha-typescript.suite函数的典型用法代码示例。如果您正苦于以下问题:TypeScript suite函数的具体用法?TypeScript suite怎么用?TypeScript suite使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了suite函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: suite
suite('metrics/OSMetricsService', () => {
suite('CPUStat Parsing', () => {
test('It can parse CPU stats', () => {
const instance = new OSMetricsService();
const resp = new OSMetrics();
instance.parseCPUStatFile(cpustat, resp);
resp.user.must.be.equal(7461692);
resp.nice.must.be.equal(102384);
resp.system.must.be.equal(2042556);
resp.idle.must.be.equal(15356656);
resp.iowait.must.be.equal(319915);
resp.irq.must.be.equal(0);
resp.softirq.must.be.equal(317993);
resp.steal.must.be.equal(25113);
});
test('It can parse Context switch stats', () => {
const instance = new OSMetricsService();
const resp = new OSMetrics();
instance.parseCPUStatFile(cpustat, resp);
resp.ctxtSwaps.must.be.equal(734345521);
});
});
suite('LoadAvg Parsing', () => {
test('It can parse LoadAvg stats', () => {
const instance = new OSMetricsService();
const resp = new OSMetrics();
instance.parseLoadAvgFile(loadAvg, resp);
resp.load1.must.be.equal(2.82);
resp.load5.must.be.equal(2.32);
resp.load15.must.be.equal(2.04);
});
});
});
示例2: suite
suite('ioc/autoconfig/ObjectDefinitionDecoratorInspector', () => {
suite('interestedIn', () => {
test('It\'s not interested on non-decorated classes', () => {
const definition = new BaseSingletonDefinition(Test2);
inspector.interestedIn(definition).must.be.false();
});
test('It\'s interested on decorated classes', () => {
const definition = new BaseSingletonDefinition(Test1);
inspector.interestedIn(definition).must.be.true();
});
});
suite('doInspect', () => {
test('It sets the Lazy flag appropriately', () => {
const definition = new BaseSingletonDefinition(Test1);
inspector.doInspect(definition);
definition.lazyLoading.must.be.false();
});
test('It sets autowiring properly', () => {
const definition = new BaseSingletonDefinition(Test1);
inspector.doInspect(definition);
const callDefinitions = definition.getPropertiesToSetDefinitions();
callDefinitions.length.must.equal(2);
callDefinitions[0].paramName.must.equal('prop1');
callDefinitions[0].args.length.must.equal(1);
callDefinitions[0].args[0].type.must.equal(ParamType.Reference);
callDefinitions[0].args[0].refName.must.equal('theReference');
callDefinitions[1].paramName.must.equal('prop2');
callDefinitions[1].args.length.must.equal(1);
callDefinitions[1].args[0].type.must.equal(ParamType.Config);
callDefinitions[1].args[0].key.must.equal('configKey');
});
});
});
示例3: suite
suite('log/LogManager', () => {
suite('LogManagerInternal', () => {
test('Be smart on the path properly cuts the path when dist is present', () => {
beSmartOnThePath('/some/path/with/dist/in/it/File.js').must.equal('in/it/File.js');
});
});
});
示例4: suite
suite('util/TestUtil', () => {
suite('Call capture', () => {
test('one', () => {
const mock = MockUtil.mock<Context>(Context);
MockUtil.when(mock.getDefinitionByName).isCalledWith('A').thenReturn('A is the result');
mock.getDefinitionByName('A').must.equal('A is the result');
});
});
});
示例5: suite
suite('HealthCheckGroup', () => {
suite('Grouping', () => {
test('adding simple test adds it directly', () => {
const group = new HealthCheckGroup('test1');
const mockHealthCheck = mock<HealthCheck>(HealthCheck);
when(mockHealthCheck.getCheckName()).thenReturn('simpleId');
group.addCheck(instance(mockHealthCheck));
group.healthChecks.size.must.equal(1);
Array.from(group.healthChecks.keys()).must.eql(['simpleId']);
});
test('adding 2nd level test adds it to a group', () => {
const group = new HealthCheckGroup('test1');
const mockHealthCheck = mock<HealthCheck>(HealthCheck);
when(mockHealthCheck.getCheckName()).thenReturn('simpleId.subtest');
group.addCheck(instance(mockHealthCheck));
group.healthChecks.size.must.equal(1);
Array.from(group.healthChecks.keys()).must.eql(['simpleId']);
const simpleIdGroup = group.healthChecks.get('simpleId');
simpleIdGroup.must.be.instanceOf(HealthCheckGroup);
const asGroup = simpleIdGroup as HealthCheckGroup;
asGroup.healthChecks.size.must.equal(1);
Array.from(asGroup.healthChecks.keys()).must.eql(['subtest']);
});
test('adding 2 2nd level tests adds it to the subgroup', () => {
const group = new HealthCheckGroup('test1');
const mockHealthCheck = mock<HealthCheck>(HealthCheck);
when(mockHealthCheck.getCheckName()).thenReturn('simpleId.subtest');
group.addCheck(instance(mockHealthCheck));
const mockHealthCheck2 = mock<HealthCheck>(HealthCheck);
when(mockHealthCheck2.getCheckName()).thenReturn('simpleId.subtest2');
group.addCheck(instance(mockHealthCheck2));
group.healthChecks.size.must.equal(1);
Array.from(group.healthChecks.keys()).must.eql(['simpleId']);
const simpleIdGroup = group.healthChecks.get('simpleId');
simpleIdGroup.must.be.instanceOf(HealthCheckGroup);
const asGroup = simpleIdGroup as HealthCheckGroup;
asGroup.healthChecks.size.must.equal(2);
Array.from(asGroup.healthChecks.keys()).must.eql(['subtest', 'subtest2']);
});
test('adding 3rd level test adds it to a sub-subgroup', () => {
const group = new HealthCheckGroup('test1');
const mockHealthCheck = mock<HealthCheck>(HealthCheck);
when(mockHealthCheck.getCheckName()).thenReturn('simpleId.subtest.subsubtest');
group.addCheck(instance(mockHealthCheck));
group.healthChecks.size.must.equal(1);
Array.from(group.healthChecks.keys()).must.eql(['simpleId']);
const simpleIdGroup = group.healthChecks.get('simpleId');
simpleIdGroup.must.be.instanceOf(HealthCheckGroup);
const asGroup = simpleIdGroup as HealthCheckGroup;
asGroup.healthChecks.size.must.equal(1);
Array.from(asGroup.healthChecks.keys()).must.eql(['subtest']);
const simpleIdGroup2 = asGroup.healthChecks.get('subtest');
simpleIdGroup2.must.be.instanceOf(HealthCheckGroup);
const asGroup2 = simpleIdGroup2 as HealthCheckGroup;
asGroup2.healthChecks.size.must.equal(1);
Array.from(asGroup2.healthChecks.keys()).must.eql(['subsubtest']);
});
});
suite('Lifecycle', () => {
test('starting the group starts the checks', () => {
const group = new HealthCheckGroup('test1');
const mockHealthCheck = mock<HealthCheck>(HealthCheck);
when(mockHealthCheck.getCheckName()).thenReturn('simpleId');
group.addCheck(instance(mockHealthCheck));
group.start();
verify(mockHealthCheck.start()).once();
group.stop();
});
test('stopping the group stops the checks', () => {
const group = new HealthCheckGroup('test1');
const mockHealthCheck = mock<HealthCheck>(HealthCheck);
when(mockHealthCheck.getCheckName()).thenReturn('simpleId');
group.addCheck(instance(mockHealthCheck));
group.start();
verify(mockHealthCheck.start()).once();
group.stop();
verify(mockHealthCheck.stop()).once();
});
});
suite('Result', () => {
test('all checks OK gives OK', () => {
const group = new HealthCheckGroup('test1');
const mockHealthCheck = mock<HealthCheck>(HealthCheck);
when(mockHealthCheck.getCheckName()).thenReturn('check1');
when(mockHealthCheck.getLastResult()).thenReturn(new HealthCheckResult(HealthCheckStatus.OK, 'OK'));
const mockHealthCheck2 = mock<HealthCheck>(HealthCheck);
when(mockHealthCheck2.getCheckName()).thenReturn('check2');
when(mockHealthCheck2.getLastResult()).thenReturn(new HealthCheckResult(HealthCheckStatus.OK, 'OK'));
group.addCheck(instance(mockHealthCheck));
group.addCheck(instance(mockHealthCheck2));
group.start();
const result = group.getLastResult();
result.status.must.equal(HealthCheckStatus.OK);
group.stop();
});
//.........这里部分代码省略.........
示例6: suite
suite('util/ReadyGate', () => {
test('ReadyGate is ready by default', () => {
const gate = new ReadyGate();
gate.isChannelReady().must.be.true();
});
test('Once it\'s marked as not ready it comes back as not ready', () => {
const gate = new ReadyGate();
gate.channelNotReady();
gate.isChannelReady().must.be.false();
});
test('Once it\'s marked as ready it comes back as ready', () => {
const gate = new ReadyGate();
gate.channelNotReady();
gate.channelReady();
gate.isChannelReady().must.be.true();
});
test('Await returns immediately if the gate is ready', async () => {
const gate = new ReadyGate();
const ready = {ready: false};
const promise = gate.awaitChannelReady().then(() => { ready.ready = true; });
await new Promise<void>((resolve) => { setTimeout(resolve, 0);});
ready.ready.must.be.true();
});
test('Await does not return immediately if the gate is not ready', async () => {
const gate = new ReadyGate();
gate.channelNotReady();
const ready = {ready: false};
gate.awaitChannelReady().then(() => { ready.ready = true; });
await new Promise<void>((resolve) => { setTimeout(resolve, 50);});
ready.ready.must.be.false();
gate.channelReady();
gate.awaitChannelReady().then(() => { ready.ready = true; });
await new Promise<void>((resolve) => { setTimeout(resolve, 0);});
ready.ready.must.be.true();
});
});
示例7: suite
suite('mysql/MysqlHealthCheck', () => {
test('Readonly flag is passed (true)', async () => {
const check = new MySQLHealthCheck('testCheck', true);
const mockedMysqlClient = mock(MySQLClient);
when(mockedMysqlClient.ping(anything())).thenReturn(Promise.resolve(undefined));
check.mysqlClient = instance(mockedMysqlClient);
await check.doCheck();
verify(mockedMysqlClient.ping(true)).once();
});
test('Readonly flag is passed (false)', async () => {
const check = new MySQLHealthCheck('testCheck', false);
const mockedMysqlClient = mock(MySQLClient);
when(mockedMysqlClient.ping(anything())).thenReturn(Promise.resolve(undefined));
check.mysqlClient = instance(mockedMysqlClient);
await check.doCheck();
verify(mockedMysqlClient.ping(false)).once();
});
test('OKs on success', async () => {
const check = new MySQLHealthCheck('testCheck', false);
const mockedMysqlClient = mock(MySQLClient);
when(mockedMysqlClient.ping(anything())).thenReturn(Promise.resolve(undefined));
check.mysqlClient = instance(mockedMysqlClient);
await check.runCheck();
const result = check.getLastResult();
result.status.must.equal(HealthCheckStatus.OK);
});
test('CRITICAL on exception', async () => {
const check = new MySQLHealthCheck('testCheck', false);
const mockedMysqlClient = mock(MySQLClient);
when(mockedMysqlClient.ping(anything())).thenThrow(new Error('Error'));
check.mysqlClient = instance(mockedMysqlClient);
await check.runCheck();
const result = check.getLastResult();
result.status.must.equal(HealthCheckStatus.CRITICAL);
});
});
示例8: suite
suite('ioc/Decorators', () => {
suite('Autowire', () => {
test('Autowire gets called', () => {
// const val = new Test1();
Reflect.hasMetadata('inceptum', Test1.prototype).must.be.true();
const metadata = Reflect.getMetadata('inceptum', Test1.prototype);
metadata.autowire.get('prop1').must.equal('the value');
});
test('Autowire by config gets called', async () => {
const context = new Context('test1', undefined, {config: new JsonProvider({my: {config: 'value' }})});
context.addObjectDefinitionInspector(new ObjectDefinitionDecoratorInspector());
context.registerSingletons(ConfigAutowire);
await context.lcStart();
const wireInto: ConfigAutowire = await context.getObjectByName('ConfigAutowire');
wireInto.val.must.equal('value');
await context.lcStop();
});
test('Autowire by config gets called and default is used if not available', async () => {
const context = new Context('test1', undefined, {config: new JsonProvider({})});
context.addObjectDefinitionInspector(new ObjectDefinitionDecoratorInspector());
context.registerSingletons(ConfigAutowire);
await context.lcStart();
const wireInto: ConfigAutowire = await context.getObjectByName('ConfigAutowire');
wireInto.val.must.equal('default');
await context.lcStop();
});
});
suite('Lazy', () => {
test('Lazy gets called', () => {
// const val = new Test1();
Reflect.hasMetadata('inceptum', Test1.prototype).must.be.true();
const metadata = Reflect.getMetadata('inceptum', Test1.prototype);
metadata.lazy.must.be.false();
});
});
suite('Groups', () => {
test('Groups are Autowired', async () => {
const context = new Context('test1');
context.addObjectDefinitionInspector(new ObjectDefinitionDecoratorInspector());
context.registerDefinition(new BaseSingletonDefinition(Wired1));
context.registerDefinition(new BaseSingletonDefinition(Wired2));
context.registerDefinition(new BaseSingletonDefinition(Wired3));
context.registerDefinition(new BaseSingletonDefinition(WireInto));
await context.lcStart();
const wireInto: WireInto = await context.getObjectByName('WireInto');
wireInto.prop1.length.must.equal(2);
(wireInto.prop1[0] instanceof Wired1).must.be.true();
(wireInto.prop1[1] instanceof Wired2).must.be.true();
wireInto.prop2.length.must.equal(1);
(wireInto.prop2[0] instanceof Wired3).must.be.true();
wireInto.prop3.length.must.equal(0);
await context.lcStop();
});
});
suite('Context', () => {
test('The Context is Autowired', async () => {
const context = new Context('test1');
context.addObjectDefinitionInspector(new ObjectDefinitionDecoratorInspector());
context.registerSingletons(ContextAutowire);
await context.lcStart();
const contextAutowire: ContextAutowire = await context.getObjectByName('ContextAutowire');
contextAutowire.context.must.eql(context);
await context.lcStop();
});
});
});