소스 검색

Stub TextEncoder in debugger tests similar to services

Jeremy Tuloup 4 년 전
부모
커밋
01e4a2a74e

+ 2 - 0
packages/debugger/package.json

@@ -79,6 +79,7 @@
     "@types/codemirror": "^0.0.97",
     "@types/jest": "^26.0.10",
     "@types/react-dom": "~16.9.8",
+    "@types/text-encoding": "^0.0.35",
     "canvas": "^2.6.1",
     "jest": "^26.4.2",
     "jest-junit": "^11.1.0",
@@ -86,6 +87,7 @@
     "jest-summary-reporter": "^0.0.2",
     "rimraf": "~3.0.0",
     "shell-quote": "^1.7.2",
+    "text-encoding": "^0.7.0",
     "ts-jest": "^26.3.0",
     "typedoc": "0.17.0-3",
     "typescript": "~4.0.2"

+ 4 - 0
packages/debugger/test/config.spec.ts

@@ -1,6 +1,10 @@
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
 
+import { init } from './utils';
+
+init();
+
 import { DebuggerConfig } from '../src/config';
 
 describe('DebuggerConfig', () => {

+ 4 - 0
packages/debugger/test/debugger.spec.ts

@@ -1,6 +1,10 @@
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
 
+import { init } from './utils';
+
+init();
+
 import { act } from 'react-dom/test-utils';
 
 import { CodeEditorWrapper } from '@jupyterlab/codeeditor';

+ 4 - 0
packages/debugger/test/service.spec.ts

@@ -1,6 +1,10 @@
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
 
+import { init } from './utils';
+
+init();
+
 import { Session, KernelSpecManager, KernelSpec } from '@jupyterlab/services';
 
 import {

+ 4 - 0
packages/debugger/test/session.spec.ts

@@ -1,6 +1,10 @@
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
 
+import { init } from './utils';
+
+init();
+
 import { Session } from '@jupyterlab/services';
 
 import {

+ 18 - 0
packages/debugger/test/utils.ts

@@ -1,6 +1,8 @@
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
 
+import encoding from 'text-encoding';
+
 // Utils from: https://github.com/jupyterlab/jupyterlab/blob/b1e2b83047421bf7196bec5f2a94d0616dcb2329/packages/services/test/utils.ts
 
 import { ServerConnection } from '@jupyterlab/services';
@@ -34,6 +36,22 @@ export const KERNELSPECS: JSONObject = {
   }
 };
 
+// stub for node global
+declare let global: any;
+
+/**
+ * This can be used by test modules that wouldn't otherwise import
+ * this file.
+ */
+export function init(): void {
+  if (typeof global !== 'undefined') {
+    global.TextEncoder = encoding.TextEncoder;
+  }
+}
+
+// Call init.
+init();
+
 /**
  * Create new server connection settings.
  *