kubernetes: more lazy use of TextEncoder

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-09-14 19:11:25 +02:00
parent 5c0098ea31
commit 6ddeade58b
4 changed files with 11 additions and 14 deletions
+5
View File
@@ -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);
};
+1 -11
View File
@@ -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,
});