1
+ import * as fs from 'fs' ;
1
2
import * as _ from 'lodash' ;
3
+ import { join } from 'path' ;
4
+ import * as proxyquire from 'proxyquire' ;
2
5
import * as sinon from 'sinon' ;
3
6
import { ChromeDebugAdapter } from 'vscode-chrome-debug-core' ;
4
7
import { Event } from 'vscode-debugadapter' ;
5
8
import * as extProtocol from '../common/extensionProtocol' ;
6
- import { NativeScriptDebugAdapter } from '../debug-adapter/nativeScriptDebugAdapter' ;
9
+ const appRoot = 'appRootMock' ;
10
+ const webpackConfigFunctionStub = sinon . stub ( ) ;
11
+
12
+ proxyquire . noCallThru ( ) ;
13
+ const nativeScriptDebugAdapterLib = proxyquire ( '../debug-adapter/nativeScriptDebugAdapter' , {
14
+ [ join ( appRoot , 'webpack.config.js' ) ] : webpackConfigFunctionStub ,
15
+ } ) ;
7
16
8
17
const examplePort = 456 ;
9
18
@@ -17,7 +26,7 @@ const customMessagesResponses = {
17
26
} ;
18
27
19
28
const defaultArgsMock : any = {
20
- appRoot : 'appRootMock' ,
29
+ appRoot,
21
30
diagnosticLogging : true ,
22
31
platform : 'android' ,
23
32
request : 'attach' ,
@@ -67,7 +76,7 @@ describe('NativeScriptDebugAdapter', () => {
67
76
setTransformOptions : ( ) => undefined ,
68
77
} ;
69
78
70
- nativeScriptDebugAdapter = new NativeScriptDebugAdapter ( {
79
+ nativeScriptDebugAdapter = new nativeScriptDebugAdapterLib . NativeScriptDebugAdapter ( {
71
80
chromeConnection : mockConstructor ( chromeConnectionMock ) ,
72
81
pathTransformer : mockConstructor ( pathTransformerMock ) ,
73
82
sourceMapTransformer : mockConstructor ( sourceMapTransformer ) ,
@@ -83,7 +92,11 @@ describe('NativeScriptDebugAdapter', () => {
83
92
84
93
platforms . forEach ( ( platform ) => {
85
94
launchMethods . forEach ( ( method ) => {
86
- const argsMock = _ . merge ( { } , defaultArgsMock , { platform, request : method } ) ;
95
+ let argsMock : any ;
96
+
97
+ beforeEach ( ( ) => {
98
+ argsMock = _ . merge ( { } , defaultArgsMock , { platform, request : method } ) ;
99
+ } ) ;
87
100
88
101
it ( `${ method } for ${ platform } should raise debug start event` , async ( ) => {
89
102
const spy = sinon . spy ( chromeSessionMock , 'sendEvent' ) ;
@@ -121,7 +134,51 @@ describe('NativeScriptDebugAdapter', () => {
121
134
122
135
sinon . assert . calledWith ( spy , sinon . match ( {
123
136
trace : true ,
124
- webRoot : 'appRootMock' ,
137
+ webRoot : appRoot ,
138
+ } ) ) ;
139
+ } ) ;
140
+
141
+ it ( `${ method } for ${ platform } should add sourceMapPathOverrides data` , async ( ) => {
142
+ const spy = sinon . spy ( ChromeDebugAdapter . prototype , 'attach' ) ;
143
+ const existsSyncStub = sinon . stub ( fs , 'existsSync' ) ;
144
+
145
+ existsSyncStub . returns ( true ) ;
146
+ webpackConfigFunctionStub
147
+ . withArgs ( { [ platform ] : platform } )
148
+ . returns ( { output : { library : 'myLib' } } ) ;
149
+
150
+ await nativeScriptDebugAdapter [ method ] ( argsMock ) ;
151
+
152
+ existsSyncStub . restore ( ) ;
153
+ sinon . assert . calledWith ( spy , sinon . match ( {
154
+ sourceMapPathOverrides : {
155
+ 'webpack:///*' : `${ join ( appRoot , 'app' ) } /*` ,
156
+ 'webpack://myLib/*' : `${ join ( appRoot , 'app' ) } /*` ,
157
+ } ,
158
+ trace : true ,
159
+ webRoot : appRoot ,
160
+ } ) ) ;
161
+
162
+ } ) ;
163
+
164
+ it ( `${ method } for ${ platform } should not fail when unable to require webpack.config.js` , async ( ) => {
165
+ const spy = sinon . spy ( ChromeDebugAdapter . prototype , 'attach' ) ;
166
+ const existsSyncStub = sinon . stub ( fs , 'existsSync' ) ;
167
+
168
+ existsSyncStub . returns ( true ) ;
169
+ webpackConfigFunctionStub
170
+ . withArgs ( { [ platform ] : platform } )
171
+ . throws ( new Error ( 'test' ) ) ;
172
+
173
+ await nativeScriptDebugAdapter [ method ] ( argsMock ) ;
174
+
175
+ existsSyncStub . restore ( ) ;
176
+ sinon . assert . calledWith ( spy , sinon . match ( {
177
+ sourceMapPathOverrides : {
178
+ 'webpack:///*' : `${ join ( appRoot , 'app' ) } /*` ,
179
+ } ,
180
+ trace : true ,
181
+ webRoot : appRoot ,
125
182
} ) ) ;
126
183
} ) ;
127
184
0 commit comments