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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = _default;
  6. var _assert = require('assert');
  7. var _jestUtil = require('jest-util');
  8. var _assertionErrorMessage = _interopRequireDefault(
  9. require('../assertionErrorMessage')
  10. );
  11. var _isError = _interopRequireDefault(require('../isError'));
  12. var _queueRunner = _interopRequireDefault(require('../queueRunner'));
  13. var _treeProcessor = _interopRequireDefault(require('../treeProcessor'));
  14. function _interopRequireDefault(obj) {
  15. return obj && obj.__esModule ? obj : {default: obj};
  16. }
  17. function _defineProperty(obj, key, value) {
  18. if (key in obj) {
  19. Object.defineProperty(obj, key, {
  20. value: value,
  21. enumerable: true,
  22. configurable: true,
  23. writable: true
  24. });
  25. } else {
  26. obj[key] = value;
  27. }
  28. return obj;
  29. }
  30. function _default(j$) {
  31. return class Env {
  32. constructor() {
  33. _defineProperty(this, 'specFilter', void 0);
  34. _defineProperty(this, 'catchExceptions', void 0);
  35. _defineProperty(this, 'throwOnExpectationFailure', void 0);
  36. _defineProperty(this, 'catchingExceptions', void 0);
  37. _defineProperty(this, 'topSuite', void 0);
  38. _defineProperty(this, 'fail', void 0);
  39. _defineProperty(this, 'pending', void 0);
  40. _defineProperty(this, 'afterAll', void 0);
  41. _defineProperty(this, 'fit', void 0);
  42. _defineProperty(this, 'throwingExpectationFailures', void 0);
  43. _defineProperty(this, 'randomizeTests', void 0);
  44. _defineProperty(this, 'randomTests', void 0);
  45. _defineProperty(this, 'seed', void 0);
  46. _defineProperty(this, 'execute', void 0);
  47. _defineProperty(this, 'fdescribe', void 0);
  48. _defineProperty(this, 'spyOn', void 0);
  49. _defineProperty(this, 'beforeEach', void 0);
  50. _defineProperty(this, 'afterEach', void 0);
  51. _defineProperty(this, 'clearReporters', void 0);
  52. _defineProperty(this, 'addReporter', void 0);
  53. _defineProperty(this, 'it', void 0);
  54. _defineProperty(this, 'xdescribe', void 0);
  55. _defineProperty(this, 'xit', void 0);
  56. _defineProperty(this, 'beforeAll', void 0);
  57. _defineProperty(this, 'todo', void 0);
  58. _defineProperty(this, 'provideFallbackReporter', void 0);
  59. _defineProperty(this, 'allowRespy', void 0);
  60. _defineProperty(this, 'describe', void 0);
  61. let totalSpecsDefined = 0;
  62. let catchExceptions = true;
  63. const realSetTimeout = global.setTimeout;
  64. const realClearTimeout = global.clearTimeout;
  65. const runnableResources = {};
  66. const currentlyExecutingSuites = [];
  67. let currentSpec = null;
  68. let throwOnExpectationFailure = false;
  69. let random = false;
  70. let seed = null;
  71. let nextSpecId = 0;
  72. let nextSuiteId = 0;
  73. const getNextSpecId = function () {
  74. return 'spec' + nextSpecId++;
  75. };
  76. const getNextSuiteId = function () {
  77. return 'suite' + nextSuiteId++;
  78. };
  79. const topSuite = new j$.Suite({
  80. id: getNextSuiteId(),
  81. description: '',
  82. getTestPath() {
  83. return j$.testPath;
  84. }
  85. });
  86. let currentDeclarationSuite = topSuite;
  87. const currentSuite = function () {
  88. return currentlyExecutingSuites[currentlyExecutingSuites.length - 1];
  89. };
  90. const currentRunnable = function () {
  91. return currentSpec || currentSuite();
  92. };
  93. const reporter = new j$.ReportDispatcher([
  94. 'jasmineStarted',
  95. 'jasmineDone',
  96. 'suiteStarted',
  97. 'suiteDone',
  98. 'specStarted',
  99. 'specDone'
  100. ]);
  101. this.specFilter = function () {
  102. return true;
  103. };
  104. const defaultResourcesForRunnable = function (id, _parentRunnableId) {
  105. const resources = {
  106. spies: []
  107. };
  108. runnableResources[id] = resources;
  109. };
  110. const clearResourcesForRunnable = function (id) {
  111. spyRegistry.clearSpies();
  112. delete runnableResources[id];
  113. };
  114. const beforeAndAfterFns = function (suite) {
  115. return function () {
  116. let afters = [];
  117. let befores = [];
  118. while (suite) {
  119. befores = befores.concat(suite.beforeFns);
  120. afters = afters.concat(suite.afterFns);
  121. suite = suite.parentSuite;
  122. }
  123. return {
  124. befores: befores.reverse(),
  125. afters
  126. };
  127. };
  128. };
  129. const getSpecName = function (spec, suite) {
  130. const fullName = [spec.description];
  131. const suiteFullName = suite.getFullName();
  132. if (suiteFullName !== '') {
  133. fullName.unshift(suiteFullName);
  134. }
  135. return fullName.join(' ');
  136. };
  137. this.catchExceptions = function (value) {
  138. catchExceptions = !!value;
  139. return catchExceptions;
  140. };
  141. this.catchingExceptions = function () {
  142. return catchExceptions;
  143. };
  144. this.throwOnExpectationFailure = function (value) {
  145. throwOnExpectationFailure = !!value;
  146. };
  147. this.throwingExpectationFailures = function () {
  148. return throwOnExpectationFailure;
  149. };
  150. this.randomizeTests = function (value) {
  151. random = !!value;
  152. };
  153. this.randomTests = function () {
  154. return random;
  155. };
  156. this.seed = function (value) {
  157. if (value) {
  158. seed = value;
  159. }
  160. return seed;
  161. };
  162. const queueRunnerFactory = options => {
  163. options.clearTimeout = realClearTimeout;
  164. options.fail = this.fail;
  165. options.setTimeout = realSetTimeout;
  166. return (0, _queueRunner.default)(options);
  167. };
  168. this.topSuite = function () {
  169. return topSuite;
  170. };
  171. const uncaught = err => {
  172. if (currentSpec) {
  173. currentSpec.onException(err);
  174. currentSpec.cancel();
  175. } else {
  176. console.error('Unhandled error');
  177. console.error(err.stack);
  178. }
  179. };
  180. let oldListenersException;
  181. let oldListenersRejection;
  182. const executionSetup = function () {
  183. // Need to ensure we are the only ones handling these exceptions.
  184. oldListenersException = process.listeners('uncaughtException').slice();
  185. oldListenersRejection = process.listeners('unhandledRejection').slice();
  186. j$.process.removeAllListeners('uncaughtException');
  187. j$.process.removeAllListeners('unhandledRejection');
  188. j$.process.on('uncaughtException', uncaught);
  189. j$.process.on('unhandledRejection', uncaught);
  190. };
  191. const executionTeardown = function () {
  192. j$.process.removeListener('uncaughtException', uncaught);
  193. j$.process.removeListener('unhandledRejection', uncaught); // restore previous exception handlers
  194. oldListenersException.forEach(listener => {
  195. j$.process.on('uncaughtException', listener);
  196. });
  197. oldListenersRejection.forEach(listener => {
  198. j$.process.on('unhandledRejection', listener);
  199. });
  200. };
  201. this.execute = async function (runnablesToRun, suiteTree = topSuite) {
  202. if (!runnablesToRun) {
  203. if (focusedRunnables.length) {
  204. runnablesToRun = focusedRunnables;
  205. } else {
  206. runnablesToRun = [suiteTree.id];
  207. }
  208. }
  209. if (currentlyExecutingSuites.length === 0) {
  210. executionSetup();
  211. }
  212. const lastDeclarationSuite = currentDeclarationSuite;
  213. await (0, _treeProcessor.default)({
  214. nodeComplete(suite) {
  215. if (!suite.disabled) {
  216. clearResourcesForRunnable(suite.id);
  217. }
  218. currentlyExecutingSuites.pop();
  219. if (suite === topSuite) {
  220. reporter.jasmineDone({
  221. failedExpectations: topSuite.result.failedExpectations
  222. });
  223. } else {
  224. reporter.suiteDone(suite.getResult());
  225. }
  226. },
  227. nodeStart(suite) {
  228. currentlyExecutingSuites.push(suite);
  229. defaultResourcesForRunnable(
  230. suite.id,
  231. suite.parentSuite && suite.parentSuite.id
  232. );
  233. if (suite === topSuite) {
  234. reporter.jasmineStarted({
  235. totalSpecsDefined
  236. });
  237. } else {
  238. reporter.suiteStarted(suite.result);
  239. }
  240. },
  241. queueRunnerFactory,
  242. runnableIds: runnablesToRun,
  243. tree: suiteTree
  244. });
  245. currentDeclarationSuite = lastDeclarationSuite;
  246. if (currentlyExecutingSuites.length === 0) {
  247. executionTeardown();
  248. }
  249. };
  250. this.addReporter = function (reporterToAdd) {
  251. reporter.addReporter(reporterToAdd);
  252. };
  253. this.provideFallbackReporter = function (reporterToAdd) {
  254. reporter.provideFallbackReporter(reporterToAdd);
  255. };
  256. this.clearReporters = function () {
  257. reporter.clearReporters();
  258. };
  259. const spyRegistry = new j$.SpyRegistry({
  260. currentSpies() {
  261. if (!currentRunnable()) {
  262. throw new Error(
  263. 'Spies must be created in a before function or a spec'
  264. );
  265. }
  266. return runnableResources[currentRunnable().id].spies;
  267. }
  268. });
  269. this.allowRespy = function (allow) {
  270. spyRegistry.allowRespy(allow);
  271. };
  272. this.spyOn = function (...args) {
  273. return spyRegistry.spyOn.apply(spyRegistry, args);
  274. };
  275. const suiteFactory = function (description) {
  276. const suite = new j$.Suite({
  277. id: getNextSuiteId(),
  278. description,
  279. parentSuite: currentDeclarationSuite,
  280. throwOnExpectationFailure,
  281. getTestPath() {
  282. return j$.testPath;
  283. }
  284. });
  285. return suite;
  286. };
  287. this.describe = function (description, specDefinitions) {
  288. const suite = suiteFactory(description);
  289. if (specDefinitions === undefined) {
  290. throw new Error(
  291. `Missing second argument. It must be a callback function.`
  292. );
  293. }
  294. if (typeof specDefinitions !== 'function') {
  295. throw new Error(
  296. `Invalid second argument, ${specDefinitions}. It must be a callback function.`
  297. );
  298. }
  299. if (specDefinitions.length > 0) {
  300. throw new Error('describe does not expect any arguments');
  301. }
  302. if (currentDeclarationSuite.markedPending) {
  303. suite.pend();
  304. }
  305. if (currentDeclarationSuite.markedTodo) {
  306. // @ts-expect-error TODO Possible error: Suite does not have todo method
  307. suite.todo();
  308. }
  309. addSpecsToSuite(suite, specDefinitions);
  310. return suite;
  311. };
  312. this.xdescribe = function (description, specDefinitions) {
  313. const suite = suiteFactory(description);
  314. suite.pend();
  315. addSpecsToSuite(suite, specDefinitions);
  316. return suite;
  317. };
  318. const focusedRunnables = [];
  319. this.fdescribe = function (description, specDefinitions) {
  320. const suite = suiteFactory(description);
  321. suite.isFocused = true;
  322. focusedRunnables.push(suite.id);
  323. unfocusAncestor();
  324. addSpecsToSuite(suite, specDefinitions);
  325. return suite;
  326. };
  327. const addSpecsToSuite = (suite, specDefinitions) => {
  328. const parentSuite = currentDeclarationSuite;
  329. parentSuite.addChild(suite);
  330. currentDeclarationSuite = suite;
  331. let declarationError = undefined;
  332. let describeReturnValue;
  333. try {
  334. describeReturnValue = specDefinitions.call(suite);
  335. } catch (e) {
  336. declarationError = e;
  337. }
  338. if ((0, _jestUtil.isPromise)(describeReturnValue)) {
  339. declarationError = new Error(
  340. 'Returning a Promise from "describe" is not supported. Tests must be defined synchronously.'
  341. );
  342. } else if (describeReturnValue !== undefined) {
  343. declarationError = new Error(
  344. 'A "describe" callback must not return a value.'
  345. );
  346. }
  347. if (declarationError) {
  348. this.it('encountered a declaration exception', () => {
  349. throw declarationError;
  350. });
  351. }
  352. currentDeclarationSuite = parentSuite;
  353. };
  354. function findFocusedAncestor(suite) {
  355. while (suite) {
  356. if (suite.isFocused) {
  357. return suite.id;
  358. }
  359. suite = suite.parentSuite;
  360. }
  361. return null;
  362. }
  363. function unfocusAncestor() {
  364. const focusedAncestor = findFocusedAncestor(currentDeclarationSuite);
  365. if (focusedAncestor) {
  366. for (let i = 0; i < focusedRunnables.length; i++) {
  367. if (focusedRunnables[i] === focusedAncestor) {
  368. focusedRunnables.splice(i, 1);
  369. break;
  370. }
  371. }
  372. }
  373. }
  374. const specFactory = (description, fn, suite, timeout) => {
  375. totalSpecsDefined++;
  376. const spec = new j$.Spec({
  377. id: getNextSpecId(),
  378. beforeAndAfterFns: beforeAndAfterFns(suite),
  379. resultCallback: specResultCallback,
  380. getSpecName(spec) {
  381. return getSpecName(spec, suite);
  382. },
  383. getTestPath() {
  384. return j$.testPath;
  385. },
  386. onStart: specStarted,
  387. description,
  388. queueRunnerFactory,
  389. userContext() {
  390. return suite.clonedSharedUserContext();
  391. },
  392. queueableFn: {
  393. fn,
  394. timeout() {
  395. return timeout || j$._DEFAULT_TIMEOUT_INTERVAL;
  396. }
  397. },
  398. throwOnExpectationFailure
  399. });
  400. if (!this.specFilter(spec)) {
  401. spec.disable();
  402. }
  403. return spec;
  404. function specResultCallback(result) {
  405. clearResourcesForRunnable(spec.id);
  406. currentSpec = null;
  407. reporter.specDone(result);
  408. }
  409. function specStarted(spec) {
  410. currentSpec = spec;
  411. defaultResourcesForRunnable(spec.id, suite.id);
  412. reporter.specStarted(spec.result);
  413. }
  414. };
  415. this.it = function (description, fn, timeout) {
  416. if (typeof description !== 'string') {
  417. throw new Error(
  418. `Invalid first argument, ${description}. It must be a string.`
  419. );
  420. }
  421. if (fn === undefined) {
  422. throw new Error(
  423. 'Missing second argument. It must be a callback function. Perhaps you want to use `test.todo` for a test placeholder.'
  424. );
  425. }
  426. if (typeof fn !== 'function') {
  427. throw new Error(
  428. `Invalid second argument, ${fn}. It must be a callback function.`
  429. );
  430. }
  431. const spec = specFactory(
  432. description,
  433. fn,
  434. currentDeclarationSuite,
  435. timeout
  436. );
  437. if (currentDeclarationSuite.markedPending) {
  438. spec.pend();
  439. } // When a test is defined inside another, jasmine will not run it.
  440. // This check throws an error to warn the user about the edge-case.
  441. if (currentSpec !== null) {
  442. throw new Error(
  443. `Tests cannot be nested. Test "${spec.description}" cannot run because it is nested within "${currentSpec.description}".`
  444. );
  445. }
  446. currentDeclarationSuite.addChild(spec);
  447. return spec;
  448. };
  449. this.xit = function (...args) {
  450. const spec = this.it.apply(this, args);
  451. spec.pend('Temporarily disabled with xit');
  452. return spec;
  453. };
  454. this.todo = function () {
  455. const description = arguments[0];
  456. if (arguments.length !== 1 || typeof description !== 'string') {
  457. throw new _jestUtil.ErrorWithStack(
  458. 'Todo must be called with only a description.',
  459. this.todo
  460. );
  461. }
  462. const spec = specFactory(
  463. description,
  464. () => {},
  465. currentDeclarationSuite
  466. );
  467. if (currentDeclarationSuite.markedPending) {
  468. spec.pend();
  469. } else {
  470. spec.todo();
  471. }
  472. currentDeclarationSuite.addChild(spec);
  473. return spec;
  474. };
  475. this.fit = function (description, fn, timeout) {
  476. const spec = specFactory(
  477. description,
  478. fn,
  479. currentDeclarationSuite,
  480. timeout
  481. );
  482. currentDeclarationSuite.addChild(spec);
  483. if (currentDeclarationSuite.markedPending) {
  484. spec.pend();
  485. } else {
  486. focusedRunnables.push(spec.id);
  487. }
  488. unfocusAncestor();
  489. return spec;
  490. };
  491. this.beforeEach = function (beforeEachFunction, timeout) {
  492. currentDeclarationSuite.beforeEach({
  493. fn: beforeEachFunction,
  494. timeout() {
  495. return timeout || j$._DEFAULT_TIMEOUT_INTERVAL;
  496. }
  497. });
  498. };
  499. this.beforeAll = function (beforeAllFunction, timeout) {
  500. currentDeclarationSuite.beforeAll({
  501. fn: beforeAllFunction,
  502. timeout() {
  503. return timeout || j$._DEFAULT_TIMEOUT_INTERVAL;
  504. }
  505. });
  506. };
  507. this.afterEach = function (afterEachFunction, timeout) {
  508. currentDeclarationSuite.afterEach({
  509. fn: afterEachFunction,
  510. timeout() {
  511. return timeout || j$._DEFAULT_TIMEOUT_INTERVAL;
  512. }
  513. });
  514. };
  515. this.afterAll = function (afterAllFunction, timeout) {
  516. currentDeclarationSuite.afterAll({
  517. fn: afterAllFunction,
  518. timeout() {
  519. return timeout || j$._DEFAULT_TIMEOUT_INTERVAL;
  520. }
  521. });
  522. };
  523. this.pending = function (message) {
  524. let fullMessage = j$.Spec.pendingSpecExceptionMessage;
  525. if (message) {
  526. fullMessage += message;
  527. }
  528. throw fullMessage;
  529. };
  530. this.fail = function (error) {
  531. let checkIsError;
  532. let message;
  533. if (
  534. error instanceof _assert.AssertionError ||
  535. (error && error.name === _assert.AssertionError.name)
  536. ) {
  537. checkIsError = false; // @ts-expect-error TODO Possible error: j$.Spec does not have expand property
  538. message = (0, _assertionErrorMessage.default)(error, {
  539. expand: j$.Spec.expand
  540. });
  541. } else {
  542. const check = (0, _isError.default)(error);
  543. checkIsError = check.isError;
  544. message = check.message;
  545. }
  546. const errorAsErrorObject = checkIsError ? error : new Error(message);
  547. const runnable = currentRunnable();
  548. if (!runnable) {
  549. errorAsErrorObject.message =
  550. 'Caught error after test environment was torn down\n\n' +
  551. errorAsErrorObject.message;
  552. throw errorAsErrorObject;
  553. }
  554. runnable.addExpectationResult(false, {
  555. matcherName: '',
  556. passed: false,
  557. expected: '',
  558. actual: '',
  559. message,
  560. error: errorAsErrorObject
  561. });
  562. };
  563. }
  564. };
  565. }