|
1 | 1 | import { Readable, Writable } from 'stream'; |
2 | | -import { Config } from './config'; |
| 2 | +import { Config } from './getConfig'; |
3 | 3 | import { getContextForConfig } from './context'; |
4 | | -import { ThemeColorName } from './themes'; |
| 4 | +import { Theme, ThemeColorName } from './themes'; |
5 | 5 | import { transformContentsStreaming } from './transformContentsStreaming'; |
| 6 | +import { ChalkInstance } from 'chalk'; |
6 | 7 |
|
7 | 8 | const TEST_THEME = Object.fromEntries( |
8 | 9 | Object.keys(ThemeColorName).map((name) => [name, {}]) |
9 | | -); |
| 10 | +) as Theme; |
10 | 11 |
|
11 | 12 | const replaceColoredText = () => (text: string) => text.replace(/./g, '░'); |
12 | 13 |
|
| 14 | +// Provide a fake chalk implementation to make it easier to read snapshots |
| 15 | +// @ts-expect-error |
| 16 | +const TEST_CHALK = { |
| 17 | + rgb: replaceColoredText, |
| 18 | + bgRgb: replaceColoredText, |
| 19 | +} as ChalkInstance; |
| 20 | + |
13 | 21 | const TEST_CONFIG: Config = { |
14 | | - // Provide a fake chalk implementation to make it easier to read snapshots |
15 | | - CHALK: { |
16 | | - // @ts-expect-error |
17 | | - rgb: replaceColoredText, |
18 | | - // @ts-expect-error |
19 | | - bgRgb: replaceColoredText, |
20 | | - }, |
21 | | - SCREEN_WIDTH: 120, |
22 | 22 | MIN_LINE_WIDTH: 60, |
23 | 23 | WRAP_LINES: false, |
24 | 24 | HIGHLIGHT_LINE_CHANGES: false, |
25 | 25 | ...TEST_THEME, |
26 | 26 | }; |
27 | 27 |
|
28 | | -const CONFIG_OVERRIDES: Record<string, Partial<Config>> = { |
| 28 | +type TestOverrides = { screenWidth: number; config: Partial<Config> }; |
| 29 | + |
| 30 | +const CONFIG_OVERRIDES: Record<string, TestOverrides> = { |
29 | 31 | splitWithoutWrapping: { |
30 | | - SCREEN_WIDTH: 80, |
31 | | - MIN_LINE_WIDTH: 40, |
32 | | - WRAP_LINES: false, |
| 32 | + screenWidth: 80, |
| 33 | + config: { |
| 34 | + MIN_LINE_WIDTH: 40, |
| 35 | + WRAP_LINES: false, |
| 36 | + }, |
33 | 37 | }, |
34 | 38 | splitWithWrapping: { |
35 | | - SCREEN_WIDTH: 80, |
36 | | - MIN_LINE_WIDTH: 40, |
37 | | - WRAP_LINES: true, |
| 39 | + screenWidth: 80, |
| 40 | + config: { |
| 41 | + MIN_LINE_WIDTH: 40, |
| 42 | + WRAP_LINES: true, |
| 43 | + }, |
38 | 44 | }, |
39 | 45 | unifiedWithWrapping: { |
40 | | - SCREEN_WIDTH: 80, |
41 | | - MIN_LINE_WIDTH: 80, |
42 | | - WRAP_LINES: true, |
| 46 | + screenWidth: 80, |
| 47 | + config: { |
| 48 | + MIN_LINE_WIDTH: 80, |
| 49 | + WRAP_LINES: true, |
| 50 | + }, |
43 | 51 | }, |
44 | 52 | // This is in split mode |
45 | 53 | inlineChangesHighlighted: { |
46 | | - HIGHLIGHT_LINE_CHANGES: true, |
47 | | - DELETED_WORD_COLOR: { color: { r: 255, g: 0, b: 0, a: 255 } }, |
48 | | - INSERTED_WORD_COLOR: { color: { r: 0, g: 255, b: 0, a: 255 } }, |
| 54 | + screenWidth: 120, |
| 55 | + config: { |
| 56 | + HIGHLIGHT_LINE_CHANGES: true, |
| 57 | + DELETED_WORD_COLOR: { color: { r: 255, g: 0, b: 0, a: 255 } }, |
| 58 | + INSERTED_WORD_COLOR: { color: { r: 0, g: 255, b: 0, a: 255 } }, |
| 59 | + }, |
49 | 60 | }, |
50 | 61 | unifiedWithInlineChangesHighlighted: { |
51 | | - SCREEN_WIDTH: 80, |
52 | | - MIN_LINE_WIDTH: 80, |
53 | | - HIGHLIGHT_LINE_CHANGES: true, |
54 | | - DELETED_WORD_COLOR: { color: { r: 255, g: 0, b: 0, a: 255 } }, |
55 | | - INSERTED_WORD_COLOR: { color: { r: 0, g: 255, b: 0, a: 255 } }, |
| 62 | + screenWidth: 80, |
| 63 | + config: { |
| 64 | + MIN_LINE_WIDTH: 80, |
| 65 | + HIGHLIGHT_LINE_CHANGES: true, |
| 66 | + DELETED_WORD_COLOR: { color: { r: 255, g: 0, b: 0, a: 255 } }, |
| 67 | + INSERTED_WORD_COLOR: { color: { r: 0, g: 255, b: 0, a: 255 } }, |
| 68 | + }, |
56 | 69 | }, |
57 | 70 | syntaxHighlighted: { |
58 | | - SCREEN_WIDTH: 80, |
59 | | - MIN_LINE_WIDTH: 40, |
60 | | - WRAP_LINES: false, |
61 | | - SYNTAX_HIGHLIGHTING_THEME: 'dark-plus', |
| 71 | + screenWidth: 80, |
| 72 | + config: { |
| 73 | + MIN_LINE_WIDTH: 40, |
| 74 | + WRAP_LINES: false, |
| 75 | + SYNTAX_HIGHLIGHTING_THEME: 'dark-plus', |
| 76 | + }, |
62 | 77 | }, |
63 | 78 | }; |
64 | 79 |
|
65 | | -for (const [configName, configOverride] of Object.entries(CONFIG_OVERRIDES)) { |
| 80 | +for (const [configName, { screenWidth, config }] of Object.entries( |
| 81 | + CONFIG_OVERRIDES |
| 82 | +)) { |
66 | 83 | async function transform(input: string): Promise<string> { |
67 | 84 | const testConfig: Config = { |
68 | 85 | ...TEST_CONFIG, |
69 | | - ...configOverride, |
| 86 | + ...config, |
70 | 87 | }; |
71 | | - const context = await getContextForConfig(testConfig); |
| 88 | + const context = await getContextForConfig( |
| 89 | + testConfig, |
| 90 | + TEST_CHALK, |
| 91 | + screenWidth |
| 92 | + ); |
72 | 93 |
|
73 | 94 | let string = ''; |
74 | 95 | await transformContentsStreaming( |
|
0 commit comments