11/* eslint-disable testing-library/no-node-access */
22/* eslint-disable testing-library/no-container */
3- import { promises as fs } from 'fs' ;
3+ import { promises as fs , globSync } from 'fs' ;
44import path from 'path' ;
55
66// eslint-disable-next-line testing-library/no-manual-cleanup
7- import { render , screen , cleanup } from '@testing-library/react' ;
8- import { globSync } from 'glob ' ;
7+ import { cleanup , render , screen } from '@testing-library/react' ;
8+ import { beforeAll , beforeEach , describe , expect , it , vi , test } from 'vitest ' ;
99
1010import syntaxHighlighter , { uppercase , canonical } from '../src' ;
1111
@@ -51,6 +51,7 @@ test('should work with modes', () => {
5151} ) ;
5252
5353test ( 'should keep trailing json bracket if highlightMode is enabled' , ( ) => {
54+ // @ts -expect-error this component's types are currently ill-defined
5455 render ( syntaxHighlighter ( '{ "a": 1 }' , 'json' , { highlightMode : true } ) ) ;
5556
5657 expect ( screen . getByTestId ( 'CodeMirror' ) . outerHTML ) . toBe (
@@ -59,27 +60,32 @@ test('should keep trailing json bracket if highlightMode is enabled', () => {
5960} ) ;
6061
6162test ( 'should have a dark theme' , ( ) => {
63+ // @ts -expect-error this component's types are currently ill-defined
6264 render ( syntaxHighlighter ( '{ "a": 1 }' , 'json' , { dark : true } ) ) ;
6365 expect ( screen . getByTestId ( 'SyntaxHighlighter' ) ) . toHaveClass ( 'cm-s-material-palenight' ) ;
6466} ) ;
6567
6668describe ( 'variable substitution' , ( ) => {
6769 it ( 'should tokenize variables (double quotes)' , ( ) => {
70+ // @ts -expect-error this component's types are currently ill-defined
6871 render ( syntaxHighlighter ( '"<<apiKey>>"' , 'json' , { tokenizeVariables : true } ) ) ;
6972 expect ( screen . getByText ( 'APIKEY' ) ) . toBeVisible ( ) ;
7073 } ) ;
7174
7275 it ( 'should tokenize variables (single quotes)' , ( ) => {
76+ // @ts -expect-error this component's types are currently ill-defined
7377 render ( syntaxHighlighter ( "'<<apiKey>>'" , 'json' , { tokenizeVariables : true } ) ) ;
7478 expect ( screen . getByText ( 'APIKEY' ) ) . toBeVisible ( ) ;
7579 } ) ;
7680
7781 it ( 'should keep enclosing characters around the variable' , ( ) => {
82+ // @ts -expect-error this component's types are currently ill-defined
7883 render ( syntaxHighlighter ( "'<<apiKey>>'" , 'json' , { tokenizeVariables : true } ) ) ;
7984 expect ( screen . getByTestId ( 'SyntaxHighlighter' ) ) . toHaveTextContent ( "'APIKEY'" ) ;
8085 } ) ;
8186
8287 it ( 'should tokenize variables outside of quotes' , ( ) => {
88+ // @ts -expect-error this component's types are currently ill-defined
8389 render ( syntaxHighlighter ( '<<apiKey>>' , 'json' , { tokenizeVariables : true } ) ) ;
8490 expect ( screen . getByText ( 'APIKEY' ) ) . toBeVisible ( ) ;
8591 } ) ;
@@ -92,38 +98,45 @@ describe('variable substitution', () => {
9298 fetch({ foo, bar, baz: <<token>> });
9399 ` ;
94100
101+ // @ts -expect-error this component's types are currently ill-defined
95102 render ( syntaxHighlighter ( codeBlock , 'json' , { tokenizeVariables : true } ) ) ;
96103 expect ( screen . getByTestId ( 'SyntaxHighlighter' ) . textContent ) . toMatchSnapshot ( ) ;
97104 } ) ;
98105
99106 it ( 'should tokenize multiple variables per line' , ( ) => {
107+ // @ts -expect-error this component's types are currently ill-defined
100108 render ( syntaxHighlighter ( '<<apiKey>> <<name>>' , 'json' , { tokenizeVariables : true } ) ) ;
101109 expect ( screen . getByTestId ( 'SyntaxHighlighter' ) ) . toHaveTextContent ( 'APIKEY NAME' ) ;
102110 } ) ;
103111
104112 it . each ( [ '\\<<wat>>' , '<<wat\\>>' , '\\<<wat\\>>' ] ) ( 'should NOT tokenize escaped variables %s' , code => {
113+ // @ts -expect-error this component's types are currently ill-defined
105114 render ( syntaxHighlighter ( code , 'json' , { tokenizeVariables : true } ) ) ;
106115 expect ( screen . getByTestId ( 'SyntaxHighlighter' ) ) . toHaveTextContent ( '<<wat>>' ) ;
107116 } ) ;
108117} ) ;
109118
110119describe ( 'variable substitution { mdx: true }' , ( ) => {
111120 it ( 'should tokenize variables (double quotes)' , ( ) => {
121+ // @ts -expect-error this component's types are currently ill-defined
112122 render ( syntaxHighlighter ( '"{user.apiKey}"' , 'json' , { tokenizeVariables : true } , { mdx : true } ) ) ;
113123 expect ( screen . getByText ( 'APIKEY' ) ) . toBeVisible ( ) ;
114124 } ) ;
115125
116126 it ( 'should tokenize variables (single quotes)' , ( ) => {
127+ // @ts -expect-error this component's types are currently ill-defined
117128 render ( syntaxHighlighter ( "'{user.apiKey}'" , 'json' , { tokenizeVariables : true } , { mdx : true } ) ) ;
118129 expect ( screen . getByText ( 'APIKEY' ) ) . toBeVisible ( ) ;
119130 } ) ;
120131
121132 it ( 'should keep enclosing characters around the variable' , ( ) => {
133+ // @ts -expect-error this component's types are currently ill-defined
122134 render ( syntaxHighlighter ( "'{user.apiKey}'" , 'json' , { tokenizeVariables : true } , { mdx : true } ) ) ;
123135 expect ( screen . getByTestId ( 'SyntaxHighlighter' ) ) . toHaveTextContent ( "'APIKEY'" ) ;
124136 } ) ;
125137
126138 it ( 'should tokenize variables outside of quotes' , ( ) => {
139+ // @ts -expect-error this component's types are currently ill-defined
127140 render ( syntaxHighlighter ( '{user.apiKey}' , 'json' , { tokenizeVariables : true } , { mdx : true } ) ) ;
128141 expect ( screen . getByText ( 'APIKEY' ) ) . toBeVisible ( ) ;
129142 } ) ;
@@ -136,6 +149,7 @@ describe('variable substitution { mdx: true }', () => {
136149 fetch({ foo, bar, baz: {user.token} });
137150 ` ;
138151
152+ // @ts -expect-error this component's types are currently ill-defined
139153 render ( syntaxHighlighter ( codeBlock , 'json' , { tokenizeVariables : true } , { mdx : true } ) ) ;
140154 expect ( screen . getByTestId ( 'SyntaxHighlighter' ) . textContent ) . toMatchInlineSnapshot ( `
141155 "
@@ -148,16 +162,19 @@ describe('variable substitution { mdx: true }', () => {
148162 } ) ;
149163
150164 it ( 'should tokenize multiple variables per line' , ( ) => {
165+ // @ts -expect-error this component's types are currently ill-defined
151166 render ( syntaxHighlighter ( '{user.apiKey} {user.name}' , 'json' , { tokenizeVariables : true } , { mdx : true } ) ) ;
152167 expect ( screen . getByTestId ( 'SyntaxHighlighter' ) ) . toHaveTextContent ( 'APIKEY NAME' ) ;
153168 } ) ;
154169
155170 it ( 'should not tokenize bracket style' , ( ) => {
171+ // @ts -expect-error this component's types are currently ill-defined
156172 render ( syntaxHighlighter ( '<<wat>>' , 'json' , { tokenizeVariables : true } , { mdx : true } ) ) ;
157173 expect ( screen . getByTestId ( 'SyntaxHighlighter' ) ) . toHaveTextContent ( '<<wat>>' ) ;
158174 } ) ;
159175
160176 it . each ( [ '\\{user.wat}' , '{user.wat\\}' , '\\{user.wat\\}' ] ) ( 'should NOT tokenize escaped variables %s' , code => {
177+ // @ts -expect-error this component's types are currently ill-defined
161178 render ( syntaxHighlighter ( code , 'json' , { tokenizeVariables : true } , { mdx : true } ) ) ;
162179 expect ( screen . getByTestId ( 'SyntaxHighlighter' ) ) . toHaveTextContent ( '{user.wat}' ) ;
163180 } ) ;
@@ -169,9 +186,9 @@ describe('Supported languages', () => {
169186 } ) ;
170187
171188 describe . each ( languages ) ( '%s' , ( language , fixtureDir ) => {
172- let testCase ;
189+ let testCase : string ;
173190
174- // eslint-disable-next-line global-require, import/no-dynamic-require
191+ // eslint-disable-next-line global-require, import/no-dynamic-require, @typescript-eslint/no-require-imports
175192 const instructions = require ( path . join ( fixtureDir , 'index.js' ) ) ;
176193
177194 beforeEach ( async ( ) => {
@@ -253,6 +270,7 @@ describe('highlight mode', () => {
253270 render (
254271 syntaxHighlighter ( code , 'curl' , {
255272 dark : true ,
273+ // @ts -expect-error this component's types are currently ill-defined
256274 highlightMode : true ,
257275 tokenizeVariables : true ,
258276 ranges : [
@@ -293,6 +311,7 @@ describe('runmode', () => {
293311 render (
294312 syntaxHighlighter ( code , 'c' , {
295313 dark : true ,
314+ // @ts -expect-error this component's types are currently ill-defined
296315 highlightMode : true ,
297316 tokenizeVariables : true ,
298317 ranges : [
@@ -315,9 +334,12 @@ describe('code folding', () => {
315334 document . createRange = ( ) => {
316335 const range = new Range ( ) ;
317336
318- range . getBoundingClientRect = jest . fn ( ) ;
337+ // eslint-disable-next-line @vitest/require-mock-type-parameters
338+ range . getBoundingClientRect = vi . fn ( ) ;
319339
320- range . getClientRects = jest . fn ( ( ) => ( {
340+ // @ts -expect-error this component's types are currently ill-defined
341+ // eslint-disable-next-line @vitest/require-mock-type-parameters
342+ range . getClientRects = vi . fn ( ( ) => ( {
321343 item : ( ) => null ,
322344 length : 0 ,
323345 } ) ) ;
@@ -328,6 +350,7 @@ describe('code folding', () => {
328350
329351 it ( 'renders folders in the gutter' , ( ) => {
330352 const { container } = render (
353+ // @ts -expect-error this component's types are currently ill-defined
331354 syntaxHighlighter ( '{ "a": { "b": { "c": 1 } }' , 'json' , { foldGutter : true , readOnly : true } ) ,
332355 ) ;
333356
0 commit comments