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 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.readConfig = readConfig;
  6. exports.readConfigs = readConfigs;
  7. Object.defineProperty(exports, 'normalize', {
  8. enumerable: true,
  9. get: function () {
  10. return _normalize.default;
  11. }
  12. });
  13. Object.defineProperty(exports, 'isJSONString', {
  14. enumerable: true,
  15. get: function () {
  16. return _utils.isJSONString;
  17. }
  18. });
  19. Object.defineProperty(exports, 'replaceRootDirInPath', {
  20. enumerable: true,
  21. get: function () {
  22. return _utils.replaceRootDirInPath;
  23. }
  24. });
  25. Object.defineProperty(exports, 'getTestEnvironment', {
  26. enumerable: true,
  27. get: function () {
  28. return _jestResolve().resolveTestEnvironment;
  29. }
  30. });
  31. Object.defineProperty(exports, 'deprecationEntries', {
  32. enumerable: true,
  33. get: function () {
  34. return _Deprecated.default;
  35. }
  36. });
  37. Object.defineProperty(exports, 'defaults', {
  38. enumerable: true,
  39. get: function () {
  40. return _Defaults.default;
  41. }
  42. });
  43. Object.defineProperty(exports, 'descriptions', {
  44. enumerable: true,
  45. get: function () {
  46. return _Descriptions.default;
  47. }
  48. });
  49. exports.constants = void 0;
  50. function path() {
  51. const data = _interopRequireWildcard(require('path'));
  52. path = function () {
  53. return data;
  54. };
  55. return data;
  56. }
  57. function _chalk() {
  58. const data = _interopRequireDefault(require('chalk'));
  59. _chalk = function () {
  60. return data;
  61. };
  62. return data;
  63. }
  64. function fs() {
  65. const data = _interopRequireWildcard(require('graceful-fs'));
  66. fs = function () {
  67. return data;
  68. };
  69. return data;
  70. }
  71. function _jestUtil() {
  72. const data = require('jest-util');
  73. _jestUtil = function () {
  74. return data;
  75. };
  76. return data;
  77. }
  78. var constants = _interopRequireWildcard(require('./constants'));
  79. exports.constants = constants;
  80. var _normalize = _interopRequireDefault(require('./normalize'));
  81. var _readConfigFileAndSetRootDir = _interopRequireDefault(
  82. require('./readConfigFileAndSetRootDir')
  83. );
  84. var _resolveConfigPath = _interopRequireDefault(require('./resolveConfigPath'));
  85. var _utils = require('./utils');
  86. function _jestResolve() {
  87. const data = require('jest-resolve');
  88. _jestResolve = function () {
  89. return data;
  90. };
  91. return data;
  92. }
  93. var _Deprecated = _interopRequireDefault(require('./Deprecated'));
  94. var _Defaults = _interopRequireDefault(require('./Defaults'));
  95. var _Descriptions = _interopRequireDefault(require('./Descriptions'));
  96. function _interopRequireDefault(obj) {
  97. return obj && obj.__esModule ? obj : {default: obj};
  98. }
  99. function _getRequireWildcardCache(nodeInterop) {
  100. if (typeof WeakMap !== 'function') return null;
  101. var cacheBabelInterop = new WeakMap();
  102. var cacheNodeInterop = new WeakMap();
  103. return (_getRequireWildcardCache = function (nodeInterop) {
  104. return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
  105. })(nodeInterop);
  106. }
  107. function _interopRequireWildcard(obj, nodeInterop) {
  108. if (!nodeInterop && obj && obj.__esModule) {
  109. return obj;
  110. }
  111. if (obj === null || (typeof obj !== 'object' && typeof obj !== 'function')) {
  112. return {default: obj};
  113. }
  114. var cache = _getRequireWildcardCache(nodeInterop);
  115. if (cache && cache.has(obj)) {
  116. return cache.get(obj);
  117. }
  118. var newObj = {};
  119. var hasPropertyDescriptor =
  120. Object.defineProperty && Object.getOwnPropertyDescriptor;
  121. for (var key in obj) {
  122. if (key !== 'default' && Object.prototype.hasOwnProperty.call(obj, key)) {
  123. var desc = hasPropertyDescriptor
  124. ? Object.getOwnPropertyDescriptor(obj, key)
  125. : null;
  126. if (desc && (desc.get || desc.set)) {
  127. Object.defineProperty(newObj, key, desc);
  128. } else {
  129. newObj[key] = obj[key];
  130. }
  131. }
  132. }
  133. newObj.default = obj;
  134. if (cache) {
  135. cache.set(obj, newObj);
  136. }
  137. return newObj;
  138. }
  139. /**
  140. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  141. *
  142. * This source code is licensed under the MIT license found in the
  143. * LICENSE file in the root directory of this source tree.
  144. */
  145. // TODO: remove export in Jest 28
  146. async function readConfig(
  147. argv,
  148. packageRootOrConfig, // Whether it needs to look into `--config` arg passed to CLI.
  149. // It only used to read initial config. If the initial config contains
  150. // `project` property, we don't want to read `--config` value and rather
  151. // read individual configs for every project.
  152. skipArgvConfigOption,
  153. parentConfigDirname,
  154. projectIndex = Infinity
  155. ) {
  156. let rawOptions;
  157. let configPath = null;
  158. if (typeof packageRootOrConfig !== 'string') {
  159. if (parentConfigDirname) {
  160. rawOptions = packageRootOrConfig;
  161. rawOptions.rootDir = rawOptions.rootDir
  162. ? (0, _utils.replaceRootDirInPath)(
  163. parentConfigDirname,
  164. rawOptions.rootDir
  165. )
  166. : parentConfigDirname;
  167. } else {
  168. throw new Error(
  169. 'Jest: Cannot use configuration as an object without a file path.'
  170. );
  171. }
  172. } else if ((0, _utils.isJSONString)(argv.config)) {
  173. // A JSON string was passed to `--config` argument and we can parse it
  174. // and use as is.
  175. let config;
  176. try {
  177. config = JSON.parse(argv.config);
  178. } catch {
  179. throw new Error(
  180. 'There was an error while parsing the `--config` argument as a JSON string.'
  181. );
  182. } // NOTE: we might need to resolve this dir to an absolute path in the future
  183. config.rootDir = config.rootDir || packageRootOrConfig;
  184. rawOptions = config; // A string passed to `--config`, which is either a direct path to the config
  185. // or a path to directory containing `package.json`, `jest.config.js` or `jest.config.ts`
  186. } else if (!skipArgvConfigOption && typeof argv.config == 'string') {
  187. configPath = (0, _resolveConfigPath.default)(argv.config, process.cwd());
  188. rawOptions = await (0, _readConfigFileAndSetRootDir.default)(configPath);
  189. } else {
  190. // Otherwise just try to find config in the current rootDir.
  191. configPath = (0, _resolveConfigPath.default)(
  192. packageRootOrConfig,
  193. process.cwd()
  194. );
  195. rawOptions = await (0, _readConfigFileAndSetRootDir.default)(configPath);
  196. }
  197. const {options, hasDeprecationWarnings} = await (0, _normalize.default)(
  198. rawOptions,
  199. argv,
  200. configPath,
  201. projectIndex
  202. );
  203. const {globalConfig, projectConfig} = groupOptions(options);
  204. return {
  205. configPath,
  206. globalConfig,
  207. hasDeprecationWarnings,
  208. projectConfig
  209. };
  210. }
  211. const groupOptions = options => ({
  212. globalConfig: Object.freeze({
  213. bail: options.bail,
  214. changedFilesWithAncestor: options.changedFilesWithAncestor,
  215. changedSince: options.changedSince,
  216. collectCoverage: options.collectCoverage,
  217. collectCoverageFrom: options.collectCoverageFrom,
  218. collectCoverageOnlyFrom: options.collectCoverageOnlyFrom,
  219. coverageDirectory: options.coverageDirectory,
  220. coverageProvider: options.coverageProvider,
  221. coverageReporters: options.coverageReporters,
  222. coverageThreshold: options.coverageThreshold,
  223. detectLeaks: options.detectLeaks,
  224. detectOpenHandles: options.detectOpenHandles,
  225. errorOnDeprecated: options.errorOnDeprecated,
  226. expand: options.expand,
  227. filter: options.filter,
  228. findRelatedTests: options.findRelatedTests,
  229. forceExit: options.forceExit,
  230. globalSetup: options.globalSetup,
  231. globalTeardown: options.globalTeardown,
  232. json: options.json,
  233. lastCommit: options.lastCommit,
  234. listTests: options.listTests,
  235. logHeapUsage: options.logHeapUsage,
  236. maxConcurrency: options.maxConcurrency,
  237. maxWorkers: options.maxWorkers,
  238. noSCM: undefined,
  239. noStackTrace: options.noStackTrace,
  240. nonFlagArgs: options.nonFlagArgs,
  241. notify: options.notify,
  242. notifyMode: options.notifyMode,
  243. onlyChanged: options.onlyChanged,
  244. onlyFailures: options.onlyFailures,
  245. outputFile: options.outputFile,
  246. passWithNoTests: options.passWithNoTests,
  247. projects: options.projects,
  248. replname: options.replname,
  249. reporters: options.reporters,
  250. rootDir: options.rootDir,
  251. runTestsByPath: options.runTestsByPath,
  252. silent: options.silent,
  253. skipFilter: options.skipFilter,
  254. snapshotFormat: options.snapshotFormat,
  255. testFailureExitCode: options.testFailureExitCode,
  256. testNamePattern: options.testNamePattern,
  257. testPathPattern: options.testPathPattern,
  258. testResultsProcessor: options.testResultsProcessor,
  259. testSequencer: options.testSequencer,
  260. testTimeout: options.testTimeout,
  261. updateSnapshot: options.updateSnapshot,
  262. useStderr: options.useStderr,
  263. verbose: options.verbose,
  264. watch: options.watch,
  265. watchAll: options.watchAll,
  266. watchPlugins: options.watchPlugins,
  267. watchman: options.watchman
  268. }),
  269. projectConfig: Object.freeze({
  270. automock: options.automock,
  271. cache: options.cache,
  272. cacheDirectory: options.cacheDirectory,
  273. clearMocks: options.clearMocks,
  274. coveragePathIgnorePatterns: options.coveragePathIgnorePatterns,
  275. cwd: options.cwd,
  276. dependencyExtractor: options.dependencyExtractor,
  277. detectLeaks: options.detectLeaks,
  278. detectOpenHandles: options.detectOpenHandles,
  279. displayName: options.displayName,
  280. errorOnDeprecated: options.errorOnDeprecated,
  281. extensionsToTreatAsEsm: options.extensionsToTreatAsEsm,
  282. extraGlobals: options.extraGlobals,
  283. filter: options.filter,
  284. forceCoverageMatch: options.forceCoverageMatch,
  285. globalSetup: options.globalSetup,
  286. globalTeardown: options.globalTeardown,
  287. globals: options.globals,
  288. haste: options.haste,
  289. injectGlobals: options.injectGlobals,
  290. moduleDirectories: options.moduleDirectories,
  291. moduleFileExtensions: options.moduleFileExtensions,
  292. moduleLoader: options.moduleLoader,
  293. moduleNameMapper: options.moduleNameMapper,
  294. modulePathIgnorePatterns: options.modulePathIgnorePatterns,
  295. modulePaths: options.modulePaths,
  296. name: options.name,
  297. prettierPath: options.prettierPath,
  298. resetMocks: options.resetMocks,
  299. resetModules: options.resetModules,
  300. resolver: options.resolver,
  301. restoreMocks: options.restoreMocks,
  302. rootDir: options.rootDir,
  303. roots: options.roots,
  304. runner: options.runner,
  305. setupFiles: options.setupFiles,
  306. setupFilesAfterEnv: options.setupFilesAfterEnv,
  307. skipFilter: options.skipFilter,
  308. skipNodeResolution: options.skipNodeResolution,
  309. slowTestThreshold: options.slowTestThreshold,
  310. snapshotFormat: options.snapshotFormat,
  311. snapshotResolver: options.snapshotResolver,
  312. snapshotSerializers: options.snapshotSerializers,
  313. testEnvironment: options.testEnvironment,
  314. testEnvironmentOptions: options.testEnvironmentOptions,
  315. testLocationInResults: options.testLocationInResults,
  316. testMatch: options.testMatch,
  317. testPathIgnorePatterns: options.testPathIgnorePatterns,
  318. testRegex: options.testRegex,
  319. testRunner: options.testRunner,
  320. testURL: options.testURL,
  321. timers: options.timers,
  322. transform: options.transform,
  323. transformIgnorePatterns: options.transformIgnorePatterns,
  324. unmockedModulePathPatterns: options.unmockedModulePathPatterns,
  325. watchPathIgnorePatterns: options.watchPathIgnorePatterns
  326. })
  327. });
  328. const ensureNoDuplicateConfigs = (parsedConfigs, projects) => {
  329. if (projects.length <= 1) {
  330. return;
  331. }
  332. const configPathMap = new Map();
  333. for (const config of parsedConfigs) {
  334. const {configPath} = config;
  335. if (configPathMap.has(configPath)) {
  336. const message = `Whoops! Two projects resolved to the same config path: ${_chalk().default.bold(
  337. String(configPath)
  338. )}:
  339. Project 1: ${_chalk().default.bold(
  340. projects[parsedConfigs.findIndex(x => x === config)]
  341. )}
  342. Project 2: ${_chalk().default.bold(
  343. projects[parsedConfigs.findIndex(x => x === configPathMap.get(configPath))]
  344. )}
  345. This usually means that your ${_chalk().default.bold(
  346. '"projects"'
  347. )} config includes a directory that doesn't have any configuration recognizable by Jest. Please fix it.
  348. `;
  349. throw new Error(message);
  350. }
  351. if (configPath !== null) {
  352. configPathMap.set(configPath, config);
  353. }
  354. }
  355. }; // Possible scenarios:
  356. // 1. jest --config config.json
  357. // 2. jest --projects p1 p2
  358. // 3. jest --projects p1 p2 --config config.json
  359. // 4. jest --projects p1
  360. // 5. jest
  361. //
  362. // If no projects are specified, process.cwd() will be used as the default
  363. // (and only) project.
  364. async function readConfigs(argv, projectPaths) {
  365. let globalConfig;
  366. let hasDeprecationWarnings;
  367. let configs = [];
  368. let projects = projectPaths;
  369. let configPath;
  370. if (projectPaths.length === 1) {
  371. const parsedConfig = await readConfig(argv, projects[0]);
  372. configPath = parsedConfig.configPath;
  373. hasDeprecationWarnings = parsedConfig.hasDeprecationWarnings;
  374. globalConfig = parsedConfig.globalConfig;
  375. configs = [parsedConfig.projectConfig];
  376. if (globalConfig.projects && globalConfig.projects.length) {
  377. // Even though we had one project in CLI args, there might be more
  378. // projects defined in the config.
  379. // In other words, if this was a single project,
  380. // and its config has `projects` settings, use that value instead.
  381. projects = globalConfig.projects;
  382. }
  383. }
  384. if (projects.length > 0) {
  385. const cwd =
  386. process.platform === 'win32'
  387. ? (0, _jestUtil().tryRealpath)(process.cwd())
  388. : process.cwd();
  389. const projectIsCwd = projects[0] === cwd;
  390. const parsedConfigs = await Promise.all(
  391. projects
  392. .filter(root => {
  393. // Ignore globbed files that cannot be `require`d.
  394. if (
  395. typeof root === 'string' &&
  396. fs().existsSync(root) &&
  397. !fs().lstatSync(root).isDirectory() &&
  398. !constants.JEST_CONFIG_EXT_ORDER.some(ext => root.endsWith(ext))
  399. ) {
  400. return false;
  401. }
  402. return true;
  403. })
  404. .map((root, projectIndex) => {
  405. const projectIsTheOnlyProject =
  406. projectIndex === 0 && projects.length === 1;
  407. const skipArgvConfigOption = !(
  408. projectIsTheOnlyProject && projectIsCwd
  409. );
  410. return readConfig(
  411. argv,
  412. root,
  413. skipArgvConfigOption,
  414. configPath ? path().dirname(configPath) : cwd,
  415. projectIndex
  416. );
  417. })
  418. );
  419. ensureNoDuplicateConfigs(parsedConfigs, projects);
  420. configs = parsedConfigs.map(({projectConfig}) => projectConfig);
  421. if (!hasDeprecationWarnings) {
  422. hasDeprecationWarnings = parsedConfigs.some(
  423. ({hasDeprecationWarnings}) => !!hasDeprecationWarnings
  424. );
  425. } // If no config was passed initially, use the one from the first project
  426. if (!globalConfig) {
  427. globalConfig = parsedConfigs[0].globalConfig;
  428. }
  429. }
  430. if (!globalConfig || !configs.length) {
  431. throw new Error('jest: No configuration found for any project.');
  432. }
  433. return {
  434. configs,
  435. globalConfig,
  436. hasDeprecationWarnings: !!hasDeprecationWarnings
  437. };
  438. }