Example #1
0
    it('should stop an older process if exist', () => {
      const clock = lolex.install();
      routineService.start(
        createRoutine({
          routineId: 'test',
          enabled: true,
          interval: '* * * * * *',
          nextRunAt: new Date('2018-01-01'),
        }),
      );

      routineService.start(
        createRoutine({
          routineId: 'test',
          enabled: true,
          interval: '* * * * * *',
          nextRunAt: new Date('2018-01-01'),
        }),
      );

      clock.uninstall();
      expect(clock.countTimers()).toBe(1);
    });
Example #2
0
    it('should start a new process and call it every second', () => {
      const spy = jest.spyOn(Routine, 'run');
      const clock = lolex.install();
      routineService.start(
        createRoutine({
          interval: '* * * * * *',
        }),
      );

      clock.tick(1000);
      clock.tick(1000);
      clock.uninstall();

      expect(spy).toHaveBeenCalledTimes(2);
    });
Example #3
0
    it('should not start a new process if not enabled', () => {
      const spy = jest.fn();
      const clock = lolex.install();
      routineService.start(
        createRoutine({
          routineId: 'test',
          enabled: false,
          interval: '* * * * * *',
          nextRunAt: new Date('2018-01-01'),
        }),
        spy,
      );

      clock.next();
      clock.uninstall();

      expect(spy).not.toHaveBeenCalled();
    });
Example #4
0
    it('should do nothing if routineId is unknow', () => {
      const spy = jest.spyOn(Routine, 'run');
      const clock = lolex.install();
      routineService.start(
        createRoutine({
          routineId: 'test',
          enabled: true,
          interval: '* * * * * *',
          nextRunAt: new Date('2018-01-01'),
        }),
      );

      routineService.stop('unknow');
      clock.next();
      clock.uninstall();

      expect(spy).toHaveBeenCalledTimes(1);
    });
Example #5
0
    it('should stop a process', () => {
      const spy = jest.spyOn(Routine, 'run');
      const clock = lolex.install();
      routineService.start(
        createRoutine({
          routineId: 'test',
          enabled: true,
          interval: '0 12 * * * *',
          nextRunAt: new Date('2018-01-01'),
        }),
      );

      routineService.stop('test');

      clock.next();
      clock.uninstall();

      expect(spy).not.toHaveBeenCalled();
    });