import { parseSingleStack } from "../../utils/dist/source-map.js";
const kChainableContext = /* @__PURE__ */ Symbol("kChainableContext");
function getChainableContext(chainable) {
  return chainable?.[kChainableContext];
}
function createChainable(keys, fn, context) {
  function create(context2) {
    const chain2 = function(...args) {
      return fn.apply(context2, args);
    };
    Object.assign(chain2, fn);
    Object.defineProperty(chain2, kChainableContext, {
      value: {
        withContext: () => chain2.bind(context2),
        getFixtures: () => context2.fixtures,
        setContext: (key, value) => {
          context2[key] = value;
        },
        mergeContext: (ctx) => {
          Object.assign(context2, ctx);
        }
      },
      enumerable: false
    });
    for (const key of keys) {
      Object.defineProperty(chain2, key, { get() {
        return create({
          ...context2,
          [key]: true
        });
      } });
    }
    return chain2;
  }
  const chain = create(context ?? {});
  Object.defineProperty(chain, "fn", {
    value: fn,
    enumerable: false
  });
  return chain;
}
function findTestFileStackTrace(testFilePath, error) {
  const lines = error.split("\n").slice(1);
  for (const line of lines) {
    const stack = parseSingleStack(line);
    if (stack && stack.file === testFilePath) {
      return stack;
    }
  }
}
function validateTags(config, tags) {
  if (!config.strictTags) {
    return;
  }
  const availableTags = new Set(config.tags.map((tag) => tag.name));
  for (const tag of tags) {
    if (!availableTags.has(tag)) {
      throw createNoTagsError(config.tags, tag);
    }
  }
}
function createNoTagsError(availableTags, tag, prefix = "tag") {
  if (!availableTags.length) {
    throw new Error(`The Vitest config does't define any "tags", cannot apply "${tag}" ${prefix} for this test. See: https://vitest.dev/guide/test-tags`);
  }
  throw new Error(`The ${prefix} "${tag}" is not defined in the configuration. Available tags are:
${availableTags.map((t) => `- ${t.name}${t.description ? `: ${t.description}` : ""}`).join("\n")}`);
}
function getNames(task) {
  const names = [task.name];
  let current = task;
  while (current?.suite) {
    current = current.suite;
    if (current?.name) {
      names.unshift(current.name);
    }
  }
  if (current !== task.file) {
    names.unshift(task.file.name);
  }
  return names;
}
function createTaskName(names, separator = " > ") {
  return names.filter((name) => name !== void 0).join(separator);
}
export {
  createChainable as a,
  createTaskName as e,
  findTestFileStackTrace as f,
  getNames as j,
  validateTags as v,
  getChainableContext as w,
  createNoTagsError as x
};
//# sourceMappingURL=chunk-tasks.js.map
