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
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@
using System.Linq;
using JEngine.Core.Encrypt;
using UnityEditor;
using UnityEditor.Search;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
using ObjectField = UnityEditor.UIElements.ObjectField;

namespace JEngine.Core.Editor.CustomEditor
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "JEngine.Core.Editor",
"rootNamespace": "",
"rootNamespace": "JEngine.Core",
"references": [
"GUID:ba02d1bbd77cf4a0c8606d3e5cbbbe79",
"GUID:2373f786d14518f44b0f475db77ba4de",
Expand All @@ -10,7 +10,8 @@
"GUID:6055be8ebefd69e48b49212b09b47b2f",
"GUID:f51ebe6a0ceec4240a699833d6309b23",
"GUID:e34a5702dd353724aa315fb8011f08c3",
"GUID:3743e71edcd5bd8499007797ef02cbfb"
"GUID:3743e71edcd5bd8499007797ef02cbfb",
"GUID:27619889b8ba8c24980f49ee34dbb44a"
],
"includePlatforms": [
"Editor"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ internal static class ChangeScene
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
private static void DoChange()
{
// Skip scene change when running Play Mode tests
if (TestRunnerCallbacks.IsRunningTests)
{
return;
}

var jump = Settings.Instance.jumpStartUp;
if (!jump) return;
var scene = SceneManager.GetActiveScene();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using UnityEditor;
using UnityEditor.TestTools.TestRunner.Api;
using UnityEngine;

namespace JEngine.Core.Editor.Misc
{
/// <summary>
/// Tracks Unity Test Runner state to allow other systems to detect when tests are running
/// </summary>
[InitializeOnLoad]
internal class TestRunnerCallbacks : ICallbacks
{
private const string SessionStateKey = "JEngine.TestRunnerCallbacks.IsRunningTests";

private static volatile bool _isRunningTests;

/// <summary>
/// Returns true when tests are currently running
/// </summary>
public static bool IsRunningTests
{
get => _isRunningTests;
private set
{
_isRunningTests = value;
// Persist to SessionState to survive domain reloads during test execution
SessionState.SetBool(SessionStateKey, value);
}
}

private static readonly TestRunnerCallbacks _instance = new TestRunnerCallbacks();
private static TestRunnerApi _api;

static TestRunnerCallbacks()
{
// Restore state after domain reload (e.g., recompilation during test run)
_isRunningTests = SessionState.GetBool(SessionStateKey, false);

_api = ScriptableObject.CreateInstance<TestRunnerApi>();
_api.RegisterCallbacks(_instance);
EditorApplication.quitting += OnEditorQuitting;
}

private static void OnEditorQuitting()
{
EditorApplication.quitting -= OnEditorQuitting;

if (_api != null)
{
_api.UnregisterCallbacks(_instance);
Object.Destroy(_api);
_api = null;
}

// Clear session state on quit
SessionState.EraseBool(SessionStateKey);
}

public void RunStarted(ITestAdaptor testsToRun)
{
IsRunningTests = true;
}

public void RunFinished(ITestResultAdaptor result)
{
IsRunningTests = false;
}

// Required by ICallbacks interface but not needed - we only track overall run state
public void TestStarted(ITestAdaptor test) { }

// Required by ICallbacks interface but not needed - we only track overall run state
public void TestFinished(ITestResultAdaptor result) { }
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "JEngine.Core",
"rootNamespace": "",
"rootNamespace": "JEngine.Core",
"references": [
"GUID:4140bd2e2764f1f47ab93125ecb61942",
"GUID:13ba8ce62aa80c74598530029cb2d649",
Expand Down