Skip to content

Commit a9afcce

Browse files
committed
Minor tweaks of tests
1 parent c75b012 commit a9afcce

File tree

2 files changed

+45
-30
lines changed

2 files changed

+45
-30
lines changed

test/JavaScriptEngineSwitcher.Tests/ChakraCore/CommonTests.cs

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -194,40 +194,56 @@ public void MappingRuntimeErrorDuringOutOfMemory()
194194
arr.push('Current date: ' + new Date());
195195
}";
196196

197-
JsRuntimeException exception = null;
198-
199197
// Act
200-
using (IJsEngine jsEngine = new ChakraCoreJsEngine(
201-
new ChakraCoreSettings
202-
{
203-
MemoryLimit = new UIntPtr(2 * 1024 * 1024)
204-
}
205-
))
198+
IJsEngine jsEngine = null;
199+
JsException exception = null;
200+
201+
try
206202
{
207-
try
208-
{
209-
jsEngine.Execute(input);
210-
}
211-
catch (JsRuntimeException e)
212-
{
213-
exception = e;
214-
}
203+
jsEngine = new ChakraCoreJsEngine(
204+
new ChakraCoreSettings
205+
{
206+
MemoryLimit = new UIntPtr(2 * 1024 * 1024)
207+
}
208+
);
209+
jsEngine.Execute(input);
210+
}
211+
catch (JsEngineException e)
212+
{
213+
exception = e;
214+
}
215+
catch (JsRuntimeException e)
216+
{
217+
exception = e;
218+
}
219+
finally
220+
{
221+
jsEngine?.Dispose();
215222
}
216223

217224
// Assert
218225
Assert.NotNull(exception);
219-
Assert.Equal("Runtime error", exception.Category);
220-
Assert.Equal("Out of memory", exception.Description);
226+
if (exception is JsRuntimeException)
227+
{
228+
Assert.Equal("Runtime error", exception.Category);
229+
Assert.Equal("Out of memory", exception.Description);
230+
}
231+
else if (exception is JsEngineException)
232+
{
233+
Assert.Equal("Engine load error", exception.Category);
234+
Assert.Equal("Out of memory.", exception.Description);
235+
}
221236
}
222237

223238
[Fact]
224239
public void MappingEngineLoadErrorDuringOutOfMemory()
225240
{
226241
// Arrange
242+
243+
// Act
227244
IJsEngine jsEngine = null;
228245
JsEngineLoadException exception = null;
229246

230-
// Act
231247
try
232248
{
233249
jsEngine = new ChakraCoreJsEngine(

test/JavaScriptEngineSwitcher.Tests/Yantra/ConsoleTests.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function calculateIncomeTax(salary) {
6363
;
6464

6565
// Act
66-
using (var jsEngine = CreateJsEngine(logger.Log))
66+
using (var jsEngine = CreateJsEngine(consoleCallback: logger.Log))
6767
{
6868
jsEngine.EmbedHostType("favoriteSchoolSubject", favoriteSchoolSubject);
6969
jsEngine.EmbedHostObject("wikipediaPageUrl", wikipediaPageUrl);
@@ -93,12 +93,12 @@ public void SupportsConsoleInfoMethod()
9393
console.info(driveLetter, 'drive has been formatted successfully!');";
9494

9595
// Act
96-
JsRuntimeException exception = null;
9796
IJsEngine jsEngine = null;
97+
JsRuntimeException exception = null;
9898

9999
try
100100
{
101-
jsEngine = CreateJsEngine(logger.Log);
101+
jsEngine = CreateJsEngine(consoleCallback: logger.Log);
102102
jsEngine.Execute(input);
103103
}
104104
catch (JsRuntimeException e)
@@ -128,13 +128,13 @@ public void SupportsConsoleWarnMethod()
128128
const string input = @"console.warn('Watch out, the doors are closing!');
129129
console.warn('Watch yourself,', 'be careful!');
130130
console.warn('It is forbidden to watch!');";
131-
string targetOutput = "warn: Watch out, the doors are closing!" + Environment.NewLine +
132-
"warn: Watch yourself, be careful!" + Environment.NewLine +
133-
"warn: It is forbidden to watch!" + Environment.NewLine
131+
string targetOutput = "warn: Watch out, the doors are closing!" + Environment.NewLine +
132+
"warn: Watch yourself, be careful!" + Environment.NewLine +
133+
"warn: It is forbidden to watch!" + Environment.NewLine
134134
;
135135

136136
// Act
137-
using (var jsEngine = CreateJsEngine(logger.Log))
137+
using (var jsEngine = CreateJsEngine(consoleCallback: logger.Log))
138138
{
139139
jsEngine.Execute(input);
140140
}
@@ -156,10 +156,10 @@ public void SupportsConsoleErrorMethod()
156156
var logger = new StringLogger(sb);
157157

158158
const string input = @"console.error('A terrible thing happened!');";
159-
string targetOutput = "error: A terrible thing happened!" + Environment.NewLine;
159+
string targetOutput = "error: A terrible thing happened!" + Environment.NewLine;
160160

161161
// Act
162-
using (var jsEngine = CreateJsEngine(logger.Log))
162+
using (var jsEngine = CreateJsEngine(consoleCallback: logger.Log))
163163
{
164164
jsEngine.Execute(input);
165165
}
@@ -188,8 +188,7 @@ public void Log(string type, object[] args)
188188
{
189189
if (type != "log")
190190
{
191-
_buffer.Append(type);
192-
_buffer.Append(": ");
191+
_buffer.AppendFormat("{0}: ", type);
193192
}
194193

195194
for (int argIndex = 0; argIndex < args.Length; argIndex++)

0 commit comments

Comments
 (0)