1 | import { propertyPath } from '@stryker-mutator/util';
|
2 | import { schema } from '@stryker-mutator/api/core';
|
3 | import { StrykerOptions } from '@stryker-mutator/api/core';
|
4 |
|
5 | import emojiRegex from 'emoji-regex';
|
6 |
|
7 | const emojiRe = emojiRegex();
|
8 |
|
9 | const { MutantStatus } = schema;
|
10 |
|
11 | export function wrapInClosure(codeFragment: string): string {
|
12 | return `
|
13 | (function (window) {
|
14 | ${codeFragment}
|
15 | })((Function('return this'))());`;
|
16 | }
|
17 |
|
18 | export function padLeft(input: string): string {
|
19 | return input
|
20 | .split('\n')
|
21 | .map((str) => '\t' + str)
|
22 | .join('\n');
|
23 | }
|
24 |
|
25 | export function plural(items: number): string {
|
26 | if (items > 1) {
|
27 | return 's';
|
28 | } else {
|
29 | return '';
|
30 | }
|
31 | }
|
32 |
|
33 | export function serialize(thing: unknown): string {
|
34 | return JSON.stringify(thing);
|
35 | }
|
36 |
|
37 | export function deserialize<T>(stringified: string): T {
|
38 | return JSON.parse(stringified);
|
39 | }
|
40 |
|
41 | export function getEmojiForStatus(status: schema.MutantStatus): string {
|
42 | switch (status) {
|
43 | case MutantStatus.Killed:
|
44 | return '✅';
|
45 | case MutantStatus.NoCoverage:
|
46 | return '🙈';
|
47 | case MutantStatus.Ignored:
|
48 | return '🤥';
|
49 | case MutantStatus.Survived:
|
50 | return '👽';
|
51 | case MutantStatus.Timeout:
|
52 | return '⌛';
|
53 | case MutantStatus.RuntimeError:
|
54 | case MutantStatus.CompileError:
|
55 | return '💥';
|
56 | }
|
57 | }
|
58 |
|
59 | export function stringWidth(input: string): number {
|
60 | let length = input.length;
|
61 | for (const match of input.matchAll(emojiRe)) {
|
62 | length = length - match[0].length + 2;
|
63 | }
|
64 | return length;
|
65 | }
|
66 |
|
67 |
|
68 |
|
69 |
|
70 | export const optionsPath = propertyPath<StrykerOptions>();
|