@@ -18,47 +18,75 @@ import L10nServiceProvider from '@scope/l10n-service-provider'
18
18
const PROCESS_CWD_TARGET_PATH = path . resolve ( __dirname )
19
19
20
20
let orgCwd // for process.cwd mock
21
+ let orgExit // for process.exit mock
21
22
let spyLog
22
23
let spyError
23
24
beforeEach ( ( ) => {
24
25
spyLog = jest . spyOn ( global . console , 'log' )
25
26
spyError = jest . spyOn ( global . console , 'error' )
26
27
orgCwd = process . cwd
27
28
process . cwd = jest . fn ( ( ) => PROCESS_CWD_TARGET_PATH ) // mock: process.cwd
29
+ process . exit = jest . fn ( ( code => { return 'exit!' as never } ) ) // mock: process.exit
28
30
} )
29
31
30
32
afterEach ( ( ) => {
31
33
spyError . mockRestore ( )
32
34
spyLog . mockRestore ( )
33
35
jest . clearAllMocks ( )
36
+ process . exit = orgExit
34
37
process . cwd = orgCwd
35
38
} )
36
39
37
40
// -----------
38
41
// test cases
39
42
40
43
test ( 'require options' , async ( ) => {
44
+ // run
45
+ const status = await import ( '../../src/commands/status' )
46
+ const cmd = yargs . command ( status )
47
+ await new Promise ( ( resolve , reject ) => {
48
+ cmd . parse ( `status` , ( err , argv , output ) => {
49
+ err ? reject ( err ) : resolve ( output )
50
+ } )
51
+ } )
52
+
53
+ // verify
54
+ expect ( spyError ) . toBeCalled ( )
55
+ expect ( process . exit ) . toHaveBeenCalledWith ( 1 )
56
+ } )
57
+
58
+ test ( 'getTranslationStatus: done' , async ( ) => {
59
+ // setup mocking ...
60
+ const mockStatusValue = [ {
61
+ locale : 'en' ,
62
+ percentage : 100
63
+ } , {
64
+ locale : 'ja' ,
65
+ percentage : 100
66
+ } ]
67
+ mockStatus . mockImplementation ( ( { locales } ) => Promise . resolve ( mockStatusValue ) )
68
+
69
+ // run
41
70
const status = await import ( '../../src/commands/status' )
42
71
const cmd = yargs . command ( status )
43
- try {
44
- await new Promise ( ( resolve , reject ) => {
45
- cmd . parse ( `status` , ( err , argv , output ) => {
46
- err ? reject ( err ) : resolve ( output )
47
- } )
72
+ await new Promise ( ( resolve , reject ) => {
73
+ cmd . parse ( `status --provider=@scope/l10n-service-provider` , ( err , argv , output ) => {
74
+ err ? reject ( err ) : resolve ( output )
48
75
} )
49
- } catch ( e ) {
50
- expect ( e ) . toMatchObject ( { name : 'YError' } )
51
- }
76
+ } )
77
+
78
+ // verify
79
+ expect ( process . exit ) . not . toBeCalled ( )
52
80
} )
53
81
54
- test ( 'getTranslationStatus: success ' , async ( ) => {
55
- // setup mocks
82
+ test ( 'getTranslationStatus: wip ' , async ( ) => {
83
+ // setup mocking ...
56
84
const mockStatusValue = [ {
57
85
locale : 'en' ,
58
- percentage : 24.2
86
+ percentage : 72.4
59
87
} , {
60
88
locale : 'ja' ,
61
- percentage : 100.0
89
+ percentage : 100
62
90
} ]
63
91
mockStatus . mockImplementation ( ( { locales } ) => Promise . resolve ( mockStatusValue ) )
64
92
@@ -70,4 +98,8 @@ test('getTranslationStatus: success', async () => {
70
98
err ? reject ( err ) : resolve ( output )
71
99
} )
72
100
} )
101
+
102
+ // verify
103
+ // NOTE: cannot detect process.exit calling ...
104
+ // expect(process.exit).toHaveBeenCalledWith(1)
73
105
} )
0 commit comments