Example #1
0
  test('`waitUntilWatchIsReady` correctly handles `tsc` output', async () => {
    buildOutputStream.emit('data', Buffer.from('$ tsc'));
    buildOutputStream.emit('data', Buffer.from('Compilation complete.'));

    jest.runAllTimers();

    expect(await completionHintPromise).toBe('tsc');
  });
Example #2
0
  test('`waitUntilWatchIsReady` correctly handles `webpack` output', async () => {
    buildOutputStream.emit('data', Buffer.from('$ webpack'));
    buildOutputStream.emit('data', Buffer.from('Chunk Names'));

    jest.runAllTimers();

    expect(await completionHintPromise).toBe('webpack');
  });
Example #3
0
  test('`waitUntilWatchIsReady` fallbacks to default output handler if output is not recognizable', async () => {
    buildOutputStream.emit('data', Buffer.from('$ some-cli'));
    buildOutputStream.emit('data', Buffer.from('Compilation complete.'));
    buildOutputStream.emit('data', Buffer.from('Chunk Names.'));

    jest.runAllTimers();

    expect(await completionHintPromise).toBe('timeout');
  });
Example #4
0
 return () => {
   bag.dispose();
   if (input) {
     input.removeAllListeners();
   }
   if (output) {
     output.removeAllListeners();
   }
 };
window.addEventListener("storage", (event) => {
  if (event.key !== storageKey) return;

  const oldPub = pub;
  pub = JSON.parse(event.newValue);

  if (oldPub.keyMap !== pub.keyMap) emitter.emit("keyMap");
  if (oldPub.theme !== pub.theme) emitter.emit("theme");
});
Example #6
0
  return new Promise<any>((resolve, reject) => {
    emitter.once(event, (value: any) => {
      resolve(value);
    });

    emitter.once('error', (err: Error) => {
      reject(err);
    });
  });
Example #7
0
 zoneA.run(() => {
   emitter.on('removeListener', function(type: string, handler: any) {
     zoneResults.push('remove' + type);
   });
   emitter.on('test', shouldNotRun);
   emitter.on('test1', expectZoneA);
   emitter.removeAllListeners('test');
   expect(zoneResults).toEqual(['removetest']);
   expect(emitter.listeners('removeListener').length).toBe(1);
 });
Example #8
0
				response.on('end', function() {
					try {
						output = JSON.parse(content)
						emitter.emit('done', output)
					}
					catch (e) {
						e.cause = content
						emitter.emit('error', e)
					}
				})
Example #9
0
    it('.get with invalid service name and arguments', done => {
      const socket = new EventEmitter();

      provider.emit('connection', socket);

      socket.emit('get', null, (error: any) => {
        assert.strictEqual(error.name, 'NotFound');
        assert.strictEqual(error.message, `Service 'null' not found`);
        done();
      });
    });
Example #10
0
function addHandler(emitter: EventEmitter, event: string, handler: (...args: Array<any>) => void) {
  if (isLogEvent) {
    emitter.on(event, (...args: Array<any>) => {
      console.log("%s %s", event, args)
      handler.apply(null, args)
    })
  }
  else {
    emitter.on(event, handler)
  }
}
Example #11
0
function addHandler(emitter: EventEmitter, event: string, handler: Function) {
  if (isLogEvent) {
    emitter.on(event, function (...args: any[]) {
      console.log("%s %s", event, args)
      handler.apply(null, args)
    })
  }
  else {
    emitter.on(event, handler)
  }
}
Example #12
0
 zoneA.run(() => {
   emitter.on('removeListener', function(type: string, handler: any) {
     zoneResults.push('remove' + type);
   });
   emitter.on('newListener', function(type: string, handler: any) {
     zoneResults.push('new' + type);
   });
   emitter.on('test', shouldNotRun);
   emitter.removeListener('test', shouldNotRun);
   expect(zoneResults).toEqual(['newtest', 'removetest']);
 });
Example #13
0
 const showCommands = (e: KeyboardEvent) => {
     if (e.shiftKey && isCmdOrCtrl(e) && e.key === 'P') {
         pubsub.emit('actions-toggle-show')
     } else if (!e.shiftKey && isCmdOrCtrl(e) && e.key === 'p') {
         pubsub.emit('table-search-toggle-show')
     } else if (!e.shiftKey && isCmdOrCtrl(e) && e.key === 'h') {
         pubsub.emit('history-list')
     } else if (!e.shiftKey && isCmdOrCtrl(e) && e.key === '1') {
         pubsub.emit('editor-focus')
     } else if (!e.shiftKey && isCmdOrCtrl(e) && e.key === '2') {
         pubsub.emit('results-focus')
     }
 }
Example #14
0
test('AsyncIterable#fromEvent writes before emit', async () => {
  const e = new EventEmitter();
  const a = fromEvent(e, EVENT_TYPE);

  e.emit(EVENT_TYPE, 1);
  e.emit(EVENT_TYPE, 2);
  e.emit(EVENT_TYPE, 3);

  const it = a[Symbol.asyncIterator]();
  await hasNext(it, 1);
  await hasNext(it, 2);
  await hasNext(it, 3);
});
Example #15
0
function TwitterWatcher() {
    if (!(this instanceof TwitterWatcher)) {
        return new TwitterWatcher();
    }

    events.EventEmitter.call(this);
}
Example #16
0
	constructor(filename: string) {
		super();
		EventEmitter.call(this);
		this.filename = filename;
		this.stack = [];
		this.paused = false;
	}
Example #17
0
 private invokeOnDispatch(payload: Event) {
   this.changed = false;
   this.onDispatch(payload);
   if (this.changed) {
     this.emitter.emit(CHANGE_EVENT);
   }
 }
 test('it broadcasts if case sensitivity has been updated', done => {
     eventBus.on(Event.TOGGLED_CASE_SENSITIVITY, (mode: any) => {
         assertKeyExists(mode, 'ignoreCase');
         done();
     });
     registry.toggleCaseSensitivity();
 });
Example #19
0
  '.on': function() {
    const emitter = new EventEmitter();

    let called = false;
    const handle = util.on(emitter, 'foo', function() {
      called = true;
    });
    emitter.emit('foo');
    assert.isTrue(called);
    assert.property(handle, 'destroy');

    handle.destroy();
    called = false;
    emitter.emit('foo');
    assert.isFalse(called);
  },
Example #20
0
 const emitUpdate = () => {
     const event: ICommitControlUpdateEvent = {
         uncommited,
         autoCommit: connection.settings().autoCommit,
     }
     pubsub.emit('commit-ctrl-update', event)
 }
Example #21
0
function Updater(time) {
    this.time = time;
    this.array = [
        {number: 1},
        {number: 2}
    ];
    var that;
    events.EventEmitter.call(this);

    this.init = function()
    {
        that = this;
        console.log("Contructor");
        //Start interval
        setInterval(that.run,that.time);
    };

    this.run = function()
    {
        that.array.forEach(function (item) {
           if(item.number === 2)
           {
               that.emit('Event');
           }
        });
    };
}
Example #22
0
				it("is raised when working with device", (done: mocha.Done) => {
					const expectedDebuggableViewInfo: Mobile.IDebugWebViewInfo = createDebuggableWebView("test1");

					attachDebuggableEventVerificationHandler(deviceInstance.deviceInfo.identifier, appId, expectedDebuggableViewInfo, done);
					devicesService.emit(DeviceDiscoveryEventNames.DEVICE_FOUND, deviceInstance);
					deviceInstance.applicationManager.emit(applicationEvent, appId, expectedDebuggableViewInfo);
				});
Example #23
0
		describe("deviceLogProvider on data", () => {
			let deviceLogProvider: EventEmitter;

			beforeEach(() => {
				deviceLogProvider = testInjector.resolve("deviceLogProvider");
			});

			describe(`raises ${DEVICE_LOG_EVENT_NAME} with correct identifier and data`, () => {
				const expectedDeviceLogData = "This is some log data from device.";

				const attachDeviceLogDataVerificationHandler = (expectedDeviceIdentifier: string, done: mocha.Done) => {
					deviceEmitter.on(DEVICE_LOG_EVENT_NAME, (identifier: string, data: any) => {
						assert.deepEqual(identifier, expectedDeviceIdentifier);
						assert.deepEqual(data, expectedDeviceLogData);
						// Wait for all operations to be completed and call done after that.
						setTimeout(() => done(), 0);
					});
				};

				it("is called when device reports data", (done: mocha.Done) => {
					attachDeviceLogDataVerificationHandler(deviceInstance.deviceInfo.identifier, done);
					devicesService.emit(DeviceDiscoveryEventNames.DEVICE_FOUND, deviceInstance);
					deviceLogProvider.emit("data", deviceInstance.deviceInfo.identifier, expectedDeviceLogData);
				});
			});
		});
Example #24
0
 groupTables._transform = (chunk, _, next) => {
     const [
         table,
         tableSchema,
         tableRemarks,
         tableType,
         columnName,
         columnRemarks,
         columnType,
         length,
         scale,
     ] = chunk
     if (!currentTable || currentTable.table !== table) {
         if (currentTable) {
             groupTables.push(currentTable)
             pubsub.emit('export-table', currentTable)
         }
         currentTable = {
             table,
             schema: tableSchema,
             remarks: tableRemarks,
             type: getTableType(tableType),
             columns: [],
         }
     }
     currentTable.columns.push({
         type: columnType,
         name: columnName,
         remarks: columnRemarks,
         precision: Number(length),
         scale: Number(scale),
     })
     next()
 }
Example #25
0
 groupTables._flush = done => {
     if (currentTable) {
         groupTables.push(currentTable)
         pubsub.emit('export-table', currentTable)
     }
     done()
 }
  const removeSocketListener = (
    subscriptionUrl: string, 
    subscriptionId: string, 
    callback: Subscriptions.HookCallback<any, any> | Subscriptions.SubscriptionCallback<any>, 
    sendApi: boolean
  ) => {
    if (!socket().isConnected()) {
      return;
    }

    subscriptions[subscriptionId]--;
    emitter.removeListener(subscriptionId, callback);

    if (subscriptions[subscriptionId] === 0) {
      if (sendApi && socket().isConnected()) {
        socket().delete(subscriptionUrl)
          .catch(
            (error: Requests.ErrorResponse) => {
              logger.error('Failed to remove socket listener', subscriptionUrl, error);
            });
      }

      delete subscriptions[subscriptionId];
    }
  };
Example #27
0
 channelManager.configure = function (newConfig) {
   if (channelManager.hasChannels()) {
     logger.warn("`configure()` must be called before channels are created.");
   }
   config.configure(newConfig);
   return channelManager;
 };
export async function statusEventCallback(event: {
  payload: IGitHubStatusPayload | IGitHubStatusTestPayload;
}) {
  try {
    const repo = event.payload.repository.name;
    const ci = new Circle(repo);

    log(
      chalk.bgBlue(`${chalk.black("New build from:")} ${chalk.yellow(repo)}`)
    );
    const circleBuildPayload = await ci.getBuildData(event.payload);
    log(chalk.blue(`Circle status: ${circleBuildPayload.data.status}`));

    if (circleBuildPayload.data) {
      try {
        await slack.notifyBuildStatus(circleBuildPayload.data);
        log(chalk.blue("Slack notified: 👍"));
      } catch (e) {
        const msg = e.hasOwnProperty("response") ? e.response.data : e.hasOwnProperty('message') ? e.message : e;
        if (msg.toString().indexOf("Irrelevant build event") === -1)
          throw new SlackServicesError(msg);
      }
    }

    middlewareEventHandler.emit("complete");
  } catch (e) {
    if (e.toString().indexOf("Not a Circle event") > -1) log(e.toString());
    else githubEvents.emit("error", e);
  }
}
 test('it broadcasts if whole/partial match has been toggled', done => {
     eventBus.on(Event.WHOLE_MATCH_MODE_TOGGLED, (mode: any) => {
         assertKeyExists(mode, 'wholeMatch');
         done();
     });
     registry.toggleWholeMatch();
 });
Example #30
0
test('AsyncIterable#fromEventPattern writes before emit', async () => {
  const e = new EventEmitter();
  const a = fromEventPattern(
    h => e.addListener(EVENT_TYPE, h),
    h => e.removeListener(EVENT_TYPE, h)
  );

  e.emit(EVENT_TYPE, 1);
  e.emit(EVENT_TYPE, 2);
  e.emit(EVENT_TYPE, 3);

  const it = a[Symbol.asyncIterator]();
  await hasNext(it, 1);
  await hasNext(it, 2);
  await hasNext(it, 3);
});