1
1
import { AbstractCommand } from '../../../src/commands/abstract-command'
2
2
import { Resolver } from '../../../src/commands/resolver/resolver'
3
3
import * as fs from 'fs'
4
+ import * as fse from 'fs-extra'
4
5
5
- describe ( 'Resolver command test' , ( ) => {
6
+ //TODO - remove only
7
+ describe . only ( 'Resolver command test' , ( ) => {
6
8
let res : AbstractCommand
7
9
const pathToType = './test/commands/resolver/test-schema.ts'
8
10
const pathToActualResolver = './test/output/actual/test-resolver.ts'
11
+ const pathToDirectoryActualResolver = './test/output/actual/non/existing/dir/test-resolver.ts'
12
+ const resolverDirLocation = './test/output/actual/non'
9
13
const pathToExpectedResolver = './test/output/expected/commands/resolver/test-resolver.ts'
10
14
const pathToNonOverridenFile =
11
15
'./test/output/expected/commands/resolver/test-not-overriden-by-resolver.ts'
@@ -18,20 +22,39 @@ describe('Resolver command test', () => {
18
22
if ( fs . existsSync ( pathToActualResolver ) ) {
19
23
fs . unlinkSync ( pathToActualResolver )
20
24
}
25
+ fs . stat ( resolverDirLocation , ( err , stats ) => {
26
+ if ( ! err ) {
27
+ if ( stats . isDirectory ( ) ) {
28
+ fse . remove ( resolverDirLocation , err => {
29
+ console . log (
30
+ 'Could not remove resolver dir. On windows desktops, remove it manually...' ,
31
+ err
32
+ )
33
+ } )
34
+ }
35
+ }
36
+ } )
21
37
} )
22
38
23
39
it ( 'works if action returns a function' , ( ) => {
24
40
const act = res . getAction ( )
25
41
expect ( act ) . toBeInstanceOf ( Function )
26
42
} )
27
43
28
- it ( 'works if resolver file was generated' , async ( ) => {
44
+ it . only ( 'works if resolver file was generated' , async ( ) => {
29
45
const actFunction = res . getAction ( )
30
46
await actFunction ( pathToType , pathToActualResolver )
31
47
const resolverFileExist : boolean = fs . existsSync ( pathToActualResolver )
32
48
expect ( resolverFileExist ) . toBeTruthy ( )
33
49
} )
34
50
51
+ it ( 'works if resolver file was generated in directory structure' , async ( ) => {
52
+ const actFunction = res . getAction ( )
53
+ await actFunction ( pathToType , pathToDirectoryActualResolver )
54
+ const resolverFileExist : boolean = fs . existsSync ( pathToDirectoryActualResolver )
55
+ expect ( resolverFileExist ) . toBeTruthy ( )
56
+ } )
57
+
35
58
it ( 'works if resolver file is identical to expected file' , async ( ) => {
36
59
const actFunction = res . getAction ( )
37
60
await actFunction ( pathToType , pathToActualResolver )
@@ -46,6 +69,20 @@ describe('Resolver command test', () => {
46
69
expect ( actualContent ) . toEqual ( expectedContent )
47
70
} )
48
71
72
+ // it('works if resolver file is in dir and identical to expected', async () => {
73
+ // const actFunction = res.getAction()
74
+ // await actFunction(pathToType, pathToDirectoryActualResolver)
75
+ // const expectedContent = fs
76
+ // .readFileSync(pathToExpectedResolver)
77
+ // .toString()
78
+ // .replace(/\s/g, '')
79
+ // const actualContent = fs
80
+ // .readFileSync(pathToDirectoryActualResolver)
81
+ // .toString()
82
+ // .replace(/\s/g, '')
83
+ // expect(actualContent).toEqual(expectedContent)
84
+ // })
85
+
49
86
it ( 'works if resolver command does not override existing file' , async ( ) => {
50
87
const actFunction = res . getAction ( )
51
88
await actFunction ( pathToType , pathToNonOverridenFile )
0 commit comments