Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
<PackageVersion Include="Flurl.Http.Signed" Version="4.0.2" />
<PackageVersion Include="GitHubActionsTestLogger" Version="3.0.5" />
<PackageVersion Include="ICU4N" Version="60.1.0-alpha.440" />
<PackageVersion Include="Meziantou.Analyzer" Version="3.0.156" />
<PackageVersion Include="Meziantou.Analyzer" Version="3.0.167" />
<PackageVersion Include="Microsoft.ClearScript.V8" Version="7.5.1" />
<PackageVersion Include="Microsoft.ClearScript.V8.Native.win-x64" Version="7.5.1" />
<PackageVersion Include="Microsoft.ClearScript.V8.Native.linux-x64" Version="7.5.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="5.6.0" PrivateAssets="all" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="5.6.0" PrivateAssets="all" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="5.9.0" PrivateAssets="all" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="5.9.0" PrivateAssets="all" />
<PackageVersion Include="Verify.SourceGenerators" Version="2.5.0" />
<PackageVersion Include="Verify.NUnit" Version="31.28.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="10.0.11" />
Expand All @@ -33,11 +33,11 @@
<PackageVersion Include="SharpZipLib" Version="1.4.2" />
<PackageVersion Include="SourceMaps" Version="0.3.0" />
<PackageVersion Include="Spectre.Console.Cli" Version="0.55.0" />
<PackageVersion Include="System.Text.Json" Version="10.0.10" />
<PackageVersion Include="Test262Harness" Version="1.1.1" />
<PackageVersion Include="xunit.v3.mtp-off" Version="3.2.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.5" PrivateAssets="all" />
<PackageVersion Include="YantraJS.Core" Version="1.2.422" />
<PackageVersion Include="System.Text.Json" Version="10.0.11" />
<PackageVersion Include="Test262Harness" Version="1.1.2" />
<PackageVersion Include="xunit.v3.mtp-off" Version="4.0.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="4.0.0" PrivateAssets="all" />
<PackageVersion Include="YantraJS.Core" Version="1.2.462" />
<PackageVersion Include="Zio" Version="0.24.0" />
</ItemGroup>
<ItemGroup>
Expand Down
33 changes: 22 additions & 11 deletions Jint.Tests/Runtime/EngineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1233,38 +1233,49 @@ public void ShouldParseAsLocalTime(string date)
result.Should().Be(msPriorMidnight);
}

/// <summary>
/// Wall-clock readings in the Pacific zone, carried as text rather than as <see cref="DateTime"/>.
/// xUnit serializes a theory's <see cref="DateTime"/> argument through <see cref="DateTime.ToUniversalTime"/>,
/// which reinterprets a <see cref="DateTimeKind.Unspecified"/> value as the runner machine's local time and
/// shifts it, so the value arriving here would depend on where the suite ran.
/// </summary>
public static System.Collections.Generic.IEnumerable<object[]> TestDates
{
get
{
yield return [new DateTime(2000, 1, 1)];
yield return [new DateTime(2000, 1, 1, 0, 15, 15, 15)];
yield return [new DateTime(2000, 6, 1, 0, 15, 15, 15)];
yield return [new DateTime(1900, 1, 1)];
yield return [new DateTime(1900, 1, 1, 0, 15, 15, 15)];
yield return [new DateTime(1900, 6, 1, 0, 15, 15, 15)];
yield return ["2000-01-01T00:00:00.000"];
yield return ["2000-01-01T00:15:15.015"];
yield return ["2000-06-01T00:15:15.015"];
yield return ["1900-01-01T00:00:00.000"];
yield return ["1900-01-01T00:15:15.015"];
yield return ["1900-06-01T00:15:15.015"];
}
}

[Theory, MemberData("TestDates")]
public void TestDateToISOStringFormat(DateTime testDate)
private static DateTime ParseTestDate(string testDate)
=> DateTime.ParseExact(testDate, "yyyy-MM-dd'T'HH:mm:ss.fff", CultureInfo.InvariantCulture);

[Theory, MemberData(nameof(TestDates))]
public void TestDateToISOStringFormat(string testDate)
{
var customTimeZone = _pacificTimeZone;

var engine = new Engine(ctx => ctx.LocalTimeZone(customTimeZone));
var testDateTimeOffset = new DateTimeOffset(testDate, customTimeZone.GetUtcOffset(testDate));
var date = ParseTestDate(testDate);
var testDateTimeOffset = new DateTimeOffset(date, customTimeZone.GetUtcOffset(date));
engine.Execute(
string.Format("var d = new Date({0},{1},{2},{3},{4},{5},{6});", testDateTimeOffset.Year, testDateTimeOffset.Month - 1, testDateTimeOffset.Day, testDateTimeOffset.Hour, testDateTimeOffset.Minute, testDateTimeOffset.Second, testDateTimeOffset.Millisecond));
engine.Evaluate("d.toISOString();").ToString().Should().Be(testDateTimeOffset.UtcDateTime.ToString("yyyy-MM-dd'T'HH:mm:ss.fff'Z'", CultureInfo.InvariantCulture));
}

[Theory, MemberData(nameof(TestDates))]
public void TestDateToStringFormat(DateTime testDate)
public void TestDateToStringFormat(string testDate)
{
var customTimeZone = _pacificTimeZone;

var engine = new Engine(ctx => ctx.LocalTimeZone(customTimeZone));
var dt = new DateTimeOffset(testDate, customTimeZone.GetUtcOffset(testDate));
var date = ParseTestDate(testDate);
var dt = new DateTimeOffset(date, customTimeZone.GetUtcOffset(date));
var dateScript = $"var d = new Date({dt.Year}, {dt.Month - 1}, {dt.Day}, {dt.Hour}, {dt.Minute}, {dt.Second}, {dt.Millisecond});";
engine.Execute(dateScript);

Expand Down
6 changes: 5 additions & 1 deletion Jint.Tests/Runtime/GeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ public void YieldInForLoopUpdateExpression()
return str;
""";

_engine.Evaluate(Script).Should().Be("01234");
// A regression here spins forever, and xUnit's Timeout cannot abort a synchronous test method on
// its own. Handing the engine the test's cancellation token is what makes the timeout bite.
var engine = new Engine(options => options.CancellationToken(TestContext.Current.CancellationToken));

engine.Evaluate(Script).Should().Be("01234");
}

[Fact]
Expand Down