<commit_before>import path from 'path';
import MatmanConfig from './MatmanConfig';
import {getAbsolutePath} from '../util/index';
import {getFolderNameFromPath, getNewFilePathWithTag, getSaveDirFromPath} from '../util/path';

/**
 * 截图区域的配置信息
 */
interface ClipOpts {
  x: number;
  y: number;
  width: number;
  height: number;
}

/**
 * 是否启用截图, 或者截图保存的文件名路径(如果想对路径, 则相对于basePath 而言), 或者截图配置
 */
export type ScreenOpts =
  | string
  | boolean
  | {tag?: string; path: string; fullPage: boolean; clip?: ClipOpts};

export default class ScreenshotConfig {
  tag: string | undefined;
  path: string;
  clip: ClipOpts | undefined;
  fullPage = false;

  /**
   * 构造函数
   *
   * https://github.com/segmentio/nightmare#screenshotpath-clip
   *
   * @param {MatmanConfig} matmanConfig
   * @param {String | Boolean | Object} opts
   * @param {String} [caseModuleFilePath] 测试案例模块的目录
   * @param {String} [tag] 标记
   *
   * @author helinjiang
   * @author wangjq4214
   */
  constructor(
    matmanConfig: MatmanConfig,
    opts: ScreenOpts,
    caseModuleFilePath: string,
    tag?: string,
  ) {
    this.tag = tag;

    if (opts && typeof opts === 'object') {
      // 对象中传递的标记优先
      if (opts.tag) {
        this.tag = opts.tag;
      }

      // 如果传递了对象
      this.path = this.getScreenshotFullPath(opts.path, matmanConfig.screenshotPath);

      // 截图的区域，例如 { x: 0, y: 0, width: 0, height: 0 }
      // https://github.com/electron/electron/blob/master/docs/api/browser-window.md#winsetthumbnailclipregion-windows
      this.clip = opts.clip;
      this.fullPage = opts.fullPage;<commit_msg>fix: 修复核心包中的配置缺失问题<commit_after>import path from 'path';
import MatmanConfig from './MatmanConfig';
import {getAbsolutePath} from '../util/index';
import {getFolderNameFromPath, getNewFilePathWithTag, getSaveDirFromPath} from '../util/path';

/**
 * 截图区域的配置信息
 */
interface ClipOpts {
  x: number;
  y: number;
  width: number;
  height: number;
}

/**
 * 是否启用截图, 或者截图保存的文件名路径(如果想对路径, 则相对于basePath 而言), 或者截图配置
 */
export type ScreenOpts =
  | string
  | boolean
  | {tag?: string; path: string; fullPage: boolean; clip?: ClipOpts};

export default class ScreenshotConfig {
  tag: string | undefined;
  path: string;
  clip: ClipOpts | undefined;
  fullPage = false;

  /**
   * 构造函数
   *
   * https://github.com/segmentio/nightmare#screenshotpath-clip
   *
   * @param {MatmanConfig} matmanConfig
   * @param {String | Boolean | Object} opts
   * @param {String} [caseModuleFilePath] 测试案例模块的目录
   * @param {String} [tag] 标记
   *
   * @author helinjiang
   * @author wangjq4214
   */
  constructor(
    matmanConfig: MatmanConfig,
    opts: ScreenOpts,
    caseModuleFilePath: string,
    tag?: string,
  ) {
    this.tag = tag;

    if (opts && typeof opts === 'object') {
      // 对象中传递的标记优先
      if (opts.tag) {
        this.tag = opts.tag;
      }

      // 如果传递了对象
      if (opts.path) {
        this.path = this.getScreenshotFullPath(opts.path, matmanConfig.screenshotPath);
      } else {
        // 其他情况自动生成截图保存路径
        const relativeSavePath = getSaveDirFromPath(
          path.relative(matmanConfig.caseModulesPath, caseModuleFilePath),
        );

        const saveFileName = getFolderNameFromPath(path.basename(caseModuleFilePath)) + '.png';

        this.path = this.getScreenshotFullPath(
          path.join(relativeSavePath, saveFileName),
          matmanConfig.screenshotPath,
        );
      }

      // 截图的区域，例如 { x: 0, y: 0, width: 0, height: 0 }
      // https://github.com/electron/electron/blob/master/docs/api/browser-window.md#winsetthumbnailclipregion-windows
      this.clip = opts.clip;
      this.fullPage = opts.fullPage;
{'fraction_non_alphanumeric': 0.1288730463394571, 'fraction_numerical': 0.004387167534960241, 'mean_word_length': 2.991247264770241, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4037780', 'n_tokens_mistral': 1369, 'n_tokens_neox': 1407, 'n_words': 262}