1
1
import fs from 'fs'
2
- import { join } from 'path'
2
+ import path from 'path'
3
3
4
- import { Logger , LogLevels } from 'bs-logger'
4
+ import { LogLevels } from 'bs-logger'
5
5
import { removeSync , writeFileSync } from 'fs-extra'
6
6
7
7
import { createConfigSet } from './__helpers__/fakers'
8
8
import { logTargetMock } from './__helpers__/mocks'
9
9
import { SOURCE_MAPPING_PREFIX } from './compiler/compiler-utils'
10
- import { TsCompiler } from './compiler/ts-compiler'
11
10
import { TsJestCompiler } from './compiler/ts-jest-compiler'
12
- import { ConfigSet } from './config/config-set'
13
11
import { CACHE_KEY_EL_SEPARATOR , TsJestTransformer } from './ts-jest-transformer'
14
- import type { DepGraphInfo , ProjectConfigTsJest , StringMap } from './types'
12
+ import type { DepGraphInfo } from './types'
15
13
import { stringify } from './utils/json'
16
14
import { sha1 } from './utils/sha1'
17
- import { VersionCheckers } from './utils/version-checkers'
18
15
19
16
const 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
21
26
22
27
beforeEach ( ( ) => {
23
28
logTarget . clear ( )
@@ -36,16 +41,16 @@ describe('TsJestTransformer', () => {
36
41
37
42
// @ts -expect-error testing purpose
38
43
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
+ `)
49
54
} )
50
55
51
56
test (
@@ -124,7 +129,7 @@ Array [
124
129
fileContent : 'const foo = 1' ,
125
130
resolvedModuleNames : [ ] ,
126
131
} )
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 ) )
128
133
fs . mkdirSync ( tsCacheDir , { recursive : true } )
129
134
writeFileSync ( resolvedModulesCacheDir , stringify ( [ ...depGraphs ] ) )
130
135
@@ -262,7 +267,7 @@ Array [
262
267
test ( 'should be different with non existed imported modules' , ( ) => {
263
268
jest
264
269
. spyOn ( TsJestCompiler . prototype , 'getResolvedModules' )
265
- . mockReturnValueOnce ( [ join ( process . cwd ( ) , 'src' , '__mocks__' , 'thing.ts' ) ] )
270
+ . mockReturnValueOnce ( [ path . join ( process . cwd ( ) , 'src' , '__mocks__' , 'thing.ts' ) ] )
266
271
267
272
const cacheKey1 = tr . getCacheKey ( input . fileContent , input . fileName , transformOptionsWithCache )
268
273
@@ -280,14 +285,6 @@ Array [
280
285
} )
281
286
282
287
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
291
288
let tr ! : TsJestTransformer
292
289
293
290
beforeEach ( ( ) => {
@@ -435,63 +432,4 @@ Array [
435
432
}
436
433
} )
437
434
} )
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
- } )
497
435
} )
0 commit comments