-
Notifications
You must be signed in to change notification settings - Fork 266
Description
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']);.