Skip to content

Commit 9396a2d

Browse files
committed
Fortnite Test
1 parent 02b10e3 commit 9396a2d

4 files changed

Lines changed: 57 additions & 6 deletions

File tree

Tests/WorkflowTests/OneJS.WorkflowTests.asmdef

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"references": [
55
"UnityEngine.TestRunner",
66
"UnityEditor.TestRunner",
7-
"OneJS.Runtime"
7+
"OneJS.Runtime",
8+
"OneJS.Samples",
9+
"com.tencent.puerts.core"
810
],
911
"includePlatforms": [],
1012
"excludePlatforms": [],

Tests/WorkflowTests/WorkflowTests.cs

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using UnityEngine.TestTools;
1010
using UnityEngine.UIElements;
1111
using System.Runtime.InteropServices;
12+
using OneJS.Samples;
1213
using Object = UnityEngine.Object;
1314

1415
namespace OneJS.CI {
@@ -18,6 +19,7 @@ public class WorkflowTests {
1819
static ScriptEngine _scriptEngine;
1920
static Bundler _bundler;
2021
static Runner _runner;
22+
static SampleCharacter _sampleCharacter;
2123

2224
// May consider using `Application.logMessageReceived += Catch` for log catching
2325
// Also note that WaitForEndOfFrame is not supported in batchmode (CI)
@@ -34,21 +36,28 @@ public static void OneTimeSetUp() {
3436
_mainCamera = cameraGO.AddComponent<Camera>();
3537
var prefab = LoadFromGUID<GameObject>("f99b6aec6fc021f4c9572906776c6555");
3638
prefab.SetActive(false);
37-
var go = Object.Instantiate(prefab);
39+
var scriptEngineGO = Object.Instantiate(prefab);
3840
prefab.SetActive(true);
3941

40-
_scriptEngine = go.GetComponent<ScriptEngine>();
41-
_bundler = go.GetComponent<Bundler>();
42-
_runner = go.GetComponent<Runner>();
42+
_scriptEngine = scriptEngineGO.GetComponent<ScriptEngine>();
43+
_bundler = scriptEngineGO.GetComponent<Bundler>();
44+
_runner = scriptEngineGO.GetComponent<Runner>();
4345

4446
_scriptEngine.editorWorkingDirInfo.relativePath = TMP_TEST_WORKING_DIR;
4547
_scriptEngine.playerWorkingDirInfo.relativePath = TMP_TEST_WORKING_DIR;
48+
49+
var samGO = new GameObject("Sample Character");
50+
_sampleCharacter = samGO.AddComponent<SampleCharacter>();
51+
_scriptEngine.OnPostInit += (jsEnv) => {
52+
_scriptEngine.AddToGlobal("sam", _sampleCharacter);
53+
};
4654
}
4755

4856
[OneTimeTearDown]
4957
public static void OneTimeTearDown() {
5058
Object.DestroyImmediate(_scriptEngine.gameObject);
5159
Object.DestroyImmediate(_mainCamera.gameObject);
60+
Object.DestroyImmediate(_sampleCharacter.gameObject);
5261

5362
Directory.Delete(_scriptEngine.WorkingDir, true);
5463
}
@@ -91,6 +100,35 @@ public IEnumerator WorkflowTest() {
91100
yield return null;
92101
}
93102

103+
[UnityTest]
104+
public IEnumerator FortniteTest() {
105+
LogAssert.Expect(LogType.Log, new Regex("OneJS is good to go"));
106+
_scriptEngine.gameObject.SetActive(true);
107+
_runner.enabled = false;
108+
yield return null;
109+
yield return null;
110+
111+
RunCommand($"npm run setup && npx postcss input.css -o ../Assets/tailwind.uss");
112+
RunCommand($"npm install fortnite-sample");
113+
yield return null;
114+
var twss = AssetDatabase.LoadAssetAtPath<StyleSheet>("Assets/tailwind.uss");
115+
_scriptEngine.styleSheets = new[] { _scriptEngine.styleSheets[0], twss };
116+
yield return null;
117+
118+
WriteContent("b17b25d1b82a4af2a3eb62785de08671");
119+
BuildAndReload();
120+
121+
yield return null;
122+
yield return null;
123+
124+
var uiDoc = _scriptEngine.GetComponent<UIDocument>();
125+
var root = uiDoc.rootVisualElement;
126+
var allNodes = root.Query().ToList();
127+
Assert.AreEqual(76, allNodes.Count, "Node Count mismatch");
128+
129+
yield return null;
130+
}
131+
94132
#if ONEJS_CI_GAME_UI
95133
[UnityTest]
96134
public IEnumerator GameUIsTest() {
@@ -176,4 +214,4 @@ private static void RunCommand(string command) {
176214
#endregion
177215
}
178216
}
179-
#endif
217+
#endif
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { h, render } from "preact"
2+
import { FortniteSample } from "fortnite-sample"
3+
4+
const App = () => {
5+
return <FortniteSample />
6+
}
7+
8+
render(<App />, document.body)

Tests/WorkflowTests/fortnite-test.tsx.txt.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)