Skip to content

Commit 4538aba

Browse files
bjaspanBarry Jaspanpre-commit-ci-lite[bot]
authored
Move non-test toPlainObject out of common/src/testUtil (#2003)
Move toPlainObject.ts to util; create testUtil/spyToPlainObject.ts. --------- Co-authored-by: Barry Jaspan <[email protected]> Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent 3981ac9 commit 4538aba

File tree

6 files changed

+38
-37
lines changed

6 files changed

+38
-37
lines changed

packages/common/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export * from "./types/SpokenForm";
5050
export * from "./util/textFormatters";
5151
export * from "./types/snippet.types";
5252
export * from "./testUtil/fromPlainObject";
53-
export * from "./testUtil/toPlainObject";
53+
export * from "./testUtil/spyToPlainObject";
5454
export { default as DefaultMap } from "./util/DefaultMap";
5555
export * from "./types/GeneralizedRange";
5656
export * from "./types/RangeOffsets";
@@ -92,3 +92,4 @@ export * from "./getFakeCommandServerApi";
9292
export * from "./types/TestCaseFixture";
9393
export * from "./util/getEnvironmentVariableStrict";
9494
export * from "./util/CompositeKeyDefaultMap";
95+
export * from "./util/toPlainObject";

packages/common/src/testUtil/TestCaseSnapshot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
SelectionPlainObject,
44
SerializedMarks,
55
TargetPlainObject,
6-
} from "./toPlainObject";
6+
} from "../util/toPlainObject";
77

88
export type TestCaseSnapshot = {
99
documentContents: string;

packages/common/src/testUtil/fromPlainObject.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {
55
PositionPlainObject,
66
RangePlainObject,
77
SelectionPlainObject,
8-
} from "./toPlainObject";
8+
} from "../util/toPlainObject";
99

1010
export function plainObjectToPosition({
1111
line,
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import type { Message, SpyIDERecordedValues } from "..";
2+
import {
3+
PlainFlashDescriptor,
4+
PlainHighlight,
5+
generalizedRangeToPlainObject,
6+
} from "../util/toPlainObject";
7+
8+
export interface PlainSpyIDERecordedValues {
9+
messages: Message[] | undefined;
10+
flashes: PlainFlashDescriptor[] | undefined;
11+
highlights: PlainHighlight[] | undefined;
12+
}
13+
14+
export function spyIDERecordedValuesToPlainObject(
15+
input: SpyIDERecordedValues,
16+
): PlainSpyIDERecordedValues {
17+
return {
18+
messages: input.messages,
19+
flashes: input.flashes?.map((descriptor) => ({
20+
style: descriptor.style,
21+
range: generalizedRangeToPlainObject(descriptor.range),
22+
})),
23+
highlights: input.highlights?.map((highlight) => ({
24+
highlightId: highlight.highlightId,
25+
ranges: highlight.ranges.map((range) =>
26+
generalizedRangeToPlainObject(range),
27+
),
28+
})),
29+
};
30+
}

packages/common/src/types/TestCaseFixture.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Command, CommandLatest } from "..";
22
import { TestCaseSnapshot } from "../testUtil/TestCaseSnapshot";
3-
import { PlainSpyIDERecordedValues } from "../testUtil/toPlainObject";
3+
import { PlainSpyIDERecordedValues } from "../testUtil/spyToPlainObject";
44

55
export type ThrownError = {
66
name: string;

packages/common/src/testUtil/toPlainObject.ts renamed to packages/common/src/util/toPlainObject.ts

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import type {
2-
CharacterRange,
3-
GeneralizedRange,
4-
LineRange,
5-
Message,
6-
SpyIDERecordedValues,
7-
} from "..";
1+
import type { CharacterRange, GeneralizedRange, LineRange } from "..";
82
import { FlashStyle, isLineRange } from "..";
93
import { Token } from "../types/Token";
104
import { Selection } from "../types/Selection";
@@ -27,22 +21,16 @@ export type CharacterRangePlainObject = {
2721

2822
export type GeneralizedRangePlainObject = CharacterRangePlainObject | LineRange;
2923

30-
interface PlainFlashDescriptor {
24+
export interface PlainFlashDescriptor {
3125
style: keyof typeof FlashStyle;
3226
range: GeneralizedRangePlainObject;
3327
}
3428

35-
interface PlainHighlight {
29+
export interface PlainHighlight {
3630
highlightId: string | undefined;
3731
ranges: GeneralizedRangePlainObject[];
3832
}
3933

40-
export interface PlainSpyIDERecordedValues {
41-
messages: Message[] | undefined;
42-
flashes: PlainFlashDescriptor[] | undefined;
43-
highlights: PlainHighlight[] | undefined;
44-
}
45-
4634
export type SelectionPlainObject = {
4735
anchor: PositionPlainObject;
4836
active: PositionPlainObject;
@@ -148,21 +136,3 @@ export function characterRangeToPlainObject(
148136
end: positionToPlainObject(range.end),
149137
};
150138
}
151-
152-
export function spyIDERecordedValuesToPlainObject(
153-
input: SpyIDERecordedValues,
154-
): PlainSpyIDERecordedValues {
155-
return {
156-
messages: input.messages,
157-
flashes: input.flashes?.map((descriptor) => ({
158-
style: descriptor.style,
159-
range: generalizedRangeToPlainObject(descriptor.range),
160-
})),
161-
highlights: input.highlights?.map((highlight) => ({
162-
highlightId: highlight.highlightId,
163-
ranges: highlight.ranges.map((range) =>
164-
generalizedRangeToPlainObject(range),
165-
),
166-
})),
167-
};
168-
}

0 commit comments

Comments
 (0)