kubernetes: more lazy use of TextEncoder
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-kubernetes': patch
|
||||
---
|
||||
|
||||
Avoid eager use of `TextEncoder` in order not to break tests.
|
||||
@@ -27,6 +27,8 @@ import React from 'react';
|
||||
import './matchMedia.mock';
|
||||
import { PodExecTerminal } from './PodExecTerminal';
|
||||
|
||||
global.TextEncoder = require('util').TextEncoder;
|
||||
|
||||
const textEncoder = new TextEncoder();
|
||||
|
||||
describe('PodExecTerminal', () => {
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
*/
|
||||
import { AttachAddon, IAttachOptions } from 'xterm-addon-attach';
|
||||
|
||||
const textEncoder = new TextEncoder();
|
||||
|
||||
export class PodExecTerminalAttachAddon extends AttachAddon {
|
||||
#textEncoder = new TextEncoder();
|
||||
|
||||
constructor(socket: WebSocket, options?: IAttachOptions) {
|
||||
super(socket, options);
|
||||
|
||||
@@ -30,7 +30,7 @@ export class PodExecTerminalAttachAddon extends AttachAddon {
|
||||
return;
|
||||
}
|
||||
|
||||
const buffer = Uint8Array.from([0, ...textEncoder.encode(data)]);
|
||||
const buffer = Uint8Array.from([0, ...this.#textEncoder.encode(data)]);
|
||||
|
||||
thisAddon._socket.send(buffer);
|
||||
};
|
||||
|
||||
@@ -13,15 +13,5 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import '@testing-library/jest-dom';
|
||||
// eslint-disable-next-line no-restricted-imports
|
||||
import { TextDecoder, TextEncoder } from 'util';
|
||||
|
||||
// These are missing from jest-node, so not available on global.
|
||||
Object.defineProperty(global, 'TextEncoder', {
|
||||
value: TextEncoder,
|
||||
});
|
||||
|
||||
Object.defineProperty(global, 'TextDecoder', {
|
||||
value: TextDecoder,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user