beforeEach(() => {
        clock = sinon.useFakeTimers();
        // Pretend we are a browser
        global['navigator'] = {
            hardwareConcurrency: 8,
            oscpu: 'Win32',
            language: 'en-GB',
            userAgent: 'foo',
            platform: 'Win32'
        };

        global['screen'] = {
            width: 1024,
            height: 1024,
            colorDepth: 32,
            orientation: {
                type: 'landscape-primary'
            }
        };

        global['window'] = {
            outerWidth: 1000,
            outerHeight: 1000,
            innerWidth: 950,
            innerHeight: 950
        };
        
        subject = new UserEnvironment();

    });
Beispiel #2
0
    test('build range filter in iso format', () => {
      const clock = sinon.useFakeTimers(moment.utc([2000, 1, 1, 0, 0, 0, 0]).valueOf());

      const filter = getTime(
        {
          id: 'test',
          title: 'test',
          timeFieldName: 'date',
          fields: [
            {
              name: 'date',
              type: 'date',
              esTypes: ['date'],
              aggregatable: true,
              searchable: true,
              filterable: true,
            },
          ],
        },
        { from: 'now-60y', to: 'now' }
      ) as Filter;
      expect(filter.range.date).to.eql({
        gte: '1940-02-01T00:00:00.000Z',
        lte: '2000-02-01T00:00:00.000Z',
        format: 'strict_date_optional_time',
      });
      clock.restore();
    });
Beispiel #3
0
 it('should use current time if not passed', () => {
   const fakeTimers = sinon.useFakeTimers();
   fakeTimers.setSystemTime(112233 * 1000);
   inst.lastReceipt.update();
   expect(inst.lastReceipt.get()).to.be.eq(112233);
   fakeTimers.restore();
 });
Beispiel #4
0
 it('should return true if updated was call more than 10secs ago (see before)', () => {
   const t = sinon.useFakeTimers();
   inst.lastReceipt.update();
   t.tick(10000);
   expect(inst.lastReceipt.isStale()).is.true;
   t.restore();
 });
    function () {
      const clock = sinon.useFakeTimers();

      const autoReload = true;
      const updatePreset = sinon.stub().returns(Promise.resolve());
      const applyCustomization = sinon.spy();
      const reload = sinon.spy();
      const cancel = sinon.stub();
      const showCustomizationMessage = sinon.spy();

      return applyDetection('', '', undefined, undefined, undefined, autoReload,
        updatePreset, applyCustomization, reload, cancel, showCustomizationMessage)
        .then(() => {
          // No functions should have been called before 1s
          clock.tick(999);
          expect(applyCustomization.called).to.be.false;
          expect(reload.called).to.be.false;
          expect(showCustomizationMessage.called).to.be.false;

          // Only 'applyCustomization' and 'reload' functions should have been called on 1s
          clock.tick(1);
          expect(applyCustomization.called).to.be.true;
          expect(reload.called).to.be.true;
          expect(showCustomizationMessage.called).to.be.false;

          clock.restore();
        });
    });
Beispiel #6
0
    test('failed RPC call', function (done) {
      var clock = sinon.useFakeTimers()

      var daemon = new stratum.Daemon({
        path: '/doesnt/exist/%s',
        datadir: 'data/dir',
        port: 8080,
        host: 'localhost',
        user: '******',
        password: '******',
        name: 'Mycoin'
      })

      sinon.stub(daemon.rpc, 'call').callsFake(function (name, params, callback) {
        if (name === 'test') {
          callback('error')
        }
      })

      daemon.call('test').catch(function (message) {
        expect(message).to.equal('error')
      }).done(function () {
        var promise = daemon.call('timeout')
        clock.tick(4000)

        promise.catch(function (message) {
          expect(message).to.be('Command timed out')
        }).done(function () {
          clock.restore()
          done()
        })
      })

    })
Beispiel #7
0
    it('can temporarily be disabled with ssrForceFetchDelay', () => {
      clock = sinon.useFakeTimers();

      const client = new ApolloClient({
        networkInterface,
        ssrForceFetchDelay: 100,
        addTypename: false,
      });

      // Run a query first to initialize the store
      const outerPromise = client.query({ query })
        // then query for real
        .then(() => {
          const promise = client.query({ query, forceFetch: true });
          clock.tick(0);
          return promise;
        })
        .then((result) => {
          assert.deepEqual(result.data, { myNumber: { n: 1 } });
          clock.tick(100);
          const promise = client.query({ query, forceFetch: true });
          clock.tick(0);
          return promise;
        })
        .then((result) => {
          assert.deepEqual(result.data, { myNumber: { n: 2 } });
        });
      clock.tick(0);
      return outerPromise;
    });
 beforeEach(async () => {
     await blockchainLifecycle.startAsync();
     const sinonTimerConfig = { shouldAdvanceTime: true } as any;
     // This constructor has incorrect types
     timer = Sinon.useFakeTimers(sinonTimerConfig);
     currentUnixTimestampSec = utils.getCurrentUnixTimestampSec();
     expirationWatcher = new ExpirationWatcher();
 });
Beispiel #9
0
    it('should calculate `nextRunAt` with `interval`', () => {
        const clock = sinon.useFakeTimers(new Date('2016-07-05 22:02:50').getTime());

        return instance.every((1000 * 60 * 5), 'task5', {qwe: 'asd'}).then((createdTask) => {
            createdTask.nextRunAt.getTime().should.be.equal(new Date('2016-07-05 22:07:50').getTime());
            clock.restore();
        });
    });
Beispiel #10
0
    it('should calculate `nextRunAt` with `runAtTime`', () => {
        const clock = sinon.useFakeTimers(new Date('2016-07-05 22:02:50').getTime());

        return instance.everyDayAt('00:00', 'task4', {qwe: 'asd'}).then((createdTask) => {
            createdTask.nextRunAt.getTime().should.be.equal(new Date('2016-07-06 00:00:00').getTime());
            clock.restore();
        });
    });