diff --git a/.changeset/light-clocks-listen.md b/.changeset/light-clocks-listen.md new file mode 100644 index 0000000000..e3d841ad7d --- /dev/null +++ b/.changeset/light-clocks-listen.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-kubernetes': patch +--- + +Avoid eager use of `TextEncoder` in order not to break tests. diff --git a/plugins/kubernetes/src/components/PodExecTerminal/PodExecTerminal.test.tsx b/plugins/kubernetes/src/components/PodExecTerminal/PodExecTerminal.test.tsx index 1c913a7726..18e40bc241 100644 --- a/plugins/kubernetes/src/components/PodExecTerminal/PodExecTerminal.test.tsx +++ b/plugins/kubernetes/src/components/PodExecTerminal/PodExecTerminal.test.tsx @@ -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', () => { diff --git a/plugins/kubernetes/src/components/PodExecTerminal/PodExecTerminalAttachAddon.ts b/plugins/kubernetes/src/components/PodExecTerminal/PodExecTerminalAttachAddon.ts index fb80472f73..dba58a6746 100644 --- a/plugins/kubernetes/src/components/PodExecTerminal/PodExecTerminalAttachAddon.ts +++ b/plugins/kubernetes/src/components/PodExecTerminal/PodExecTerminalAttachAddon.ts @@ -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); }; diff --git a/plugins/kubernetes/src/setupTests.ts b/plugins/kubernetes/src/setupTests.ts index a373310a1a..963c0f188b 100644 --- a/plugins/kubernetes/src/setupTests.ts +++ b/plugins/kubernetes/src/setupTests.ts @@ -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, -});