How to use the @ionic/utils-stream.ReadableStreamBuffer function in @ionic/utils-stream

To help you get started, we’ve selected a few @ionic/utils-stream examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ionic-team / ionic-cli / packages / @ionic / utils-subprocess / src / __tests__ / index.ts View on Github external
it('should pipe stdout and stderr in run()', async () => {
      const cmd = new Subprocess('cmd', []);
      const mockSpawnStdout = new ReadableStreamBuffer();
      const mockSpawnStderr = new ReadableStreamBuffer();
      const cp = new class extends EventEmitter { stdout = mockSpawnStdout; stderr = mockSpawnStderr; };
      mockCrossSpawn.mockImplementation(() => cp);
      const stdoutMock = new WritableStreamBuffer();
      const stderrMock = new WritableStreamBuffer();
      const promise = cmd.run();
      promise.p.stdout.pipe(stdoutMock);
      promise.p.stderr.pipe(stderrMock);
      mockSpawnStdout.feed('hello world!');
      mockSpawnStdout.stop();
      mockSpawnStderr.feed('oh no!');
      mockSpawnStderr.stop();
      await Promise.all([promisifyEvent(stdoutMock, 'finish'), promisifyEvent(stderrMock, 'finish')]);
      cp.emit('close', 0);
      await promise;
      expect(mockCrossSpawn).toHaveBeenCalledTimes(1);
      expect(stdoutMock.consume().toString()).toEqual('hello world!');
github ionic-team / ionic-cli / packages / @ionic / utils-subprocess / src / __tests__ / index.ts View on Github external
it('should have child process in run() return value', async () => {
      const cmd = new Subprocess('cmd', []);
      const mockSpawnStdout = new ReadableStreamBuffer();
      const mockSpawnStderr = new ReadableStreamBuffer();
      const cp = new class extends EventEmitter { stdout = mockSpawnStdout; stderr = mockSpawnStderr; };
      mockCrossSpawn.mockImplementation(() => cp);
      const promise = cmd.run();
      expect(promise.p).toBe(cp);
    });
github ionic-team / ionic-cli / packages / @ionic / utils-subprocess / src / __tests__ / index.ts View on Github external
it('should error with combined output for output()', async done => {
      const cmd = new Subprocess('cmd', []);
      const mockSpawnStdout = new ReadableStreamBuffer();
      const mockSpawnStderr = new ReadableStreamBuffer();
      const cp = new class extends EventEmitter { stdout = mockSpawnStdout; stderr = mockSpawnStderr; };
      mockCrossSpawn.mockImplementation(() => cp);
      const p = cmd.output();
      const outletter = '1';
      const errletter = '2';
      const outinput = outletter.repeat(26);
      const errinput = errletter.repeat(26);
      mockSpawnStdout.feed(outinput);
      mockSpawnStdout.stop();
      mockSpawnStderr.feed(errinput);
      mockSpawnStderr.stop();
      await Promise.all([promisifyEvent(mockSpawnStdout, 'end'), promisifyEvent(mockSpawnStderr, 'end')]);
      cp.emit('close', 1);
      try {
        await p;
      } catch (e) {
github ionic-team / ionic-cli / packages / @ionic / utils-subprocess / src / __tests__ / index.ts View on Github external
it('should error for signal exit', async () => {
      const cmd = new Subprocess('cmd', []);
      const mockSpawnStdout = new ReadableStreamBuffer();
      const mockSpawnStderr = new ReadableStreamBuffer();
      const cp = new class extends EventEmitter { stdout = mockSpawnStdout; stderr = mockSpawnStderr; };
      mockCrossSpawn.mockImplementation(() => cp);
      const buf = new WritableStreamBuffer();
      const promise = cmd.run();
      promise.p.stdout.pipe(buf);
      promise.p.stderr.pipe(buf);
      mockSpawnStdout.stop();
      mockSpawnStderr.stop();
      await promisifyEvent(buf, 'finish');
      cp.emit('close', null, 'SIGINT');
      await expect(promise).rejects.toThrow('Signal exit from subprocess.');
    });
github ionic-team / ionic-cli / packages / @ionic / utils-subprocess / src / __tests__ / index.ts View on Github external
it('should have child process in run() return value', async () => {
      const cmd = new Subprocess('cmd', []);
      const mockSpawnStdout = new ReadableStreamBuffer();
      const mockSpawnStderr = new ReadableStreamBuffer();
      const cp = new class extends EventEmitter { stdout = mockSpawnStdout; stderr = mockSpawnStderr; };
      mockCrossSpawn.mockImplementation(() => cp);
      const promise = cmd.run();
      expect(promise.p).toBe(cp);
    });
github ionic-team / ionic-cli / packages / @ionic / utils-subprocess / src / __tests__ / index.ts View on Github external
it('should pipe stdout and stderr in run()', async () => {
      const cmd = new Subprocess('cmd', []);
      const mockSpawnStdout = new ReadableStreamBuffer();
      const mockSpawnStderr = new ReadableStreamBuffer();
      const cp = new class extends EventEmitter { stdout = mockSpawnStdout; stderr = mockSpawnStderr; };
      mockCrossSpawn.mockImplementation(() => cp);
      const stdoutMock = new WritableStreamBuffer();
      const stderrMock = new WritableStreamBuffer();
      const promise = cmd.run();
      promise.p.stdout.pipe(stdoutMock);
      promise.p.stderr.pipe(stderrMock);
      mockSpawnStdout.feed('hello world!');
      mockSpawnStdout.stop();
      mockSpawnStderr.feed('oh no!');
      mockSpawnStderr.stop();
      await Promise.all([promisifyEvent(stdoutMock, 'finish'), promisifyEvent(stderrMock, 'finish')]);
      cp.emit('close', 0);
      await promise;
      expect(mockCrossSpawn).toHaveBeenCalledTimes(1);
github ionic-team / ionic-cli / packages / @ionic / utils-subprocess / src / __tests__ / index.ts View on Github external
it('should error with combined output for output()', async done => {
      const cmd = new Subprocess('cmd', []);
      const mockSpawnStdout = new ReadableStreamBuffer();
      const mockSpawnStderr = new ReadableStreamBuffer();
      const cp = new class extends EventEmitter { stdout = mockSpawnStdout; stderr = mockSpawnStderr; };
      mockCrossSpawn.mockImplementation(() => cp);
      const p = cmd.output();
      const outletter = '1';
      const errletter = '2';
      const outinput = outletter.repeat(26);
      const errinput = errletter.repeat(26);
      mockSpawnStdout.feed(outinput);
      mockSpawnStdout.stop();
      mockSpawnStderr.feed(errinput);
      mockSpawnStderr.stop();
      await Promise.all([promisifyEvent(mockSpawnStdout, 'end'), promisifyEvent(mockSpawnStderr, 'end')]);
      cp.emit('close', 1);
      try {
        await p;
github ionic-team / ionic-cli / packages / @ionic / utils-subprocess / src / __tests__ / index.ts View on Github external
it('should error for signal exit', async () => {
      const cmd = new Subprocess('cmd', []);
      const mockSpawnStdout = new ReadableStreamBuffer();
      const mockSpawnStderr = new ReadableStreamBuffer();
      const cp = new class extends EventEmitter { stdout = mockSpawnStdout; stderr = mockSpawnStderr; };
      mockCrossSpawn.mockImplementation(() => cp);
      const buf = new WritableStreamBuffer();
      const promise = cmd.run();
      promise.p.stdout.pipe(buf);
      promise.p.stderr.pipe(buf);
      mockSpawnStdout.stop();
      mockSpawnStderr.stop();
      await promisifyEvent(buf, 'finish');
      cp.emit('close', null, 'SIGINT');
      await expect(promise).rejects.toThrow('Signal exit from subprocess.');
    });

@ionic/utils-stream

Stream utils for NodeJS

MIT
Latest version published 11 months ago

Package Health Score

75 / 100
Full package analysis

Similar packages