UNPKG

@stryker-mutator/core

Version:

The extendable JavaScript mutation testing framework

62 lines 1.64 kB
import { propertyPath } from '@stryker-mutator/util'; import { schema } from '@stryker-mutator/api/core'; import emojiRegex from 'emoji-regex'; const emojiRe = emojiRegex(); const { MutantStatus } = schema; export function wrapInClosure(codeFragment) { return ` (function (window) { ${codeFragment} })((Function('return this'))());`; } export function padLeft(input) { return input .split('\n') .map((str) => '\t' + str) .join('\n'); } export function plural(items) { if (items > 1) { return 's'; } else { return ''; } } export function serialize(thing) { return JSON.stringify(thing); } export function deserialize(stringified) { return JSON.parse(stringified); } export function getEmojiForStatus(status) { switch (status) { case MutantStatus.Killed: return '✅'; case MutantStatus.NoCoverage: return '🙈'; case MutantStatus.Ignored: return '🤥'; case MutantStatus.Survived: return '👽'; case MutantStatus.Timeout: return '⏰'; case MutantStatus.Pending: return '⌛'; case MutantStatus.RuntimeError: case MutantStatus.CompileError: return '💥'; } } export function stringWidth(input) { let length = input.length; for (const match of input.matchAll(emojiRe)) { length = length - match[0].length + 2; } return length; } /** * Print the name of (or path to) a stryker option */ export const optionsPath = propertyPath(); //# sourceMappingURL=string-utils.js.map