11import fs from 'fs'
2- import { join } from 'path'
2+ import path from 'path'
33
4- import { Logger , LogLevels } from 'bs-logger'
4+ import { LogLevels } from 'bs-logger'
55import { removeSync , writeFileSync } from 'fs-extra'
66
77import { createConfigSet } from './__helpers__/fakers'
88import { logTargetMock } from './__helpers__/mocks'
99import { SOURCE_MAPPING_PREFIX } from './compiler/compiler-utils'
10- import { TsCompiler } from './compiler/ts-compiler'
1110import { TsJestCompiler } from './compiler/ts-jest-compiler'
12- import { ConfigSet } from './config/config-set'
1311import { CACHE_KEY_EL_SEPARATOR , TsJestTransformer } from './ts-jest-transformer'
14- import type { DepGraphInfo , ProjectConfigTsJest , StringMap } from './types'
12+ import type { DepGraphInfo } from './types'
1513import { stringify } from './utils/json'
1614import { sha1 } from './utils/sha1'
17- import { VersionCheckers } from './utils/version-checkers'
1815
1916const logTarget = logTargetMock ( )
20- const cacheDir = join ( process . cwd ( ) , 'tmp' )
17+ const cacheDir = path . join ( process . cwd ( ) , 'tmp' )
18+ const baseTransformOptions = {
19+ config : {
20+ testMatch : [ ] ,
21+ testRegex : [ ] ,
22+ extensionsToTreatAsEsm : [ ] ,
23+ } ,
24+ cacheFS : new Map ( ) ,
25+ } as any // eslint-disable-line @typescript-eslint/no-explicit-any
2126
2227beforeEach ( ( ) => {
2328 logTarget . clear ( )
@@ -36,16 +41,16 @@ describe('TsJestTransformer', () => {
3641
3742 // @ts -expect-error testing purpose
3843 expect ( Object . keys ( TsJestTransformer . _cachedConfigSets [ 0 ] ) ) . toMatchInlineSnapshot ( `
39- Array [
40- "jestConfig",
41- "configSet",
42- "transformerCfgStr",
43- "compiler",
44- "depGraphs",
45- "tsResolvedModulesCachePath",
46- "watchMode",
47- ]
48- ` )
44+ Array [
45+ "jestConfig",
46+ "configSet",
47+ "transformerCfgStr",
48+ "compiler",
49+ "depGraphs",
50+ "tsResolvedModulesCachePath",
51+ "watchMode",
52+ ]
53+ `)
4954 } )
5055
5156 test (
@@ -124,7 +129,7 @@ Array [
124129 fileContent : 'const foo = 1' ,
125130 resolvedModuleNames : [ ] ,
126131 } )
127- const resolvedModulesCacheDir = join ( tsCacheDir , sha1 ( 'ts-jest-resolved-modules' , CACHE_KEY_EL_SEPARATOR ) )
132+ const resolvedModulesCacheDir = path . join ( tsCacheDir , sha1 ( 'ts-jest-resolved-modules' , CACHE_KEY_EL_SEPARATOR ) )
128133 fs . mkdirSync ( tsCacheDir , { recursive : true } )
129134 writeFileSync ( resolvedModulesCacheDir , stringify ( [ ...depGraphs ] ) )
130135
@@ -262,7 +267,7 @@ Array [
262267 test ( 'should be different with non existed imported modules' , ( ) => {
263268 jest
264269 . spyOn ( TsJestCompiler . prototype , 'getResolvedModules' )
265- . mockReturnValueOnce ( [ join ( process . cwd ( ) , 'src' , '__mocks__' , 'thing.ts' ) ] )
270+ . mockReturnValueOnce ( [ path . join ( process . cwd ( ) , 'src' , '__mocks__' , 'thing.ts' ) ] )
266271
267272 const cacheKey1 = tr . getCacheKey ( input . fileContent , input . fileName , transformOptionsWithCache )
268273
@@ -280,14 +285,6 @@ Array [
280285 } )
281286
282287 describe ( 'process' , ( ) => {
283- const baseTransformOptions = {
284- config : {
285- testMatch : [ ] ,
286- testRegex : [ ] ,
287- extensionsToTreatAsEsm : [ ] ,
288- } ,
289- cacheFS : new Map ( ) ,
290- } as any // eslint-disable-line @typescript-eslint/no-explicit-any
291288 let tr ! : TsJestTransformer
292289
293290 beforeEach ( ( ) => {
@@ -435,63 +432,4 @@ Array [
435432 }
436433 } )
437434 } )
438-
439- describe ( 'subclass extends TsJestTransformer' , ( ) => {
440- class MyTsCompiler extends TsCompiler {
441- constructor ( readonly configSet : ConfigSet , readonly runtimeCacheFS : StringMap ) {
442- super ( configSet , runtimeCacheFS )
443- }
444- }
445-
446- class MyConfigSet extends ConfigSet {
447- constructor ( readonly jestConfig : ProjectConfigTsJest , readonly parentLogger ?: Logger ) {
448- super ( jestConfig , parentLogger )
449- }
450- }
451-
452- class MyTransformer extends TsJestTransformer {
453- protected _createCompiler ( configSet : ConfigSet , cacheFS : StringMap ) : void {
454- this . _compiler = new MyTsCompiler ( configSet , cacheFS )
455- }
456-
457- // eslint-disable-next-line class-methods-use-this
458- protected _createConfigSet ( config : ProjectConfigTsJest ) : MyConfigSet {
459- return new MyConfigSet ( config )
460- }
461- }
462- let tr : MyTransformer
463-
464- beforeEach ( ( ) => {
465- tr = new MyTransformer ( )
466- } )
467-
468- test ( 'should have jest version checking' , ( ) => {
469- VersionCheckers . jest . warn = jest . fn ( )
470-
471- new MyTransformer ( )
472-
473- expect ( VersionCheckers . jest . warn ) . toHaveBeenCalled ( )
474- } )
475-
476- test ( 'should create MyTsCompiler instance' , ( ) => {
477- // @ts -expect-error testing purpose
478- tr . _createCompiler ( createConfigSet ( ) , new Map ( ) )
479-
480- // @ts -expect-error testing purpose
481- expect ( tr . _compiler ) . toBeInstanceOf ( MyTsCompiler )
482- } )
483-
484- test ( 'should create MyConfigSet instance' , ( ) => {
485- expect (
486- // @ts -expect-error testing purpose
487- tr . _createConfigSet ( {
488- cwd : process . cwd ( ) ,
489- extensionsToTreatAsEsm : [ ] ,
490- globals : Object . create ( null ) ,
491- testMatch : [ ] ,
492- testRegex : [ ] ,
493- } ) ,
494- ) . toBeInstanceOf ( MyConfigSet )
495- } )
496- } )
497435} )
0 commit comments