@@ -5,9 +5,12 @@ import { mkdtemp, writeFile } from 'node:fs/promises'
55import { tmpdir } from 'node:os'
66import { join } from 'node:path'
77
8- import { describe , expect , test } from 'vitest'
8+ import { beforeEach , describe , expect , test , vi } from 'vitest'
99
10- import { loadConfig } from '../../src/config/loadConfig.js'
10+ import {
11+ TEST_ONLY_hasNativeTSSupport as hasNativeTSSupport ,
12+ loadConfig ,
13+ } from '../../src/config/loadConfig.js'
1114import type { Config } from '../../src/index.js'
1215
1316describe ( 'Config - loadConfig' , ( ) => {
@@ -307,3 +310,57 @@ describe('Config - loadConfig', () => {
307310 } )
308311 } )
309312} )
313+
314+ describe ( 'hasNativeTSSupport' , ( ) => {
315+ const process : {
316+ env : Record < string , string >
317+ features : { typescript ?: false | 'strip' | 'transform' | undefined }
318+ } = {
319+ env : { } ,
320+ features : { } ,
321+ }
322+
323+ beforeEach ( ( ) => {
324+ process . env = { }
325+ process . features = { }
326+ vi . stubGlobal ( 'process' , process )
327+
328+ return ( ) => {
329+ vi . unstubAllGlobals ( )
330+ }
331+ } )
332+
333+ test ( 'without features.typescript' , ( ) => {
334+ expect ( hasNativeTSSupport ( ) ) . toBe ( false )
335+ } )
336+
337+ test ( 'with features.typescript: "transform"' , ( ) => {
338+ process . features . typescript = 'transform'
339+ expect ( hasNativeTSSupport ( ) ) . toBe ( true )
340+ } )
341+
342+ test ( 'with features.typescript: "strip"' , ( ) => {
343+ process . features . typescript = 'strip'
344+ expect ( hasNativeTSSupport ( ) ) . toBe ( true )
345+ } )
346+
347+ test ( 'with features.typescript: false' , ( ) => {
348+ process . features . typescript = false
349+ expect ( hasNativeTSSupport ( ) ) . toBe ( false )
350+ } )
351+
352+ test ( 'with features.typescript: undefined' , ( ) => {
353+ process . features . typescript = undefined
354+ expect ( hasNativeTSSupport ( ) ) . toBe ( false )
355+ } )
356+
357+ test ( 'with NODE_OPTIONS: --experimental-transform-types' , ( ) => {
358+ process . env [ 'NODE_OPTIONS' ] = '--experimental-transform-types'
359+ expect ( hasNativeTSSupport ( ) ) . toBe ( true )
360+ } )
361+
362+ test ( 'with NODE_OPTIONS: --experimental-strip-types' , ( ) => {
363+ process . env [ 'NODE_OPTIONS' ] = '--experimental-strip-types'
364+ expect ( hasNativeTSSupport ( ) ) . toBe ( true )
365+ } )
366+ } )
0 commit comments