當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript jest-message-util.formatExecError函數代碼示例

本文整理匯總了TypeScript中jest-message-util.formatExecError函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript formatExecError函數的具體用法?TypeScript formatExecError怎麽用?TypeScript formatExecError使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了formatExecError函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: ErrorWithStack

const _dispatchDescribe = (
  blockFn: BlockFn,
  blockName: BlockName,
  describeFn: DescribeFn,
  mode?: BlockMode,
) => {
  const asyncError = new ErrorWithStack(undefined, describeFn);
  if (blockFn === undefined) {
    asyncError.message = `Missing second argument. It must be a callback function.`;
    throw asyncError;
  }
  if (typeof blockFn !== 'function') {
    asyncError.message = `Invalid second argument, ${blockFn}. It must be a callback function.`;
    throw asyncError;
  }
  dispatch({
    asyncError,
    blockName,
    mode,
    name: 'start_describe_definition',
  });
  const describeReturn = blockFn();

  // TODO throw in Jest 25
  if (isPromise(describeReturn)) {
    console.log(
      formatExecError(
        new ErrorWithStack(
          chalk.yellow(
            'Returning a Promise from "describe" is not supported. Tests must be defined synchronously.\n' +
              'Returning a value from "describe" will fail the test in a future version of Jest.',
          ),
          describeFn,
        ),
        {rootDir: '', testMatch: []},
        {noStackTrace: false},
      ),
    );
  } else if (describeReturn !== undefined) {
    console.log(
      formatExecError(
        new ErrorWithStack(
          chalk.yellow(
            'A "describe" callback must not return a value.\n' +
              'Returning a value from "describe" will fail the test in a future version of Jest.',
          ),
          describeFn,
        ),
        {rootDir: '', testMatch: []},
        {noStackTrace: false},
      ),
    );
  }

  dispatch({blockName, mode, name: 'finish_describe_definition'});
};
開發者ID:Volune,項目名稱:jest,代碼行數:56,代碼來源:index.ts

示例2: catch

      const addSpecsToSuite = (suite: Suite, specDefinitions: Function) => {
        const parentSuite = currentDeclarationSuite;
        parentSuite.addChild(suite);
        currentDeclarationSuite = suite;

        let declarationError: undefined | Error = undefined;
        let describeReturnValue: undefined | Error = undefined;
        try {
          describeReturnValue = specDefinitions.call(suite);
        } catch (e) {
          declarationError = e;
        }

        // TODO throw in Jest 25: declarationError = new Error
        if (isPromise(describeReturnValue)) {
          console.log(
            formatExecError(
              new Error(
                chalk.yellow(
                  'Returning a Promise from "describe" is not supported. Tests must be defined synchronously.\n' +
                    'Returning a value from "describe" will fail the test in a future version of Jest.',
                ),
              ),
              {rootDir: '', testMatch: []},
              {noStackTrace: false},
            ),
          );
        } else if (describeReturnValue !== undefined) {
          console.log(
            formatExecError(
              new Error(
                chalk.yellow(
                  'A "describe" callback must not return a value.\n' +
                    'Returning a value from "describe" will fail the test in a future version of Jest.',
                ),
              ),
              {rootDir: '', testMatch: []},
              {noStackTrace: false},
            ),
          );
        }

        if (declarationError) {
          this.it('encountered a declaration exception', () => {
            throw declarationError;
          });
        }

        currentDeclarationSuite = parentSuite;
      };
開發者ID:facebook,項目名稱:jest,代碼行數:50,代碼來源:Env.ts

示例3: fakeConsolePush

  testConsole._log = function fakeConsolePush(
    _type: LogType,
    message: LogMessage,
  ) {
    const error = new ErrorWithStack(
      `${chalk.red(
        `${chalk.bold(
          'Cannot log after tests are done.',
        )} Did you forget to wait for something async in your test?`,
      )}\nAttempted to log "${message}".`,
      fakeConsolePush,
    );

    const formattedError = formatExecError(
      error,
      config,
      {noStackTrace: false},
      undefined,
      true,
    );

    process.stderr.write('\n' + formattedError + '\n');
    // TODO: set exit code in Jest 25
    // process.exitCode = 1;
  };
開發者ID:Volune,項目名稱:jest,代碼行數:25,代碼來源:runTest.ts

示例4: formatExecError

 }).catch(error =>
   // Errors thrown inside `runJest`, e.g. by resolvers, are caught here for
   // continuous watch mode execution. We need to reprint them to the
   // terminal and give just a little bit of extra space so they fit below
   // `preRunMessagePrint` message nicely.
   console.error(
     '\n\n' +
       formatExecError(error, contexts[0].config, {noStackTrace: false}),
   ),
開發者ID:facebook,項目名稱:jest,代碼行數:9,代碼來源:watch.ts

示例5: formatExecError

    }).catch(e => {
      const message = formatExecError(e, configs[0], {noStackTrace: true})
        .split('\n')
        .filter(line => !line.includes('Command failed:'))
        .join('\n');

      console.error(chalk.red(`\n\n${message}`));

      process.exit(1);

      // We do process.exit, so this is dead code
      return Promise.reject(e);
    });
開發者ID:Volune,項目名稱:jest,代碼行數:13,代碼來源:getChangedFilesPromise.ts

示例6: async

 const onFailure = async (test: Test, error: SerializableError) => {
   if (watcher.isInterrupted()) {
     return;
   }
   const testResult = buildFailureTestResult(test.path, error);
   testResult.failureMessage = formatExecError(
     testResult.testExecError,
     test.context.config,
     this._globalConfig,
     test.path,
   );
   addResult(aggregatedResults, testResult);
   await this._dispatcher.onTestResult(test, testResult, aggregatedResults);
 };
開發者ID:facebook,項目名稱:jest,代碼行數:14,代碼來源:TestScheduler.ts

示例7: exit

    environment.global.process.exit = function exit(...args: Array<any>) {
      const error = new ErrorWithStack(
        `process.exit called with "${args.join(', ')}"`,
        exit,
      );

      const formattedError = formatExecError(
        error,
        config,
        {noStackTrace: false},
        undefined,
        true,
      );

      process.stderr.write(formattedError);

      return realExit(...args);
    };
開發者ID:Volune,項目名稱:jest,代碼行數:18,代碼來源:runTest.ts

示例8: watch


//.........這裏部分代碼省略.........
  });

  if (globalConfig.watchPlugins != null) {
    const watchPluginKeys: WatchPluginKeysMap = new Map();
    for (const plugin of watchPlugins) {
      const reservedInfo =
        RESERVED_KEY_PLUGINS.get(plugin.constructor as WatchPluginClass) ||
        ({} as ReservedInfo);
      const key = reservedInfo.key || getPluginKey(plugin, globalConfig);
      if (!key) {
        continue;
      }
      const {forbiddenOverwriteMessage} = reservedInfo;
      watchPluginKeys.set(key, {
        forbiddenOverwriteMessage,
        overwritable: forbiddenOverwriteMessage == null,
        plugin,
      });
    }

    for (const pluginWithConfig of globalConfig.watchPlugins) {
      let plugin: WatchPlugin;
      try {
        const ThirdPartyPlugin = require(pluginWithConfig.path);
        plugin = new ThirdPartyPlugin({
          config: pluginWithConfig.config,
          stdin,
          stdout: outputStream,
        });
      } catch (error) {
        const errorWithContext = new Error(
          `Failed to initialize watch plugin "${chalk.bold(
            slash(path.relative(process.cwd(), pluginWithConfig.path)),
          )}":\n\n${formatExecError(error, contexts[0].config, {
            noStackTrace: false,
          })}`,
        );
        delete errorWithContext.stack;
        return Promise.reject(errorWithContext);
      }
      checkForConflicts(watchPluginKeys, plugin, globalConfig);

      const hookSubscriber = hooks.getSubscriber();
      if (plugin.apply) {
        plugin.apply(hookSubscriber);
      }
      watchPlugins.push(plugin);
    }
  }

  const failedTestsCache = new FailedTestsCache();
  let searchSources = contexts.map(context => ({
    context,
    searchSource: new SearchSource(context),
  }));
  let isRunning = false;
  let testWatcher: TestWatcher;
  let shouldDisplayWatchUsage = true;
  let isWatchUsageDisplayed = false;

  const emitFileChange = () => {
    if (hooks.isUsed('onFileChange')) {
      const projects = searchSources.map(({context, searchSource}) => ({
        config: context.config,
        testPaths: searchSource.findMatchingTests('').tests.map(t => t.path),
      }));
開發者ID:facebook,項目名稱:jest,代碼行數:67,代碼來源:watch.ts

示例9: formatExecError

 .map(err => formatExecError(err, config, globalConfig))
開發者ID:facebook,項目名稱:jest,代碼行數:1,代碼來源:jestAdapterInit.ts

示例10: formatExecError

 .map(err =>
   formatExecError(err, config, {noStackTrace: false}, undefined, true),
開發者ID:Volune,項目名稱:jest,代碼行數:2,代碼來源:collectHandles.ts


注:本文中的jest-message-util.formatExecError函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。