Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. 'use strict';
  2. function _jsdom() {
  3. const data = require('jsdom');
  4. _jsdom = function () {
  5. return data;
  6. };
  7. return data;
  8. }
  9. function _fakeTimers() {
  10. const data = require('@jest/fake-timers');
  11. _fakeTimers = function () {
  12. return data;
  13. };
  14. return data;
  15. }
  16. function _jestMock() {
  17. const data = require('jest-mock');
  18. _jestMock = function () {
  19. return data;
  20. };
  21. return data;
  22. }
  23. function _jestUtil() {
  24. const data = require('jest-util');
  25. _jestUtil = function () {
  26. return data;
  27. };
  28. return data;
  29. }
  30. function _defineProperty(obj, key, value) {
  31. if (key in obj) {
  32. Object.defineProperty(obj, key, {
  33. value: value,
  34. enumerable: true,
  35. configurable: true,
  36. writable: true
  37. });
  38. } else {
  39. obj[key] = value;
  40. }
  41. return obj;
  42. }
  43. class JSDOMEnvironment {
  44. constructor(config, options) {
  45. _defineProperty(this, 'dom', void 0);
  46. _defineProperty(this, 'fakeTimers', void 0);
  47. _defineProperty(this, 'fakeTimersModern', void 0);
  48. _defineProperty(this, 'global', void 0);
  49. _defineProperty(this, 'errorEventListener', void 0);
  50. _defineProperty(this, 'moduleMocker', void 0);
  51. this.dom = new (_jsdom().JSDOM)('<!DOCTYPE html>', {
  52. pretendToBeVisual: true,
  53. resources:
  54. typeof config.testEnvironmentOptions.userAgent === 'string'
  55. ? new (_jsdom().ResourceLoader)({
  56. userAgent: config.testEnvironmentOptions.userAgent
  57. })
  58. : undefined,
  59. runScripts: 'dangerously',
  60. url: config.testURL,
  61. virtualConsole: new (_jsdom().VirtualConsole)().sendTo(
  62. (options === null || options === void 0 ? void 0 : options.console) ||
  63. console
  64. ),
  65. ...config.testEnvironmentOptions
  66. });
  67. const global = (this.global = this.dom.window.document.defaultView);
  68. if (!global) {
  69. throw new Error('JSDOM did not return a Window object');
  70. } // for "universal" code (code should use `globalThis`)
  71. global.global = global; // Node's error-message stack size is limited at 10, but it's pretty useful
  72. // to see more than that when a test fails.
  73. this.global.Error.stackTraceLimit = 100;
  74. (0, _jestUtil().installCommonGlobals)(global, config.globals); // TODO: remove this ASAP, but it currently causes tests to run really slow
  75. global.Buffer = Buffer; // Report uncaught errors.
  76. this.errorEventListener = event => {
  77. if (userErrorListenerCount === 0 && event.error) {
  78. process.emit('uncaughtException', event.error);
  79. }
  80. };
  81. global.addEventListener('error', this.errorEventListener); // However, don't report them as uncaught if the user listens to 'error' event.
  82. // In that case, we assume the might have custom error handling logic.
  83. const originalAddListener = global.addEventListener;
  84. const originalRemoveListener = global.removeEventListener;
  85. let userErrorListenerCount = 0;
  86. global.addEventListener = function (...args) {
  87. if (args[0] === 'error') {
  88. userErrorListenerCount++;
  89. }
  90. return originalAddListener.apply(this, args);
  91. };
  92. global.removeEventListener = function (...args) {
  93. if (args[0] === 'error') {
  94. userErrorListenerCount--;
  95. }
  96. return originalRemoveListener.apply(this, args);
  97. };
  98. this.moduleMocker = new (_jestMock().ModuleMocker)(global);
  99. const timerConfig = {
  100. idToRef: id => id,
  101. refToId: ref => ref
  102. };
  103. this.fakeTimers = new (_fakeTimers().LegacyFakeTimers)({
  104. config,
  105. global: global,
  106. moduleMocker: this.moduleMocker,
  107. timerConfig
  108. });
  109. this.fakeTimersModern = new (_fakeTimers().ModernFakeTimers)({
  110. config,
  111. global: global
  112. });
  113. }
  114. async setup() {}
  115. async teardown() {
  116. if (this.fakeTimers) {
  117. this.fakeTimers.dispose();
  118. }
  119. if (this.fakeTimersModern) {
  120. this.fakeTimersModern.dispose();
  121. }
  122. if (this.global) {
  123. if (this.errorEventListener) {
  124. this.global.removeEventListener('error', this.errorEventListener);
  125. } // Dispose "document" to prevent "load" event from triggering.
  126. Object.defineProperty(this.global, 'document', {
  127. value: null
  128. });
  129. this.global.close();
  130. }
  131. this.errorEventListener = null; // @ts-expect-error
  132. this.global = null;
  133. this.dom = null;
  134. this.fakeTimers = null;
  135. this.fakeTimersModern = null;
  136. }
  137. getVmContext() {
  138. if (this.dom) {
  139. return this.dom.getInternalVMContext();
  140. }
  141. return null;
  142. }
  143. }
  144. module.exports = JSDOMEnvironment;