Skip to content
This repository was archived by the owner on Nov 9, 2026. It is now read-only.

Commit 62818ee

Browse files
bghgaryCopilot
andauthored
Organize runtime tests by feature (#257)
[Created by Copilot on behalf of @bghgary] Native and JavaScript runtime tests for unrelated features were grouped together, making coverage hard to navigate. This change groups the existing tests by feature and packages the generated test bundle and fixtures together under `Assets`. The same tests continue to run through the existing runner. --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 68f925b commit 62818ee

62 files changed

Lines changed: 2816 additions & 2737 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/build-android.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ jobs:
6666
target: google_apis
6767
arch: x86_64
6868
emulator-options: -no-snapshot -no-window -no-boot-anim -no-audio
69-
script: chmod +x Tests/UnitTests/Android/gradlew && Tests/UnitTests/Android/gradlew -p Tests/UnitTests/Android connectedAndroidTest -PabiFilters=x86_64 -PjsEngine=${{ inputs.js-engine }} -PndkVersion=${{ env.NDK_VERSION }}
69+
script: chmod +x Tests/UnitTests/Source/Android/gradlew && Tests/UnitTests/Source/Android/gradlew -p Tests/UnitTests/Source/Android connectedAndroidTest -PabiFilters=x86_64 -PjsEngine=${{ inputs.js-engine }} -PndkVersion=${{ env.NDK_VERSION }}
7070

7171
- name: Dump Test Results
7272
if: always()
73-
working-directory: Tests/UnitTests/Android
73+
working-directory: Tests/UnitTests/Source/Android
7474
run: |
7575
find ./app/build/outputs/androidTest-results -name "*.txt" -print0 | while IFS= read -r -d '' file; do
7676
echo "cat \"$file\""
@@ -82,5 +82,5 @@ jobs:
8282
uses: actions/upload-artifact@v4
8383
with:
8484
name: AndroidTestResults_${{ inputs.js-engine }}
85-
path: Tests/UnitTests/Android/app/build/outputs/androidTest-results/connected
85+
path: Tests/UnitTests/Source/Android/app/build/outputs/androidTest-results/connected
8686
if-no-files-found: ignore

‎.gitignore‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
/Build
2-
Tests/UnitTests/dist/

‎Documentation/DebugJavaScriptDevTools.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Click `Configure...` and in the target discovery settings add an entry `localhos
88
![Target discovery settings](Images/DevTools/chrome-targets.png)
99

1010
## Setting Up To Debug
11-
Make sure to change the line in [tests.js](https://github.com/BabylonJS/JsRuntimeHost/blob/f487c7b3f89b407e95a53543a06a34f1a1fbb860/Tests/UnitTests/Scripts/tests.js#L2) to true, or else the DevTools won't have enough time to attach to the JavaScript Instance. If you are debugging your own script, you can also use [setTimeout()](https://developer.mozilla.org/en-US/docs/web/api/settimeout) to delay the execution of the code you are trying to debug while you wait to attach the debugger.
11+
Set `waitForDebugger` to true in [Tests.JavaScript.cpp](../Tests/UnitTests/Source/Tests.JavaScript.cpp) so DevTools has time to attach to the JavaScript instance. If you are debugging your own script, you can also use [setTimeout()](https://developer.mozilla.org/en-US/docs/web/api/settimeout) to delay execution while you attach the debugger.
1212

1313
## Debugging on Android/Emulator
1414

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Use a git-enabled terminal to run the following command.
2525
git clone https://github.com/BabylonJS/JsRuntimeHost.git
2626
```
2727

28-
The unit tests require some NPM packages. From the root of the repository on the command line, run the following commands:
28+
The unit tests require some NPM packages. From the root of the repository on the command line, run the following commands. The CMake or Android Gradle build generates `tests.js` in its build directory and packages it as `Assets/tests.js`; installing packages alone does not build the bundle.
2929

3030
```
3131
cd Tests
@@ -50,7 +50,7 @@ First, download the latest release of Ninja, extract the binary, and add it to y
5050
Once you have Android Studio downloaded, you need to set up an Android emulator if you do not have a physical Android device. You can do this by selecting `Tools` -> `Device Manager` and then selecting a device. (We are using Pixel 2 API 27).
5151

5252
Open the project located at
53-
`JsRuntimeHost\Tests\UnitTests\Android` with Android Studio. Note that this can take a while to load. (The bottom right corner of the Android Studio window shows you what is currently being loaded.)
53+
`JsRuntimeHost\Tests\UnitTests\Source\Android` with Android Studio. Note that this can take a while to load. (The bottom right corner of the Android Studio window shows you what is currently being loaded.)
5454

5555
Then in the LEFT PANE, right click on `app`, and select `Run 'All Tests'`, as displayed in the image below.
5656

‎Tests/UnitTests/CMakeLists.txt‎

Lines changed: 53 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,71 @@
1-
set(SCRIPTS
2-
"Scripts/symlink_target.js"
3-
"dist/tests.js")
4-
5-
set(TYPE_SCRIPTS
6-
"Scripts/tests.ts")
1+
set(TEST_BUNDLE "${CMAKE_CURRENT_BINARY_DIR}/Assets/tests.js")
2+
set(SCRIPTS "${TEST_BUNDLE}")
3+
4+
file(GLOB_RECURSE TEST_JAVASCRIPT CONFIGURE_DEPENDS
5+
"${CMAKE_CURRENT_SOURCE_DIR}/Source/Scripts/*.ts")
6+
find_program(NPM_EXECUTABLE NAMES npm npm.cmd REQUIRED)
7+
add_custom_command(
8+
OUTPUT "${TEST_BUNDLE}"
9+
COMMAND "${NPM_EXECUTABLE}" run build -- --output-path "${CMAKE_CURRENT_BINARY_DIR}/Assets" --no-output-compare-before-emit
10+
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.."
11+
MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/Source/Scripts/tests.javaScript.all.ts"
12+
DEPENDS ${TEST_JAVASCRIPT}
13+
"${CMAKE_CURRENT_SOURCE_DIR}/../webpack.config.js"
14+
"${CMAKE_CURRENT_SOURCE_DIR}/../babel-plugin-replace-bigint.js"
15+
"${CMAKE_CURRENT_SOURCE_DIR}/../package.json"
16+
"${CMAKE_CURRENT_SOURCE_DIR}/../package-lock.json"
17+
VERBATIM)
18+
19+
set_source_files_properties(${TEST_JAVASCRIPT} PROPERTIES HEADER_FILE_ONLY TRUE)
720

821
file(GLOB ASSETS "${CMAKE_CURRENT_SOURCE_DIR}/Assets/*")
922

1023
set(SOURCES
11-
"Shared/DelayedTaskScheduler.cpp"
12-
"Shared/StandardStreamLogger.cpp"
13-
"Shared/TimeoutDispatcher.cpp"
14-
"Shared/Shared.cpp"
15-
"Shared/Shared.h")
24+
"Source/App.cpp"
25+
"Source/App.h"
26+
"Source/Tests.AppRuntime.cpp"
27+
"Source/Tests.Console.cpp"
28+
"Source/Tests.DelayedTaskScheduler.cpp"
29+
"Source/Tests.JavaScript.cpp"
30+
"Source/Tests.NodeApi.cpp"
31+
"Source/Tests.Scheduling.cpp"
32+
"Source/Tests.StandardStreamLogger.cpp"
33+
"Source/Tests.TimeoutDispatcher.cpp")
1634

1735
if(APPLE)
1836
if(IOS)
1937
set(SOURCES ${SOURCES}
20-
"iOS/App.mm")
38+
"Source/iOS/App.mm")
2139

2240
set(PLIST_FILE
23-
"${CMAKE_CURRENT_LIST_DIR}/iOS/Info.plist")
41+
"${CMAKE_CURRENT_LIST_DIR}/Source/iOS/Info.plist")
2442

2543
set(STORYBOARD
26-
"${CMAKE_CURRENT_LIST_DIR}/iOS/Base.lproj/LaunchScreen.storyboard"
27-
"${CMAKE_CURRENT_LIST_DIR}/iOS/Base.lproj/Main.storyboard")
44+
"${CMAKE_CURRENT_LIST_DIR}/Source/iOS/Base.lproj/LaunchScreen.storyboard"
45+
"${CMAKE_CURRENT_LIST_DIR}/Source/iOS/Base.lproj/Main.storyboard")
2846

2947
set_source_files_properties(
3048
${SCRIPTS}
31-
${TYPE_SCRIPTS}
32-
PROPERTIES MACOSX_PACKAGE_LOCATION "Scripts")
49+
PROPERTIES MACOSX_PACKAGE_LOCATION "Assets")
3350

3451
set_source_files_properties(
3552
${ASSETS}
3653
PROPERTIES MACOSX_PACKAGE_LOCATION "Assets")
3754
else()
3855
set(SOURCES ${SOURCES}
39-
macOS/App.mm)
56+
Source/macOS/App.mm)
4057
endif()
4158
elseif(WIN32)
4259
set(SOURCES ${SOURCES}
43-
Win32/App.cpp)
60+
Source/Win32/App.cpp)
4461
elseif(UNIX AND NOT ANDROID)
4562
set(SOURCES ${SOURCES}
46-
Linux/App.cpp)
63+
Source/Linux/App.cpp)
4764
endif()
4865

49-
add_executable(UnitTests ${SOURCES} ${SCRIPTS} ${TYPE_SCRIPTS} ${ASSETS})
66+
add_executable(UnitTests ${SOURCES} ${TEST_JAVASCRIPT} ${SCRIPTS} ${ASSETS})
5067
if(NAPI_JAVASCRIPT_ENGINE STREQUAL "V8")
51-
target_sources(UnitTests PRIVATE "Shared/V8ForegroundTaskRunner.cpp")
68+
target_sources(UnitTests PRIVATE "Source/Tests.V8ForegroundTaskRunner.cpp")
5269
target_link_libraries(UnitTests PRIVATE AppRuntimeInternal)
5370
endif()
5471
target_compile_definitions(UnitTests PRIVATE JSRUNTIMEHOST_PLATFORM="${JSRUNTIMEHOST_PLATFORM}")
@@ -97,30 +114,29 @@ if(IOS)
97114
XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET ${DEPLOYMENT_TARGET}
98115
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "com.jsruntimehost.unittests")
99116
else()
100-
foreach(SCRIPT ${SCRIPTS})
101-
get_filename_component(SCRIPT_NAME "${SCRIPT}" NAME)
102-
add_custom_command(
103-
OUTPUT "${CMAKE_CFG_INTDIR}/Scripts/${SCRIPT_NAME}"
104-
COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/${SCRIPT}" "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/Scripts/${SCRIPT_NAME}"
105-
COMMENT "Copying ${SCRIPT_NAME}"
106-
MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/${SCRIPT}")
107-
endforeach()
117+
# Incremental builds may still have resources from the former Scripts directory.
118+
add_custom_command(TARGET UnitTests POST_BUILD
119+
COMMAND "${CMAKE_COMMAND}" -E rm -rf "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/Scripts")
120+
121+
if(CMAKE_CONFIGURATION_TYPES)
122+
add_custom_command(TARGET UnitTests POST_BUILD
123+
COMMAND "${CMAKE_COMMAND}" -E make_directory "$<TARGET_FILE_DIR:UnitTests>/Assets"
124+
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${TEST_BUNDLE}" "$<TARGET_FILE_DIR:UnitTests>/Assets/tests.js")
125+
endif()
108126

109127
add_custom_command(TARGET UnitTests POST_BUILD
110-
COMMAND ${CMAKE_COMMAND} -E create_symlink "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/Scripts/symlink_target.js" "${CMAKE_CFG_INTDIR}/Scripts/symlink_1.js")
128+
COMMAND ${CMAKE_COMMAND} -E create_symlink "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/Assets/symlink_target.js" "${CMAKE_CFG_INTDIR}/Assets/symlink_1.js")
111129
add_custom_command(TARGET UnitTests POST_BUILD
112-
COMMAND ${CMAKE_COMMAND} -E create_symlink "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/Scripts/symlink_1.js" "${CMAKE_CFG_INTDIR}/Scripts/symlink_2.js")
130+
COMMAND ${CMAKE_COMMAND} -E create_symlink "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/Assets/symlink_1.js" "${CMAKE_CFG_INTDIR}/Assets/symlink_2.js")
113131

114132
foreach(ASSET ${ASSETS})
115133
get_filename_component(ASSET_NAME "${ASSET}" NAME)
116134
add_custom_command(TARGET UnitTests POST_BUILD
117-
COMMAND "${CMAKE_COMMAND}" -E copy "${ASSET}" "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/Assets/${ASSET_NAME}"
118-
COMMENT "Copying ${ASSET_NAME}")
135+
COMMAND "${CMAKE_COMMAND}" -E copy "${ASSET}" "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/Assets/${ASSET_NAME}")
119136
endforeach()
120137
endif()
121138

122139
set_property(TARGET UnitTests PROPERTY FOLDER Tests)
123140

124-
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES} ${SCRIPTS})
125-
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/Scripts PREFIX scripts FILES ${TYPE_SCRIPTS})
126-
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/Assets PREFIX assets FILES ${ASSETS})
141+
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES} ${TEST_JAVASCRIPT})
142+
source_group("Assets" FILES ${SCRIPTS} ${ASSETS})

0 commit comments

Comments
 (0)