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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.separateMessageFromStack =
  6. exports.formatResultsErrors =
  7. exports.formatStackTrace =
  8. exports.getTopFrame =
  9. exports.getStackTraceLines =
  10. exports.formatExecError =
  11. void 0;
  12. var path = _interopRequireWildcard(require('path'));
  13. var _codeFrame = require('@babel/code-frame');
  14. var _chalk = _interopRequireDefault(require('chalk'));
  15. var fs = _interopRequireWildcard(require('graceful-fs'));
  16. var _micromatch = _interopRequireDefault(require('micromatch'));
  17. var _slash = _interopRequireDefault(require('slash'));
  18. var _stackUtils = _interopRequireDefault(require('stack-utils'));
  19. var _prettyFormat = require('pretty-format');
  20. function _interopRequireDefault(obj) {
  21. return obj && obj.__esModule ? obj : {default: obj};
  22. }
  23. function _getRequireWildcardCache(nodeInterop) {
  24. if (typeof WeakMap !== 'function') return null;
  25. var cacheBabelInterop = new WeakMap();
  26. var cacheNodeInterop = new WeakMap();
  27. return (_getRequireWildcardCache = function (nodeInterop) {
  28. return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
  29. })(nodeInterop);
  30. }
  31. function _interopRequireWildcard(obj, nodeInterop) {
  32. if (!nodeInterop && obj && obj.__esModule) {
  33. return obj;
  34. }
  35. if (obj === null || (typeof obj !== 'object' && typeof obj !== 'function')) {
  36. return {default: obj};
  37. }
  38. var cache = _getRequireWildcardCache(nodeInterop);
  39. if (cache && cache.has(obj)) {
  40. return cache.get(obj);
  41. }
  42. var newObj = {};
  43. var hasPropertyDescriptor =
  44. Object.defineProperty && Object.getOwnPropertyDescriptor;
  45. for (var key in obj) {
  46. if (key !== 'default' && Object.prototype.hasOwnProperty.call(obj, key)) {
  47. var desc = hasPropertyDescriptor
  48. ? Object.getOwnPropertyDescriptor(obj, key)
  49. : null;
  50. if (desc && (desc.get || desc.set)) {
  51. Object.defineProperty(newObj, key, desc);
  52. } else {
  53. newObj[key] = obj[key];
  54. }
  55. }
  56. }
  57. newObj.default = obj;
  58. if (cache) {
  59. cache.set(obj, newObj);
  60. }
  61. return newObj;
  62. }
  63. var global = (function () {
  64. if (typeof globalThis !== 'undefined') {
  65. return globalThis;
  66. } else if (typeof global !== 'undefined') {
  67. return global;
  68. } else if (typeof self !== 'undefined') {
  69. return self;
  70. } else if (typeof window !== 'undefined') {
  71. return window;
  72. } else {
  73. return Function('return this')();
  74. }
  75. })();
  76. var Symbol = global['jest-symbol-do-not-touch'] || global.Symbol;
  77. var global = (function () {
  78. if (typeof globalThis !== 'undefined') {
  79. return globalThis;
  80. } else if (typeof global !== 'undefined') {
  81. return global;
  82. } else if (typeof self !== 'undefined') {
  83. return self;
  84. } else if (typeof window !== 'undefined') {
  85. return window;
  86. } else {
  87. return Function('return this')();
  88. }
  89. })();
  90. var Symbol = global['jest-symbol-do-not-touch'] || global.Symbol;
  91. var global = (function () {
  92. if (typeof globalThis !== 'undefined') {
  93. return globalThis;
  94. } else if (typeof global !== 'undefined') {
  95. return global;
  96. } else if (typeof self !== 'undefined') {
  97. return self;
  98. } else if (typeof window !== 'undefined') {
  99. return window;
  100. } else {
  101. return Function('return this')();
  102. }
  103. })();
  104. var jestReadFile =
  105. global[Symbol.for('jest-native-read-file')] || fs.readFileSync;
  106. // stack utils tries to create pretty stack by making paths relative.
  107. const stackUtils = new _stackUtils.default({
  108. cwd: 'something which does not exist'
  109. });
  110. let nodeInternals = [];
  111. try {
  112. nodeInternals = _stackUtils.default.nodeInternals();
  113. } catch {
  114. // `StackUtils.nodeInternals()` fails in browsers. We don't need to remove
  115. // node internals in the browser though, so no issue.
  116. }
  117. const PATH_NODE_MODULES = `${path.sep}node_modules${path.sep}`;
  118. const PATH_JEST_PACKAGES = `${path.sep}jest${path.sep}packages${path.sep}`; // filter for noisy stack trace lines
  119. const JASMINE_IGNORE =
  120. /^\s+at(?:(?:.jasmine\-)|\s+jasmine\.buildExpectationResult)/;
  121. const JEST_INTERNALS_IGNORE =
  122. /^\s+at.*?jest(-.*?)?(\/|\\)(build|node_modules|packages)(\/|\\)/;
  123. const ANONYMOUS_FN_IGNORE = /^\s+at <anonymous>.*$/;
  124. const ANONYMOUS_PROMISE_IGNORE = /^\s+at (new )?Promise \(<anonymous>\).*$/;
  125. const ANONYMOUS_GENERATOR_IGNORE = /^\s+at Generator.next \(<anonymous>\).*$/;
  126. const NATIVE_NEXT_IGNORE = /^\s+at next \(native\).*$/;
  127. const TITLE_INDENT = ' ';
  128. const MESSAGE_INDENT = ' ';
  129. const STACK_INDENT = ' ';
  130. const ANCESTRY_SEPARATOR = ' \u203A ';
  131. const TITLE_BULLET = _chalk.default.bold('\u25cf ');
  132. const STACK_TRACE_COLOR = _chalk.default.dim;
  133. const STACK_PATH_REGEXP = /\s*at.*\(?(\:\d*\:\d*|native)\)?/;
  134. const EXEC_ERROR_MESSAGE = 'Test suite failed to run';
  135. const NOT_EMPTY_LINE_REGEXP = /^(?!$)/gm;
  136. const indentAllLines = (lines, indent) =>
  137. lines.replace(NOT_EMPTY_LINE_REGEXP, indent);
  138. const trim = string => (string || '').trim(); // Some errors contain not only line numbers in stack traces
  139. // e.g. SyntaxErrors can contain snippets of code, and we don't
  140. // want to trim those, because they may have pointers to the column/character
  141. // which will get misaligned.
  142. const trimPaths = string =>
  143. string.match(STACK_PATH_REGEXP) ? trim(string) : string;
  144. const getRenderedCallsite = (fileContent, line, column) => {
  145. let renderedCallsite = (0, _codeFrame.codeFrameColumns)(
  146. fileContent,
  147. {
  148. start: {
  149. column,
  150. line
  151. }
  152. },
  153. {
  154. highlightCode: true
  155. }
  156. );
  157. renderedCallsite = indentAllLines(renderedCallsite, MESSAGE_INDENT);
  158. renderedCallsite = `\n${renderedCallsite}\n`;
  159. return renderedCallsite;
  160. };
  161. const blankStringRegexp = /^\s*$/;
  162. function checkForCommonEnvironmentErrors(error) {
  163. if (
  164. error.includes('ReferenceError: document is not defined') ||
  165. error.includes('ReferenceError: window is not defined') ||
  166. error.includes('ReferenceError: navigator is not defined')
  167. ) {
  168. return warnAboutWrongTestEnvironment(error, 'jsdom');
  169. } else if (error.includes('.unref is not a function')) {
  170. return warnAboutWrongTestEnvironment(error, 'node');
  171. }
  172. return error;
  173. }
  174. function warnAboutWrongTestEnvironment(error, env) {
  175. return (
  176. _chalk.default.bold.red(
  177. `The error below may be caused by using the wrong test environment, see ${_chalk.default.dim.underline(
  178. 'https://jestjs.io/docs/configuration#testenvironment-string'
  179. )}.\nConsider using the "${env}" test environment.\n\n`
  180. ) + error
  181. );
  182. } // ExecError is an error thrown outside of the test suite (not inside an `it` or
  183. // `before/after each` hooks). If it's thrown, none of the tests in the file
  184. // are executed.
  185. const formatExecError = (error, config, options, testPath, reuseMessage) => {
  186. if (!error || typeof error === 'number') {
  187. error = new Error(`Expected an Error, but "${String(error)}" was thrown`);
  188. error.stack = '';
  189. }
  190. let message, stack;
  191. if (typeof error === 'string' || !error) {
  192. error || (error = 'EMPTY ERROR');
  193. message = '';
  194. stack = error;
  195. } else {
  196. message = error.message;
  197. stack =
  198. typeof error.stack === 'string'
  199. ? error.stack
  200. : `thrown: ${(0, _prettyFormat.format)(error, {
  201. maxDepth: 3
  202. })}`;
  203. }
  204. const separated = separateMessageFromStack(stack || '');
  205. stack = separated.stack;
  206. if (separated.message.includes(trim(message))) {
  207. // Often stack trace already contains the duplicate of the message
  208. message = separated.message;
  209. }
  210. message = checkForCommonEnvironmentErrors(message);
  211. message = indentAllLines(message, MESSAGE_INDENT);
  212. stack =
  213. stack && !options.noStackTrace
  214. ? '\n' + formatStackTrace(stack, config, options, testPath)
  215. : '';
  216. if (
  217. typeof stack !== 'string' ||
  218. (blankStringRegexp.test(message) && blankStringRegexp.test(stack))
  219. ) {
  220. // this can happen if an empty object is thrown.
  221. message = `thrown: ${(0, _prettyFormat.format)(error, {
  222. maxDepth: 3
  223. })}`;
  224. }
  225. let messageToUse;
  226. if (reuseMessage) {
  227. messageToUse = ` ${message.trim()}`;
  228. } else {
  229. messageToUse = `${EXEC_ERROR_MESSAGE}\n\n${message}`;
  230. }
  231. return TITLE_INDENT + TITLE_BULLET + messageToUse + stack + '\n';
  232. };
  233. exports.formatExecError = formatExecError;
  234. const removeInternalStackEntries = (lines, options) => {
  235. let pathCounter = 0;
  236. return lines.filter(line => {
  237. if (ANONYMOUS_FN_IGNORE.test(line)) {
  238. return false;
  239. }
  240. if (ANONYMOUS_PROMISE_IGNORE.test(line)) {
  241. return false;
  242. }
  243. if (ANONYMOUS_GENERATOR_IGNORE.test(line)) {
  244. return false;
  245. }
  246. if (NATIVE_NEXT_IGNORE.test(line)) {
  247. return false;
  248. }
  249. if (nodeInternals.some(internal => internal.test(line))) {
  250. return false;
  251. }
  252. if (!STACK_PATH_REGEXP.test(line)) {
  253. return true;
  254. }
  255. if (JASMINE_IGNORE.test(line)) {
  256. return false;
  257. }
  258. if (++pathCounter === 1) {
  259. return true; // always keep the first line even if it's from Jest
  260. }
  261. if (options.noStackTrace) {
  262. return false;
  263. }
  264. if (JEST_INTERNALS_IGNORE.test(line)) {
  265. return false;
  266. }
  267. return true;
  268. });
  269. };
  270. const formatPaths = (config, relativeTestPath, line) => {
  271. // Extract the file path from the trace line.
  272. const match = line.match(/(^\s*at .*?\(?)([^()]+)(:[0-9]+:[0-9]+\)?.*$)/);
  273. if (!match) {
  274. return line;
  275. }
  276. let filePath = (0, _slash.default)(path.relative(config.rootDir, match[2])); // highlight paths from the current test file
  277. if (
  278. (config.testMatch &&
  279. config.testMatch.length &&
  280. (0, _micromatch.default)([filePath], config.testMatch).length > 0) ||
  281. filePath === relativeTestPath
  282. ) {
  283. filePath = _chalk.default.reset.cyan(filePath);
  284. }
  285. return STACK_TRACE_COLOR(match[1]) + filePath + STACK_TRACE_COLOR(match[3]);
  286. };
  287. const getStackTraceLines = (
  288. stack,
  289. options = {
  290. noCodeFrame: false,
  291. noStackTrace: false
  292. }
  293. ) => removeInternalStackEntries(stack.split(/\n/), options);
  294. exports.getStackTraceLines = getStackTraceLines;
  295. const getTopFrame = lines => {
  296. for (const line of lines) {
  297. if (line.includes(PATH_NODE_MODULES) || line.includes(PATH_JEST_PACKAGES)) {
  298. continue;
  299. }
  300. const parsedFrame = stackUtils.parseLine(line.trim());
  301. if (parsedFrame && parsedFrame.file) {
  302. return parsedFrame;
  303. }
  304. }
  305. return null;
  306. };
  307. exports.getTopFrame = getTopFrame;
  308. const formatStackTrace = (stack, config, options, testPath) => {
  309. const lines = getStackTraceLines(stack, options);
  310. let renderedCallsite = '';
  311. const relativeTestPath = testPath
  312. ? (0, _slash.default)(path.relative(config.rootDir, testPath))
  313. : null;
  314. if (!options.noStackTrace && !options.noCodeFrame) {
  315. const topFrame = getTopFrame(lines);
  316. if (topFrame) {
  317. const {column, file: filename, line} = topFrame;
  318. if (line && filename && path.isAbsolute(filename)) {
  319. let fileContent;
  320. try {
  321. // TODO: check & read HasteFS instead of reading the filesystem:
  322. // see: https://github.com/facebook/jest/pull/5405#discussion_r164281696
  323. fileContent = jestReadFile(filename, 'utf8');
  324. renderedCallsite = getRenderedCallsite(fileContent, line, column);
  325. } catch {
  326. // the file does not exist or is inaccessible, we ignore
  327. }
  328. }
  329. }
  330. }
  331. const stacktrace = lines
  332. .filter(Boolean)
  333. .map(
  334. line =>
  335. STACK_INDENT + formatPaths(config, relativeTestPath, trimPaths(line))
  336. )
  337. .join('\n');
  338. return renderedCallsite
  339. ? `${renderedCallsite}\n${stacktrace}`
  340. : `\n${stacktrace}`;
  341. };
  342. exports.formatStackTrace = formatStackTrace;
  343. const formatResultsErrors = (testResults, config, options, testPath) => {
  344. const failedResults = testResults.reduce((errors, result) => {
  345. result.failureMessages.forEach(item => {
  346. errors.push({
  347. content: checkForCommonEnvironmentErrors(item),
  348. result
  349. });
  350. });
  351. return errors;
  352. }, []);
  353. if (!failedResults.length) {
  354. return null;
  355. }
  356. return failedResults
  357. .map(({result, content}) => {
  358. let {message, stack} = separateMessageFromStack(content);
  359. stack = options.noStackTrace
  360. ? ''
  361. : STACK_TRACE_COLOR(
  362. formatStackTrace(stack, config, options, testPath)
  363. ) + '\n';
  364. message = indentAllLines(message, MESSAGE_INDENT);
  365. const title =
  366. _chalk.default.bold.red(
  367. TITLE_INDENT +
  368. TITLE_BULLET +
  369. result.ancestorTitles.join(ANCESTRY_SEPARATOR) +
  370. (result.ancestorTitles.length ? ANCESTRY_SEPARATOR : '') +
  371. result.title
  372. ) + '\n';
  373. return title + '\n' + message + '\n' + stack;
  374. })
  375. .join('\n');
  376. };
  377. exports.formatResultsErrors = formatResultsErrors;
  378. const errorRegexp = /^Error:?\s*$/;
  379. const removeBlankErrorLine = str =>
  380. str
  381. .split('\n') // Lines saying just `Error:` are useless
  382. .filter(line => !errorRegexp.test(line))
  383. .join('\n')
  384. .trimRight(); // jasmine and worker farm sometimes don't give us access to the actual
  385. // Error object, so we have to regexp out the message from the stack string
  386. // to format it.
  387. const separateMessageFromStack = content => {
  388. if (!content) {
  389. return {
  390. message: '',
  391. stack: ''
  392. };
  393. } // All lines up to what looks like a stack -- or if nothing looks like a stack
  394. // (maybe it's a code frame instead), just the first non-empty line.
  395. // If the error is a plain "Error:" instead of a SyntaxError or TypeError we
  396. // remove the prefix from the message because it is generally not useful.
  397. const messageMatch = content.match(
  398. /^(?:Error: )?([\s\S]*?(?=\n\s*at\s.*:\d*:\d*)|\s*.*)([\s\S]*)$/
  399. );
  400. if (!messageMatch) {
  401. // For typescript
  402. throw new Error('If you hit this error, the regex above is buggy.');
  403. }
  404. const message = removeBlankErrorLine(messageMatch[1]);
  405. const stack = removeBlankErrorLine(messageMatch[2]);
  406. return {
  407. message,
  408. stack
  409. };
  410. };
  411. exports.separateMessageFromStack = separateMessageFromStack;