当前位置: 首页>>代码示例>>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;未经允许,请勿转载。