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.

jestAdapterInit.js 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.runAndTransformResultsToJestFormat = exports.initialize = void 0;
  6. var _throat = _interopRequireDefault(require('throat'));
  7. var _testResult = require('@jest/test-result');
  8. var _expect = require('expect');
  9. var _jestEach = require('jest-each');
  10. var _jestMessageUtil = require('jest-message-util');
  11. var _jestSnapshot = require('jest-snapshot');
  12. var _ = _interopRequireDefault(require('..'));
  13. var _run = _interopRequireDefault(require('../run'));
  14. var _state = require('../state');
  15. var _testCaseReportHandler = _interopRequireDefault(
  16. require('../testCaseReportHandler')
  17. );
  18. var _utils = require('../utils');
  19. var _jestExpect = _interopRequireDefault(require('./jestExpect'));
  20. function _interopRequireDefault(obj) {
  21. return obj && obj.__esModule ? obj : {default: obj};
  22. }
  23. /**
  24. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  25. *
  26. * This source code is licensed under the MIT license found in the
  27. * LICENSE file in the root directory of this source tree.
  28. */
  29. const initialize = async ({
  30. config,
  31. environment,
  32. globalConfig,
  33. localRequire,
  34. parentProcess,
  35. sendMessageToJest,
  36. setGlobalsForRuntime,
  37. testPath
  38. }) => {
  39. if (globalConfig.testTimeout) {
  40. (0, _state.getState)().testTimeout = globalConfig.testTimeout;
  41. }
  42. const mutex = (0, _throat.default)(globalConfig.maxConcurrency); // @ts-expect-error
  43. const globalsObject = {
  44. ..._.default,
  45. fdescribe: _.default.describe.only,
  46. fit: _.default.it.only,
  47. xdescribe: _.default.describe.skip,
  48. xit: _.default.it.skip,
  49. xtest: _.default.it.skip
  50. };
  51. globalsObject.test.concurrent = (test => {
  52. const concurrent = (testName, testFn, timeout) => {
  53. // For concurrent tests we first run the function that returns promise, and then register a
  54. // normal test that will be waiting on the returned promise (when we start the test, the promise
  55. // will already be in the process of execution).
  56. // Unfortunately at this stage there's no way to know if there are any `.only` tests in the suite
  57. // that will result in this test to be skipped, so we'll be executing the promise function anyway,
  58. // even if it ends up being skipped.
  59. const promise = mutex(() => testFn());
  60. globalsObject.test(testName, () => promise, timeout);
  61. };
  62. const only = (testName, testFn, timeout) => {
  63. const promise = mutex(() => testFn()); // eslint-disable-next-line jest/no-focused-tests
  64. test.only(testName, () => promise, timeout);
  65. };
  66. concurrent.only = only;
  67. concurrent.skip = test.skip;
  68. concurrent.each = (0, _jestEach.bind)(test, false);
  69. concurrent.skip.each = (0, _jestEach.bind)(test.skip, false);
  70. only.each = (0, _jestEach.bind)(test.only, false);
  71. return concurrent;
  72. })(globalsObject.test);
  73. (0, _state.addEventHandler)(eventHandler);
  74. if (environment.handleTestEvent) {
  75. (0, _state.addEventHandler)(environment.handleTestEvent.bind(environment));
  76. }
  77. const runtimeGlobals = {
  78. ...globalsObject,
  79. expect: (0, _jestExpect.default)(globalConfig)
  80. };
  81. setGlobalsForRuntime(runtimeGlobals);
  82. if (config.injectGlobals) {
  83. Object.assign(environment.global, runtimeGlobals);
  84. }
  85. await (0, _state.dispatch)({
  86. name: 'setup',
  87. parentProcess,
  88. runtimeGlobals,
  89. testNamePattern: globalConfig.testNamePattern
  90. });
  91. if (config.testLocationInResults) {
  92. await (0, _state.dispatch)({
  93. name: 'include_test_location_in_result'
  94. });
  95. } // Jest tests snapshotSerializers in order preceding built-in serializers.
  96. // Therefore, add in reverse because the last added is the first tested.
  97. config.snapshotSerializers
  98. .concat()
  99. .reverse()
  100. .forEach(path => (0, _jestSnapshot.addSerializer)(localRequire(path)));
  101. const {expand, updateSnapshot} = globalConfig;
  102. const snapshotResolver = await (0, _jestSnapshot.buildSnapshotResolver)(
  103. config,
  104. localRequire
  105. );
  106. const snapshotPath = snapshotResolver.resolveSnapshotPath(testPath);
  107. const snapshotState = new _jestSnapshot.SnapshotState(snapshotPath, {
  108. expand,
  109. prettierPath: config.prettierPath,
  110. snapshotFormat: config.snapshotFormat,
  111. updateSnapshot
  112. }); // @ts-expect-error: snapshotState is a jest extension of `expect`
  113. (0, _expect.setState)({
  114. snapshotState,
  115. testPath
  116. });
  117. (0, _state.addEventHandler)(handleSnapshotStateAfterRetry(snapshotState));
  118. if (sendMessageToJest) {
  119. (0, _state.addEventHandler)(
  120. (0, _testCaseReportHandler.default)(testPath, sendMessageToJest)
  121. );
  122. } // Return it back to the outer scope (test runner outside the VM).
  123. return {
  124. globals: globalsObject,
  125. snapshotState
  126. };
  127. };
  128. exports.initialize = initialize;
  129. const runAndTransformResultsToJestFormat = async ({
  130. config,
  131. globalConfig,
  132. testPath
  133. }) => {
  134. const runResult = await (0, _run.default)();
  135. let numFailingTests = 0;
  136. let numPassingTests = 0;
  137. let numPendingTests = 0;
  138. let numTodoTests = 0;
  139. const assertionResults = runResult.testResults.map(testResult => {
  140. let status;
  141. if (testResult.status === 'skip') {
  142. status = 'pending';
  143. numPendingTests += 1;
  144. } else if (testResult.status === 'todo') {
  145. status = 'todo';
  146. numTodoTests += 1;
  147. } else if (testResult.errors.length) {
  148. status = 'failed';
  149. numFailingTests += 1;
  150. } else {
  151. status = 'passed';
  152. numPassingTests += 1;
  153. }
  154. const ancestorTitles = testResult.testPath.filter(
  155. name => name !== _state.ROOT_DESCRIBE_BLOCK_NAME
  156. );
  157. const title = ancestorTitles.pop();
  158. return {
  159. ancestorTitles,
  160. duration: testResult.duration,
  161. failureDetails: testResult.errorsDetailed,
  162. failureMessages: testResult.errors,
  163. fullName: title
  164. ? ancestorTitles.concat(title).join(' ')
  165. : ancestorTitles.join(' '),
  166. invocations: testResult.invocations,
  167. location: testResult.location,
  168. numPassingAsserts: 0,
  169. status,
  170. title: testResult.testPath[testResult.testPath.length - 1]
  171. };
  172. });
  173. let failureMessage = (0, _jestMessageUtil.formatResultsErrors)(
  174. assertionResults,
  175. config,
  176. globalConfig,
  177. testPath
  178. );
  179. let testExecError;
  180. if (runResult.unhandledErrors.length) {
  181. testExecError = {
  182. message: '',
  183. stack: runResult.unhandledErrors.join('\n')
  184. };
  185. failureMessage =
  186. (failureMessage || '') +
  187. '\n\n' +
  188. runResult.unhandledErrors
  189. .map(err =>
  190. (0, _jestMessageUtil.formatExecError)(err, config, globalConfig)
  191. )
  192. .join('\n');
  193. }
  194. await (0, _state.dispatch)({
  195. name: 'teardown'
  196. });
  197. return {
  198. ...(0, _testResult.createEmptyTestResult)(),
  199. console: undefined,
  200. displayName: config.displayName,
  201. failureMessage,
  202. numFailingTests,
  203. numPassingTests,
  204. numPendingTests,
  205. numTodoTests,
  206. testExecError,
  207. testFilePath: testPath,
  208. testResults: assertionResults
  209. };
  210. };
  211. exports.runAndTransformResultsToJestFormat = runAndTransformResultsToJestFormat;
  212. const handleSnapshotStateAfterRetry = snapshotState => event => {
  213. switch (event.name) {
  214. case 'test_retry': {
  215. // Clear any snapshot data that occurred in previous test run
  216. snapshotState.clear();
  217. }
  218. }
  219. };
  220. const eventHandler = async event => {
  221. switch (event.name) {
  222. case 'test_start': {
  223. (0, _expect.setState)({
  224. currentTestName: (0, _utils.getTestID)(event.test)
  225. });
  226. break;
  227. }
  228. case 'test_done': {
  229. _addSuppressedErrors(event.test);
  230. _addExpectedAssertionErrors(event.test);
  231. break;
  232. }
  233. }
  234. };
  235. const _addExpectedAssertionErrors = test => {
  236. const failures = (0, _expect.extractExpectedAssertionsErrors)();
  237. const errors = failures.map(failure => failure.error);
  238. test.errors = test.errors.concat(errors);
  239. }; // Get suppressed errors from ``jest-matchers`` that weren't throw during
  240. // test execution and add them to the test result, potentially failing
  241. // a passing test.
  242. const _addSuppressedErrors = test => {
  243. const {suppressedErrors} = (0, _expect.getState)();
  244. (0, _expect.setState)({
  245. suppressedErrors: []
  246. });
  247. if (suppressedErrors.length) {
  248. test.errors = test.errors.concat(suppressedErrors);
  249. }
  250. };