Skip to content

Commit 22bd2a0

Browse files
committed
Remove unused code
1 parent 23b5397 commit 22bd2a0

File tree

3 files changed

+31
-124
lines changed

3 files changed

+31
-124
lines changed

test/helpers/expect-logs.ts

Lines changed: 0 additions & 118 deletions
This file was deleted.

test/helpers/expect-multiline.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Makes a regexp pattern to match multiline strings. String arguments passed to
3+
* `makeMultilineMatcher` will be escaped then merged together into a regexp
4+
* that will match partial lines of multi-line error messages when paired with
5+
* Jest `expect().toThrow` or `expect.stringMatching`.
6+
*
7+
* @example
8+
* ```
9+
* const expected = makeMultilineMatcher('Line 1', 'Line 2', '3')
10+
* //=> 'Line 1[\S\s]*Line 2[\S\s]*3'
11+
*
12+
* expect('Line 1\nLine 2\nLine 3').toEqual(expect.stringMatching(expected));
13+
* //=> passes
14+
* ```
15+
*/
16+
export function makeMultilineMatcher(...parts: string[]): string {
17+
return parts.map(escapeRegExp).join('[\\S\\s]*');
18+
}
19+
20+
/**
21+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping
22+
*/
23+
function escapeRegExp(string: string): string {
24+
return string.replace(/[$()*+.?[\\\]^{|}]/g, '\\$&'); // $& means the whole matched string
25+
}

test/options.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, test } from '@jest/globals';
22
import { DEFAULT_OPTIONS, parseConfig } from '../transforms/helpers/options';
3-
import { makeLogMatcher } from './helpers/expect-logs';
3+
import { makeMultilineMatcher } from './helpers/expect-multiline';
44

55
describe('options', () => {
66
describe('parseConfig', () => {
@@ -60,7 +60,7 @@ describe('options', () => {
6060
test('it errors for invalid `decorators` config', () => {
6161
expect(() => parseConfig('test', { decorators: 'oops' })).toThrow(
6262
new RegExp(
63-
makeLogMatcher(
63+
makeMultilineMatcher(
6464
'test Config Error',
6565
"[decorators] Expected DecoratorOptions object or boolean, received 'oops'"
6666
)
@@ -95,7 +95,7 @@ describe('options', () => {
9595
test(`it errors for invalid \`${fieldName}\` config`, () => {
9696
expect(() => parseConfig('test', { [fieldName]: 'oops' })).toThrow(
9797
new RegExp(
98-
makeLogMatcher(
98+
makeMultilineMatcher(
9999
'test Config Error',
100100
`[${fieldName}] Expected boolean, received string`
101101
)
@@ -119,7 +119,7 @@ describe('options', () => {
119119
test('it errors for invalid `quote` config', () => {
120120
expect(() => parseConfig('test', { quote: 'oops' })).toThrow(
121121
new RegExp(
122-
makeLogMatcher(
122+
makeMultilineMatcher(
123123
'test Config Error',
124124
"[quote] Expected 'single' or 'double', received 'oops"
125125
)
@@ -157,7 +157,7 @@ describe('options', () => {
157157
parseConfig('test', { ignoreLeakingState: false })
158158
).toThrow(
159159
new RegExp(
160-
makeLogMatcher(
160+
makeMultilineMatcher(
161161
'test Config Error',
162162
'[ignoreLeakingState] Expected array of strings or comma-separated string, received false'
163163
)
@@ -178,7 +178,7 @@ describe('options', () => {
178178
test('it errors for invalid `type` config', () => {
179179
expect(() => parseConfig('test', { type: 'oops' })).toThrow(
180180
new RegExp(
181-
makeLogMatcher(
181+
makeMultilineMatcher(
182182
'test Config Error',
183183
"[type] Expected 'services', 'routes', 'components', or 'controllers', received 'oops"
184184
)

0 commit comments

Comments
 (0)