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
6 changes: 3 additions & 3 deletions .github/workflows/build-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ jobs:
target: google_apis
arch: x86_64
emulator-options: -no-snapshot -no-window -no-boot-anim -no-audio
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 }}
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 }}

- name: Dump Test Results
if: always()
working-directory: Tests/UnitTests/Android
working-directory: Tests/UnitTests/Source/Android
run: |
find ./app/build/outputs/androidTest-results -name "*.txt" -print0 | while IFS= read -r -d '' file; do
echo "cat \"$file\""
Expand All @@ -82,5 +82,5 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: AndroidTestResults_${{ inputs.js-engine }}
path: Tests/UnitTests/Android/app/build/outputs/androidTest-results/connected
path: Tests/UnitTests/Source/Android/app/build/outputs/androidTest-results/connected
if-no-files-found: ignore
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/Build
Tests/UnitTests/dist/
2 changes: 1 addition & 1 deletion Documentation/DebugJavaScriptDevTools.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Click `Configure...` and in the target discovery settings add an entry `localhos
![Target discovery settings](Images/DevTools/chrome-targets.png)

## Setting Up To Debug
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.
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.

## Debugging on Android/Emulator

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Use a git-enabled terminal to run the following command.
git clone https://github.com/BabylonJS/JsRuntimeHost.git
```

The unit tests require some NPM packages. From the root of the repository on the command line, run the following commands:
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.

```
cd Tests
Expand All @@ -50,7 +50,7 @@ First, download the latest release of Ninja, extract the binary, and add it to y
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).

Open the project located at
`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.)
`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.)

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

Expand Down
90 changes: 53 additions & 37 deletions Tests/UnitTests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,54 +1,71 @@
set(SCRIPTS
"Scripts/symlink_target.js"
"dist/tests.js")

set(TYPE_SCRIPTS
"Scripts/tests.ts")
set(TEST_BUNDLE "${CMAKE_CURRENT_BINARY_DIR}/Assets/tests.js")
set(SCRIPTS "${TEST_BUNDLE}")

file(GLOB_RECURSE TEST_JAVASCRIPT CONFIGURE_DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/Source/Scripts/*.ts")
find_program(NPM_EXECUTABLE NAMES npm npm.cmd REQUIRED)
add_custom_command(
OUTPUT "${TEST_BUNDLE}"
COMMAND "${NPM_EXECUTABLE}" run build -- --output-path "${CMAKE_CURRENT_BINARY_DIR}/Assets" --no-output-compare-before-emit
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.."
MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/Source/Scripts/tests.javaScript.all.ts"
DEPENDS ${TEST_JAVASCRIPT}
"${CMAKE_CURRENT_SOURCE_DIR}/../webpack.config.js"
"${CMAKE_CURRENT_SOURCE_DIR}/../babel-plugin-replace-bigint.js"
"${CMAKE_CURRENT_SOURCE_DIR}/../package.json"
"${CMAKE_CURRENT_SOURCE_DIR}/../package-lock.json"
VERBATIM)

set_source_files_properties(${TEST_JAVASCRIPT} PROPERTIES HEADER_FILE_ONLY TRUE)

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

set(SOURCES
"Shared/DelayedTaskScheduler.cpp"
"Shared/StandardStreamLogger.cpp"
"Shared/TimeoutDispatcher.cpp"
"Shared/Shared.cpp"
"Shared/Shared.h")
"Source/App.cpp"
"Source/App.h"
"Source/Tests.AppRuntime.cpp"
"Source/Tests.Console.cpp"
"Source/Tests.DelayedTaskScheduler.cpp"
"Source/Tests.JavaScript.cpp"
"Source/Tests.NodeApi.cpp"
"Source/Tests.Scheduling.cpp"
"Source/Tests.StandardStreamLogger.cpp"
"Source/Tests.TimeoutDispatcher.cpp")

if(APPLE)
if(IOS)
set(SOURCES ${SOURCES}
"iOS/App.mm")
"Source/iOS/App.mm")

set(PLIST_FILE
"${CMAKE_CURRENT_LIST_DIR}/iOS/Info.plist")
"${CMAKE_CURRENT_LIST_DIR}/Source/iOS/Info.plist")

set(STORYBOARD
"${CMAKE_CURRENT_LIST_DIR}/iOS/Base.lproj/LaunchScreen.storyboard"
"${CMAKE_CURRENT_LIST_DIR}/iOS/Base.lproj/Main.storyboard")
"${CMAKE_CURRENT_LIST_DIR}/Source/iOS/Base.lproj/LaunchScreen.storyboard"
"${CMAKE_CURRENT_LIST_DIR}/Source/iOS/Base.lproj/Main.storyboard")
Comment thread
bghgary marked this conversation as resolved.

set_source_files_properties(
${SCRIPTS}
${TYPE_SCRIPTS}
PROPERTIES MACOSX_PACKAGE_LOCATION "Scripts")
PROPERTIES MACOSX_PACKAGE_LOCATION "Assets")

set_source_files_properties(
${ASSETS}
PROPERTIES MACOSX_PACKAGE_LOCATION "Assets")
else()
set(SOURCES ${SOURCES}
macOS/App.mm)
Source/macOS/App.mm)
endif()
elseif(WIN32)
set(SOURCES ${SOURCES}
Win32/App.cpp)
Source/Win32/App.cpp)
elseif(UNIX AND NOT ANDROID)
set(SOURCES ${SOURCES}
Linux/App.cpp)
Source/Linux/App.cpp)
endif()

add_executable(UnitTests ${SOURCES} ${SCRIPTS} ${TYPE_SCRIPTS} ${ASSETS})
add_executable(UnitTests ${SOURCES} ${TEST_JAVASCRIPT} ${SCRIPTS} ${ASSETS})
if(NAPI_JAVASCRIPT_ENGINE STREQUAL "V8")
target_sources(UnitTests PRIVATE "Shared/V8ForegroundTaskRunner.cpp")
target_sources(UnitTests PRIVATE "Source/Tests.V8ForegroundTaskRunner.cpp")
target_link_libraries(UnitTests PRIVATE AppRuntimeInternal)
endif()
target_compile_definitions(UnitTests PRIVATE JSRUNTIMEHOST_PLATFORM="${JSRUNTIMEHOST_PLATFORM}")
Expand Down Expand Up @@ -97,30 +114,29 @@ if(IOS)
XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET ${DEPLOYMENT_TARGET}
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "com.jsruntimehost.unittests")
else()
foreach(SCRIPT ${SCRIPTS})
get_filename_component(SCRIPT_NAME "${SCRIPT}" NAME)
add_custom_command(
OUTPUT "${CMAKE_CFG_INTDIR}/Scripts/${SCRIPT_NAME}"
COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/${SCRIPT}" "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/Scripts/${SCRIPT_NAME}"
COMMENT "Copying ${SCRIPT_NAME}"
MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/${SCRIPT}")
endforeach()
# Incremental builds may still have resources from the former Scripts directory.
add_custom_command(TARGET UnitTests POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E rm -rf "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/Scripts")

if(CMAKE_CONFIGURATION_TYPES)
add_custom_command(TARGET UnitTests POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E make_directory "$<TARGET_FILE_DIR:UnitTests>/Assets"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${TEST_BUNDLE}" "$<TARGET_FILE_DIR:UnitTests>/Assets/tests.js")
endif()

add_custom_command(TARGET UnitTests POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/Scripts/symlink_target.js" "${CMAKE_CFG_INTDIR}/Scripts/symlink_1.js")
COMMAND ${CMAKE_COMMAND} -E create_symlink "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/Assets/symlink_target.js" "${CMAKE_CFG_INTDIR}/Assets/symlink_1.js")
add_custom_command(TARGET UnitTests POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/Scripts/symlink_1.js" "${CMAKE_CFG_INTDIR}/Scripts/symlink_2.js")
COMMAND ${CMAKE_COMMAND} -E create_symlink "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/Assets/symlink_1.js" "${CMAKE_CFG_INTDIR}/Assets/symlink_2.js")

foreach(ASSET ${ASSETS})
get_filename_component(ASSET_NAME "${ASSET}" NAME)
add_custom_command(TARGET UnitTests POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy "${ASSET}" "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/Assets/${ASSET_NAME}"
COMMENT "Copying ${ASSET_NAME}")
COMMAND "${CMAKE_COMMAND}" -E copy "${ASSET}" "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/Assets/${ASSET_NAME}")
endforeach()
endif()

set_property(TARGET UnitTests PROPERTY FOLDER Tests)

source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES} ${SCRIPTS})
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/Scripts PREFIX scripts FILES ${TYPE_SCRIPTS})
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/Assets PREFIX assets FILES ${ASSETS})
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES} ${TEST_JAVASCRIPT})
source_group("Assets" FILES ${SCRIPTS} ${ASSETS})
Loading
Loading