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.

run.js 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _state = require('./state');
  7. var _types = require('./types');
  8. var _utils = require('./utils');
  9. /**
  10. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  11. *
  12. * This source code is licensed under the MIT license found in the
  13. * LICENSE file in the root directory of this source tree.
  14. */
  15. const run = async () => {
  16. const {rootDescribeBlock} = (0, _state.getState)();
  17. await (0, _state.dispatch)({
  18. name: 'run_start'
  19. });
  20. await _runTestsForDescribeBlock(rootDescribeBlock);
  21. await (0, _state.dispatch)({
  22. name: 'run_finish'
  23. });
  24. return (0, _utils.makeRunResult)(
  25. (0, _state.getState)().rootDescribeBlock,
  26. (0, _state.getState)().unhandledErrors
  27. );
  28. };
  29. const _runTestsForDescribeBlock = async describeBlock => {
  30. await (0, _state.dispatch)({
  31. describeBlock,
  32. name: 'run_describe_start'
  33. });
  34. const {beforeAll, afterAll} = (0, _utils.getAllHooksForDescribe)(
  35. describeBlock
  36. );
  37. const isSkipped = describeBlock.mode === 'skip';
  38. if (!isSkipped) {
  39. for (const hook of beforeAll) {
  40. await _callCircusHook({
  41. describeBlock,
  42. hook
  43. });
  44. }
  45. } // Tests that fail and are retried we run after other tests
  46. const retryTimes = parseInt(global[_types.RETRY_TIMES], 10) || 0;
  47. const deferredRetryTests = [];
  48. for (const child of describeBlock.children) {
  49. switch (child.type) {
  50. case 'describeBlock': {
  51. await _runTestsForDescribeBlock(child);
  52. break;
  53. }
  54. case 'test': {
  55. const hasErrorsBeforeTestRun = child.errors.length > 0;
  56. await _runTest(child, isSkipped);
  57. if (
  58. hasErrorsBeforeTestRun === false &&
  59. retryTimes > 0 &&
  60. child.errors.length > 0
  61. ) {
  62. deferredRetryTests.push(child);
  63. }
  64. break;
  65. }
  66. }
  67. } // Re-run failed tests n-times if configured
  68. for (const test of deferredRetryTests) {
  69. let numRetriesAvailable = retryTimes;
  70. while (numRetriesAvailable > 0 && test.errors.length > 0) {
  71. // Clear errors so retries occur
  72. await (0, _state.dispatch)({
  73. name: 'test_retry',
  74. test
  75. });
  76. await _runTest(test, isSkipped);
  77. numRetriesAvailable--;
  78. }
  79. }
  80. if (!isSkipped) {
  81. for (const hook of afterAll) {
  82. await _callCircusHook({
  83. describeBlock,
  84. hook
  85. });
  86. }
  87. }
  88. await (0, _state.dispatch)({
  89. describeBlock,
  90. name: 'run_describe_finish'
  91. });
  92. };
  93. const _runTest = async (test, parentSkipped) => {
  94. await (0, _state.dispatch)({
  95. name: 'test_start',
  96. test
  97. });
  98. const testContext = Object.create(null);
  99. const {hasFocusedTests, testNamePattern} = (0, _state.getState)();
  100. const isSkipped =
  101. parentSkipped ||
  102. test.mode === 'skip' ||
  103. (hasFocusedTests && test.mode !== 'only') ||
  104. (testNamePattern && !testNamePattern.test((0, _utils.getTestID)(test)));
  105. if (isSkipped) {
  106. await (0, _state.dispatch)({
  107. name: 'test_skip',
  108. test
  109. });
  110. return;
  111. }
  112. if (test.mode === 'todo') {
  113. await (0, _state.dispatch)({
  114. name: 'test_todo',
  115. test
  116. });
  117. return;
  118. }
  119. const {afterEach, beforeEach} = (0, _utils.getEachHooksForTest)(test);
  120. for (const hook of beforeEach) {
  121. if (test.errors.length) {
  122. // If any of the before hooks failed already, we don't run any
  123. // hooks after that.
  124. break;
  125. }
  126. await _callCircusHook({
  127. hook,
  128. test,
  129. testContext
  130. });
  131. }
  132. await _callCircusTest(test, testContext);
  133. for (const hook of afterEach) {
  134. await _callCircusHook({
  135. hook,
  136. test,
  137. testContext
  138. });
  139. } // `afterAll` hooks should not affect test status (pass or fail), because if
  140. // we had a global `afterAll` hook it would block all existing tests until
  141. // this hook is executed. So we dispatch `test_done` right away.
  142. await (0, _state.dispatch)({
  143. name: 'test_done',
  144. test
  145. });
  146. };
  147. const _callCircusHook = async ({hook, test, describeBlock, testContext}) => {
  148. await (0, _state.dispatch)({
  149. hook,
  150. name: 'hook_start'
  151. });
  152. const timeout = hook.timeout || (0, _state.getState)().testTimeout;
  153. try {
  154. await (0, _utils.callAsyncCircusFn)(hook, testContext, {
  155. isHook: true,
  156. timeout
  157. });
  158. await (0, _state.dispatch)({
  159. describeBlock,
  160. hook,
  161. name: 'hook_success',
  162. test
  163. });
  164. } catch (error) {
  165. await (0, _state.dispatch)({
  166. describeBlock,
  167. error,
  168. hook,
  169. name: 'hook_failure',
  170. test
  171. });
  172. }
  173. };
  174. const _callCircusTest = async (test, testContext) => {
  175. await (0, _state.dispatch)({
  176. name: 'test_fn_start',
  177. test
  178. });
  179. const timeout = test.timeout || (0, _state.getState)().testTimeout;
  180. (0, _utils.invariant)(
  181. test.fn,
  182. `Tests with no 'fn' should have 'mode' set to 'skipped'`
  183. );
  184. if (test.errors.length) {
  185. return; // We don't run the test if there's already an error in before hooks.
  186. }
  187. try {
  188. await (0, _utils.callAsyncCircusFn)(test, testContext, {
  189. isHook: false,
  190. timeout
  191. });
  192. await (0, _state.dispatch)({
  193. name: 'test_fn_success',
  194. test
  195. });
  196. } catch (error) {
  197. await (0, _state.dispatch)({
  198. error,
  199. name: 'test_fn_failure',
  200. test
  201. });
  202. }
  203. };
  204. var _default = run;
  205. exports.default = _default;