Skip to content

Changing the wrapper to show real-time output #395

@dannystaple

Description

@dannystaple

Context

For lengthy apply's, the wrapper will mean that no output is shown until the end.
This is due to the code https://github.com/hashicorp/setup-terraform/blob/main/wrapper/terraform.js using a listener, which looks like it buffers up everything, and then prints it to the console at https://github.com/hashicorp/setup-terraform/blob/main/wrapper/terraform.js#L42.

Potential fix

What would work here, would be to update the listener https://github.com/hashicorp/setup-terraform/blob/main/wrapper/lib/output-listener.js#L28 so the constructor takes an output stream as an argument, like process.stdout, and when making the call this._buff.push(data);, also perform something like this.stream.write(data);, potentially with a this.stream.flush();.

Ie:

  get listener () {
    const listen = function listen (data) {
      this._buff.push(data);
      if (this.stream) {
        this.stream.write(data);
        this.stream.flush();
      }
    };
    return listen.bind(this);
  }

The effect

This will then ensure that every chunk of data gets sent on to the appropriate stream, while also buffering, similar to the tee command.

Testing

Unit tests could be sorted by perhaps using a mock, looking for the stream calls when applied. Something like expect(listener.contents).toHaveCalls(['foo', 'bar', 'baz']);.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions