// receiving metrics now would cause an emit sandbox.stub(metricsProvider, "emit").callsFake((key, data, discardEvent) => { if (discardEvent) { return; } expect(key) .to.be.a("string") .that.equals("metrics"); expect(data) .to.be.an("object") .that.deep.equals( _.last(metricsProvider._aggregation[metricsProvider.zoomLevelKey].data) ); });
beforeEach(() => { sandbox = sinon.createSandbox(); mockStart = 10000000; mockNow = mockStart; sandbox.stub(Date, "now").callsFake(() => mockNow); fill = function (count, interval) { const mockData = []; for (let i = 0; i < count; ++i) { mockNow += interval; const mockMetric = createMockMetric(); metricsProvider._onMetrics(mockMetric); mockData.push(mockMetric); } return mockData; }; testContainer = utils.getTestContainer(sandbox); metricsProvider = new MetricsProvider(testContainer.screen); });
describe("startGraphs", () => { it("offsets at the end or the beginning of the data set", () => { // load some data fill(100, 500); sandbox.stub(metricsProvider, "adjustScrollOffset").callsFake((direction) => { let length = metricsProvider._aggregation[AGGREGATE_TIME_LEVELS[0]].data.length; length = direction < 0 ? -length : Number(length); expect(direction) .to.be.a("number") .that.equals(length); }); metricsProvider.startGraphs(-1); metricsProvider.startGraphs(+1); }); });
describe("resetGraphs", () => { it("resets zoom level and scroll offsets", () => { sandbox.stub(metricsProvider, "setZoomLevel").callsFake((zoom) => { expect(zoom) .to.be.a("number") .that.equals(0); }); _.each(AGGREGATE_TIME_LEVELS, (level) => { expect(metricsProvider) .to.be.an("object") .with.property("_aggregation") .which.is.an("object") .with.property(level) .which.is.an("object") .with.property("scrollOffset") .which.is.a("number") .that.equals(0); }); metricsProvider.resetGraphs(); }); });
let seed1 = Math.random(); let seed2 = Math.random(); let stub = sinon.stub(mathRandom, 'onBeforeRun').callsFake((kernel) => { kernel.setUniform1f('randomSeed1', seed1); kernel.setUniform1f('randomSeed2', seed2); assert.ok(stub.called); stub.restore(); stub.callsFake((kernel) => { kernel.setUniform1f('randomSeed1', seed1); kernel.setUniform1f('randomSeed2', seed2);
pool.querySpy.callsFake(() => { return new Promise((resolve) => { resolveQuery = resolve;
}, ]}; const stub = sinon.stub(updates.githubApi.repos, 'getReleases').callsFake(() => Promise.resolve(mockReleaseData)); return updates.refresh('beta.2') .then(data => {
const reportable = _.size(_.filter(endpoints, endpoint => endpoint.report)); const metrics = new Metrics({id, endpoints, data: {prisoner: 'valjean'}}); sinon.stub(axios, 'create').callsFake(({baseURL = 'localhost'} = {}) => ({ post: (path, data) => { baseURL.should.equal(endpoints[counter].url); const reportable = _.size(_.filter(endpoints, endpoint => endpoint.report)); const metrics = new Metrics({endpoints, log: {debug: sinon.spy(), verbose: sinon.spy()}}); sinon.stub(axios, 'create').callsFake(() => ({ post: () => Promise.reject(), })); const endpoints = [{url: 'https://place.for.the.things/metrics', report: true}]; const metrics = new Metrics({endpoints, data: {inspector: 'javier'}}); sinon.stub(axios, 'create').callsFake(() => ({ post: (path, data) => { if (data.action === 'escape') data.should.have.property('freedman', 'valjean');
describe( 'legacy-routes', () => { describe( '#isLegacyRoute()', () => { beforeAll( () => { sinon.stub( config, 'isEnabled' ).callsFake( ( flag ) => { return features.indexOf( flag ) > -1; } );
beforeEach(() => { let counter = {}; sinon.stub(axios, 'create').callsFake(() => ({ get: url => { counter[url] = counter[url] + 1 || 0;
describe('#sh', () => { it('should use shelljs.exec when mode is exec and detached is false', () => { const shell = new Shell(); sinon.stub(_shell, 'exec').callsFake(fakeExec); return shell.sh(['slip', 'sliding', 'away']) .then(result => { sinon.stub(child, 'spawn').callsFake(fakeSpawn); _.forEach([{mode: 'collect'}, {detached: true}], opts => { return shell.sh(['tupelo', 'honey', 'baby'], opts) sinon.stub(child, 'spawn').callsFake(fakeSpawn); return shell.sh(['set', 'us', 'up', 'the', 'bomb'], {mode: 'attach'}).should.be.rejected .then(child.spawn.restore()); sinon.stub(child, 'spawn').callsFake(fakeSpawn); return shell.sh(['van', 'the', 'man'], {detached: true}).should.be.fulfilled .then(child.spawn.restore()); const shell = new Shell(); process.lando = 'browser'; sinon.stub(child, 'spawn').callsFake((cmd, args, opts) => { opts.stdio[0].should.equal('ignore'); opts.stdio[1].should.equal('pipe'); const shell = new Shell(); process.lando = 'node'; sinon.stub(child, 'spawn').callsFake((cmd, args, opts) => { opts.stdio.should.equal('inherit'); return {
describe('storage:s3', function() { var createClientStub, uploadFileStub, onSpy beforeEach(function(){ onSpy = sinon.stub().callsFake(function(type, func) { if (type === 'end') { func({})
beforeAll(() => { try { fs.statSync(configPath); fs.unlinkSync(configPath); } catch (e) { // no config, just exit } sinon .stub(inquirer, 'prompt') .onFirstCall() .callsFake(() => Promise.resolve(configData)) .onSecondCall() .callsFake(() => Promise.resolve(users[0])) .onThirdCall() .callsFake(() => Promise.resolve(users[1])); });
it('should update password and send confirmation email when email and reset token are valid', async () => { await PasswordResetToken.create(resetToken); sandbox .stub(emailProvider, 'sendPasswordChangeEmail') .callsFake(() => Promise.resolve('email sent')); return request(app) .post('/v1/auth/reset-password') .send({ email: dbUser.email, password: 'updatedPassword2', resetToken: resetToken.resetToken, }) .expect(httpStatus.OK) .then((res) => { expect(res.body).to.be.equal('Password Updated'); }); });