fs#watchFile TypeScript Examples

The following examples show how to use fs#watchFile. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LogWatcher.ts    From awakened-poe-trade with MIT License 6 votes vote down vote up
static async watch (path: string) {
    if (this.file) {
      unwatchFile(this.filePath!)
      await this.file.close()
      this.file = undefined
      this.isReading = false
    }

    watchFile(path, { interval: 450 }, () => {
      this.handleFileChange()
    })
    this.filePath = path

    this.file = await fs.open(path, 'r')
    const stats = await this.file.stat()
    this.offset = stats.size
  }
Example #2
Source File: commandBuilder.test.ts    From bedrock-cli with MIT License 6 votes vote down vote up
describe("Tests Command Builder's exit function", () => {
  it("calling exit function", async (done) => {
    (watchFile as jest.Mock).mockImplementationOnce((f, cb) => {
      cb({ size: 100 });
    });
    const exitFn = jest.fn();
    await exitCmd(logger, exitFn, 1, 100).then(() => {
      expect(exitFn).toBeCalledTimes(1);
      expect(exitFn.mock.calls).toEqual([[1]]);
      done();
    });
  });
  it("calling exit function without file transport", async (done) => {
    const exitFn = jest.fn();
    await exitCmd(
      createLogger({
        defaultMeta: { service: "bedrock" },
        level: "info",
        transports: [],
      }),
      exitFn,
      1,
      100
    ).then(() => {
      expect(exitFn).toBeCalledTimes(1);
      expect(exitFn.mock.calls).toEqual([[1]]);
      done();
    });
  });
});