99using UnityEngine . TestTools ;
1010using UnityEngine . UIElements ;
1111using System . Runtime . InteropServices ;
12+ using OneJS . Samples ;
1213using Object = UnityEngine . Object ;
1314
1415namespace 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
0 commit comments