Skip to content

Commit 195e688

Browse files
committed
test: hasNativeTSSupport mock test
1 parent 06dcaf0 commit 195e688

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

packages/rspeedy/core/src/config/loadConfig.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,7 @@ function isJavaScriptPath(configPath: string): boolean {
178178
const ext = extname(configPath)
179179
return ['.js', '.mjs', '.cjs'].includes(ext)
180180
}
181+
182+
export function TEST_ONLY_hasNativeTSSupport(): boolean {
183+
return hasNativeTSSupport()
184+
}

packages/rspeedy/core/test/config/loadConfig.test.ts

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ import { mkdtemp, writeFile } from 'node:fs/promises'
55
import { tmpdir } from 'node:os'
66
import { 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'
1114
import type { Config } from '../../src/index.js'
1215

1316
describe('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

Comments
 (0)