mirror of
https://github.com/game-ci/unity-test-runner.git
synced 2026-01-29 14:39:33 +08:00
Compare commits
40 Commits
v1.4.1
...
v2.0-alpha
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e1be8325cd | ||
|
|
26807aaf05 | ||
|
|
a9d07b742d | ||
|
|
0c3e710069 | ||
|
|
a067c3d5ab | ||
|
|
3fca186a7b | ||
|
|
a8b9742ecd | ||
|
|
31cd755121 | ||
|
|
679222c549 | ||
|
|
29899d84e8 | ||
|
|
7d26e264b9 | ||
|
|
bac0f97d2f | ||
|
|
c4e44617e2 | ||
|
|
25e14f52b8 | ||
|
|
3a40ffcf5f | ||
|
|
3277792c11 | ||
|
|
ac2e8a74d0 | ||
|
|
8107d46ab7 | ||
|
|
a4e8475a2f | ||
|
|
f02586c1c9 | ||
|
|
31ae95179d | ||
|
|
cd86c7302b | ||
|
|
21831e61ad | ||
|
|
7c1cba9a39 | ||
|
|
29e179f50b | ||
|
|
2fa69494ad | ||
|
|
4e717f6c82 | ||
|
|
173716a8a9 | ||
|
|
3c915726f4 | ||
|
|
5cfdb7ee17 | ||
|
|
51648a5093 | ||
|
|
2297daa673 | ||
|
|
7711f454ba | ||
|
|
b518514f36 | ||
|
|
7e50ed34dd | ||
|
|
c85e37ca1f | ||
|
|
58f580c801 | ||
|
|
4ba71aefa9 | ||
|
|
bed834cb73 | ||
|
|
eb51009c09 |
9
.github/pull_request_template.md
vendored
Normal file
9
.github/pull_request_template.md
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
#### Changes
|
||||
|
||||
- ...
|
||||
|
||||
#### Checklist
|
||||
|
||||
- [x] Read the contribution [guide](../CONTRIBUTING.md) and accept the [code](../CODE_OF_CONDUCT.md) of conduct
|
||||
- [ ] Readme (updated or not needed)
|
||||
- [ ] Tests (added, updated or not needed)
|
||||
6
.github/workflows/main.yml
vendored
6
.github/workflows/main.yml
vendored
@@ -12,14 +12,14 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v1.1.2
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 12.x
|
||||
- run: yarn
|
||||
- run: yarn lint
|
||||
- run: yarn test
|
||||
- run: yarn build || { echo "build command should always succeed" ; exit 61; }
|
||||
- run: yarn build --quiet && git diff --quiet action || { echo "action should be auto generated" ; exit 62; }
|
||||
- run: yarn build --quiet && git diff --quiet action || { echo "ERROR - index.js is different from repository version. Forgot to run `yarn build`?" ; exit 62; }
|
||||
|
||||
testAllModesLikeInTheReadme:
|
||||
name: Test in ${{ matrix.testMode }} on version ${{ matrix.unityVersion }}
|
||||
@@ -38,7 +38,7 @@ jobs:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
lfs: true
|
||||
- uses: actions/cache@v1.1.0
|
||||
- uses: actions/cache@v2
|
||||
with:
|
||||
path: ${{ matrix.projectPath }}/Library
|
||||
key: Library-${{ matrix.projectPath }}
|
||||
|
||||
@@ -2,5 +2,6 @@
|
||||
"semi": true,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "all",
|
||||
"printWidth": 100
|
||||
"printWidth": 100,
|
||||
"arrowParens": "avoid"
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ You have [Node](https://nodejs.org/) installed at v12.2.0+ and [Yarn](https://ya
|
||||
Please note that commit hooks will run automatically to perform some tasks;
|
||||
|
||||
- format your code
|
||||
- run tests
|
||||
- build distributable files
|
||||
- run tests & lint - `yarn lint && yarn test`
|
||||
- build distributable files - `yarn build`
|
||||
|
||||
#### License
|
||||
|
||||
|
||||
265
README.md
265
README.md
@@ -1,262 +1,43 @@
|
||||
# Unity - Test runner
|
||||
|
||||
[](https://github.com/webbertakken/unity-test-runner/actions?query=branch%3Amaster+event%3Apush+workflow%3A"Actions%20%F0%9F%98%8E")
|
||||
|
||||
---
|
||||
(Not affiliated with Unity Technologies)
|
||||
|
||||
GitHub Action to
|
||||
[run tests](https://github.com/marketplace/actions/unity-test-runner)
|
||||
for any Unity project.
|
||||
|
||||
Part of the
|
||||
[Unity Actions](https://github.com/webbertakken/unity-actions)
|
||||
collection.
|
||||
Part of the <a href="https://game.ci">GameCI</a> open source project.
|
||||
<br />
|
||||
<br />
|
||||
|
||||
---
|
||||
[](https://github.com/webbertakken/unity-test-runner/actions?query=branch%3Amaster+event%3Apush+workflow%3A"Actions%20%F0%9F%98%8E")
|
||||
<br />
|
||||
<br />
|
||||
|
||||
This is a recommended step to prepare your pipeline for using the
|
||||
[Build](https://github.com/webbertakken/unity-actions#build)
|
||||
action.
|
||||
## How to use
|
||||
|
||||
## Documentation
|
||||
Find the
|
||||
[docs](https://game.ci/docs)
|
||||
on the GameCI
|
||||
[website](https://game.ci/).
|
||||
|
||||
See the
|
||||
[Unity Actions](https://github.com/webbertakken/unity-actions)
|
||||
collection repository for workflow documentation and reference implementation.
|
||||
## Related actions
|
||||
|
||||
## Usage
|
||||
Visit the
|
||||
GameCI <a href="https://github.com/game-ci/unity-actions">Unity Actions</a>
|
||||
status repository for related Actions.
|
||||
|
||||
#### Setup test runner
|
||||
## Community
|
||||
|
||||
By default the test runner will run all your playmode and editmode tests.
|
||||
Feel free to join us on
|
||||
<a href="http://game.ci/discord"><img height="30" src="media/Discord-Logo.svg" alt="Discord" /></a>
|
||||
and engage with the community.
|
||||
|
||||
Create or edit the file called `.github/workflows/main.yml` and add a job to it.
|
||||
## Contributing
|
||||
|
||||
##### Personal License
|
||||
To help improve the documentation, please find the docs [repository](https://github.com/game-ci/documentation).
|
||||
|
||||
Personal licenses require a one-time manual activation step (per unity version).
|
||||
|
||||
Make sure you
|
||||
[acquire and activate](https://github.com/marketplace/actions/unity-request-activation-file)
|
||||
your license file and add it as a secret.
|
||||
|
||||
Then, define the test step as follows:
|
||||
|
||||
```yaml
|
||||
- uses: webbertakken/unity-test-runner@v1.4
|
||||
env:
|
||||
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
|
||||
with:
|
||||
projectPath: path/to/your/project
|
||||
unityVersion: 20XX.X.XXXX
|
||||
```
|
||||
|
||||
##### Professional license
|
||||
|
||||
Professional licenses do not need any manual steps.
|
||||
|
||||
Instead, three variables will need to be set.
|
||||
|
||||
- `UNITY_EMAIL` (should contain the email address for your Unity account)
|
||||
- `UNITY_PASSWORD` (the password that you use to login to Unity)
|
||||
- `UNITY_SERIAL` (the serial provided by Unity)
|
||||
|
||||
Define the test step as follows:
|
||||
|
||||
```yaml
|
||||
- uses: webbertakken/unity-test-runner@v1.4
|
||||
env:
|
||||
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
|
||||
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
|
||||
UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
|
||||
with:
|
||||
projectPath: path/to/your/project
|
||||
unityVersion: 20XX.X.XXXX
|
||||
```
|
||||
|
||||
That is all you need to test your project.
|
||||
|
||||
#### Storing test results
|
||||
|
||||
To be able to access the test results,
|
||||
they need to be uploaded as artifacts.
|
||||
To do this it is recommended to use Github Actions official
|
||||
[upload artifact action](https://github.com/marketplace/actions/upload-artifact)
|
||||
after any test action.
|
||||
|
||||
###### Using defaults
|
||||
|
||||
By default, Test Runner outputs it's results to a folder named `artifacts`.
|
||||
|
||||
Example:
|
||||
|
||||
```yaml
|
||||
- uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: Test results
|
||||
path: artifacts
|
||||
```
|
||||
|
||||
Test results can now be downloaded as Artifacts in the Actions tab.
|
||||
|
||||
###### Specifying artifacts folder
|
||||
|
||||
If a different `artifactsPath` was specified in the test runner,
|
||||
you can reference this path using the `id` of the test step.
|
||||
|
||||
Example:
|
||||
|
||||
```yaml
|
||||
- uses: webbertakken/unity-test-runner@v1.4
|
||||
id: myTestStep
|
||||
(...)
|
||||
```
|
||||
|
||||
```yaml
|
||||
- uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: Test results
|
||||
path: ${{ steps.myTestStep.outputs.artifactsPath }}
|
||||
```
|
||||
|
||||
#### Caching
|
||||
|
||||
In order to make test runs (and builds) faster,
|
||||
you can cache Library files from previous runs.
|
||||
To do so, simply add Github Actions' official
|
||||
[cache action](https://github.com/marketplace/actions/cache)
|
||||
before any unity steps.
|
||||
|
||||
Example:
|
||||
|
||||
```yaml
|
||||
- uses: actions/cache@v1.1.0
|
||||
with:
|
||||
path: path/to/your/project/Library
|
||||
key: Library-MyProjectName-TargetPlatform
|
||||
restore-keys: |
|
||||
Library-MyProjectName-
|
||||
Library-
|
||||
```
|
||||
|
||||
This simple addition could speed up your test runs by more than 50%.
|
||||
|
||||
#### Complete example
|
||||
|
||||
A complete workflow that tests all modes separately could look like this:
|
||||
|
||||
```yaml
|
||||
name: Build project
|
||||
|
||||
on:
|
||||
pull_request: {}
|
||||
push: { branches: [master] }
|
||||
|
||||
env:
|
||||
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
|
||||
|
||||
jobs:
|
||||
testAllModes:
|
||||
name: Test in ${{ matrix.testMode }} on version ${{ matrix.unityVersion }}
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
projectPath:
|
||||
- path/to/your/project
|
||||
unityVersion:
|
||||
- 2019.2.11f1
|
||||
testMode:
|
||||
- playmode
|
||||
- editmode
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
lfs: true
|
||||
- uses: actions/cache@v1.1.0
|
||||
with:
|
||||
path: ${{ matrix.projectPath }}/Library
|
||||
key: Library-${{ matrix.projectPath }}
|
||||
restore-keys: |
|
||||
Library-
|
||||
- uses: webbertakken/unity-test-runner@v1.4
|
||||
id: tests
|
||||
with:
|
||||
projectPath: ${{ matrix.projectPath }}
|
||||
unityVersion: ${{ matrix.unityVersion }}
|
||||
testMode: ${{ matrix.testMode }}
|
||||
artifactsPath: ${{ matrix.testMode }}-artifacts
|
||||
- uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: Test results for ${{ matrix.testMode }}
|
||||
path: ${{ steps.tests.outputs.artifactsPath }}
|
||||
```
|
||||
|
||||
> **Note:** _Environment variables are set for all jobs in the workflow like this._
|
||||
|
||||
## Configuration options
|
||||
|
||||
Below options can be specified under `with:` for the `unity-test-runner` action.
|
||||
|
||||
#### projectPath
|
||||
|
||||
Specify the path to your Unity project to be tested.
|
||||
The path should be relative to the root of your project.
|
||||
|
||||
_**required:** `false`_
|
||||
_**default:** `<your project root>`_
|
||||
|
||||
#### unityVersion
|
||||
|
||||
Version of Unity to use for testing the project.
|
||||
|
||||
_**required:** `false`_
|
||||
_**default:** `2019.2.1f11`_
|
||||
|
||||
#### testMode
|
||||
|
||||
The type of tests to be run by the test runner.
|
||||
|
||||
Options are: "all", "playmode", "editmode"
|
||||
|
||||
_**required:** `false`_
|
||||
_**default:** `all`_
|
||||
|
||||
#### artifactsPath
|
||||
|
||||
Path where the test results should be stored.
|
||||
|
||||
In this folder a folder will be created for every test mode.
|
||||
|
||||
_**required:** `false`_
|
||||
_**default:** `artifacts`_
|
||||
|
||||
#### customParameters
|
||||
|
||||
Custom parameters to configure the test runner.
|
||||
|
||||
Parameters must start with a hyphen (`-`) and may be followed by a value (without hyphen).
|
||||
|
||||
Parameters without a value will be considered booleans (with a value of true).
|
||||
|
||||
_**example:**_
|
||||
|
||||
```yaml
|
||||
- uses: webbertakken/unity-test-runner@master
|
||||
with:
|
||||
customParameters: -profile SomeProfile -someBoolean -someValue exampleValue
|
||||
```
|
||||
|
||||
_**required:** `false`_
|
||||
_**default:** ""_
|
||||
|
||||
## More actions
|
||||
|
||||
Visit
|
||||
[Unity Actions](https://github.com/webbertakken/unity-actions)
|
||||
to find related actions for Unity.
|
||||
|
||||
Feel free to contribute.
|
||||
To contribute to this project, kindly read the [contribution guide](./CONTRIBUTING.md).
|
||||
|
||||
## Licence
|
||||
|
||||
|
||||
26
action.yml
26
action.yml
@@ -4,8 +4,30 @@ description: 'Run tests for any Unity project.'
|
||||
inputs:
|
||||
unityVersion:
|
||||
required: false
|
||||
default: '2019.2.11f1'
|
||||
description: 'Version of unity to use for testing the project.'
|
||||
default: 'auto'
|
||||
description: 'Version of unity to use for testing the project. Use "auto" to get from your ProjectSettings/ProjectVersion.txt'
|
||||
customImage:
|
||||
required: false
|
||||
default: ''
|
||||
description: 'Specific docker image that should be used for testing the project'
|
||||
projectPath:
|
||||
required: false
|
||||
description: 'Path to the Unity project to be tested.'
|
||||
testMode:
|
||||
required: false
|
||||
default: 'all'
|
||||
description: 'The type of tests to be run by the test runner.'
|
||||
artifactsPath:
|
||||
required: false
|
||||
default: 'artifacts'
|
||||
description: 'Path where test artifacts should be stored.'
|
||||
useNetworkHost:
|
||||
required: false
|
||||
default: false
|
||||
description: 'Initialises Docker using the hosts network.'
|
||||
customParameters:
|
||||
required: false
|
||||
description: 'Extra parameters to configure the Unity editor run.'
|
||||
outputs:
|
||||
artifactsPath:
|
||||
description: 'Path where the artifacts are stored'
|
||||
|
||||
@@ -8,6 +8,23 @@ source /steps/activate.sh
|
||||
source /steps/run_tests.sh
|
||||
source /steps/return_license.sh
|
||||
|
||||
#
|
||||
# Instructions for debugging
|
||||
#
|
||||
|
||||
if [[ $TEST_RUNNER_EXIT_CODE -gt 0 ]]; then
|
||||
echo ""
|
||||
echo "###########################"
|
||||
echo "# Failure #"
|
||||
echo "###########################"
|
||||
echo ""
|
||||
echo "Please note that the exit code is not very descriptive."
|
||||
echo "Most likely it will not help you solve the issue."
|
||||
echo ""
|
||||
echo "To find the reason for failure: please search for errors in the log above."
|
||||
echo ""
|
||||
fi;
|
||||
|
||||
#
|
||||
# Exit with code from the build step.
|
||||
#
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
if [[ -n "$UNITY_LICENSE" ]]; then
|
||||
if [[ -n "$UNITY_LICENSE" ]] || [[ -n "$UNITY_LICENSE_FILE" ]]; then
|
||||
#
|
||||
# PERSONAL LICENSE MODE
|
||||
#
|
||||
@@ -15,17 +15,21 @@ if [[ -n "$UNITY_LICENSE" ]]; then
|
||||
# Set the license file path
|
||||
FILE_PATH=UnityLicenseFile.ulf
|
||||
|
||||
# Copy license file from Github variables
|
||||
echo "$UNITY_LICENSE" | tr -d '\r' > $FILE_PATH
|
||||
if [[ -n "$UNITY_LICENSE" ]]; then
|
||||
# Copy license file from Github variables
|
||||
echo "$UNITY_LICENSE" | tr -d '\r' > $FILE_PATH
|
||||
elif [[ -n "$UNITY_LICENSE_FILE" ]]; then
|
||||
# Copy license file from file system
|
||||
cat "$UNITY_LICENSE_FILE" | tr -d '\r' > $FILE_PATH
|
||||
fi
|
||||
|
||||
# Activate license
|
||||
ACTIVATION_OUTPUT=$(xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \
|
||||
/opt/Unity/Editor/Unity \
|
||||
-batchmode \
|
||||
-nographics \
|
||||
-logFile /dev/stdout \
|
||||
-quit \
|
||||
-manualLicenseFile $FILE_PATH)
|
||||
ACTIVATION_OUTPUT=$(unity-editor \
|
||||
-batchmode \
|
||||
-nographics \
|
||||
-logFile /dev/stdout \
|
||||
-quit \
|
||||
-manualLicenseFile $FILE_PATH)
|
||||
|
||||
# Store the exit code from the verify command
|
||||
UNITY_EXIT_CODE=$?
|
||||
@@ -58,15 +62,14 @@ elif [[ -n "$UNITY_SERIAL" && -n "$UNITY_EMAIL" && -n "$UNITY_PASSWORD" ]]; then
|
||||
echo "Requesting activation (professional license)"
|
||||
|
||||
# Activate license
|
||||
xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \
|
||||
/opt/Unity/Editor/Unity \
|
||||
-batchmode \
|
||||
-nographics \
|
||||
-logFile /dev/stdout \
|
||||
-quit \
|
||||
-serial "$UNITY_SERIAL" \
|
||||
-username "$UNITY_EMAIL" \
|
||||
-password "$UNITY_PASSWORD"
|
||||
unity-editor \
|
||||
-batchmode \
|
||||
-nographics \
|
||||
-logFile /dev/stdout \
|
||||
-quit \
|
||||
-serial "$UNITY_SERIAL" \
|
||||
-username "$UNITY_EMAIL" \
|
||||
-password "$UNITY_PASSWORD"
|
||||
|
||||
# Store the exit code from the verify command
|
||||
UNITY_EXIT_CODE=$?
|
||||
|
||||
@@ -6,11 +6,10 @@ if [[ -n "$UNITY_SERIAL" ]]; then
|
||||
#
|
||||
# This will return the license that is currently in use.
|
||||
#
|
||||
xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \
|
||||
/opt/Unity/Editor/Unity \
|
||||
-batchmode \
|
||||
-nographics \
|
||||
-logFile /dev/stdout \
|
||||
-quit \
|
||||
-returnlicense
|
||||
unity-editor \
|
||||
-batchmode \
|
||||
-nographics \
|
||||
-logFile /dev/stdout \
|
||||
-quit \
|
||||
-returnlicense
|
||||
fi
|
||||
|
||||
@@ -74,19 +74,21 @@ if [ $EDIT_MODE = true ]; then
|
||||
echo "# Testing in EditMode #"
|
||||
echo "###########################"
|
||||
echo ""
|
||||
xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \
|
||||
/opt/Unity/Editor/Unity \
|
||||
-batchmode \
|
||||
-logfile /dev/stdout \
|
||||
-projectPath "$UNITY_PROJECT_PATH" \
|
||||
-runTests \
|
||||
-testPlatform editmode \
|
||||
-testResults "$FULL_ARTIFACTS_PATH/editmode-results.xml" \
|
||||
$CUSTOM_PARAMETERS
|
||||
unity-editor \
|
||||
-batchmode \
|
||||
-logFile "$FULL_ARTIFACTS_PATH/editmode.log" \
|
||||
-projectPath "$UNITY_PROJECT_PATH" \
|
||||
-runTests \
|
||||
-testPlatform editmode \
|
||||
-testResults "$FULL_ARTIFACTS_PATH/editmode-results.xml" \
|
||||
$CUSTOM_PARAMETERS
|
||||
|
||||
# Catch exit code
|
||||
EDIT_MODE_EXIT_CODE=$?
|
||||
|
||||
# Print unity log output
|
||||
cat "$FULL_ARTIFACTS_PATH/editmode.log"
|
||||
|
||||
# Display results
|
||||
if [ $EDIT_MODE_EXIT_CODE -eq 0 ]; then
|
||||
echo "Run succeeded, no failures occurred";
|
||||
@@ -109,19 +111,21 @@ if [ $PLAY_MODE = true ]; then
|
||||
echo "# Testing in PlayMode #"
|
||||
echo "###########################"
|
||||
echo ""
|
||||
xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \
|
||||
/opt/Unity/Editor/Unity \
|
||||
-batchmode \
|
||||
-logfile /dev/stdout \
|
||||
-projectPath "$UNITY_PROJECT_PATH" \
|
||||
-runTests \
|
||||
-testPlatform playmode \
|
||||
-testResults "$FULL_ARTIFACTS_PATH/playmode-results.xml" \
|
||||
$CUSTOM_PARAMETERS
|
||||
unity-editor \
|
||||
-batchmode \
|
||||
-logFile "$FULL_ARTIFACTS_PATH/playmode.log" \
|
||||
-projectPath "$UNITY_PROJECT_PATH" \
|
||||
-runTests \
|
||||
-testPlatform playmode \
|
||||
-testResults "$FULL_ARTIFACTS_PATH/playmode-results.xml" \
|
||||
$CUSTOM_PARAMETERS
|
||||
|
||||
# Catch exit code
|
||||
PLAY_MODE_EXIT_CODE=$?
|
||||
|
||||
# Print unity log output
|
||||
cat "$FULL_ARTIFACTS_PATH/playmode.log"
|
||||
|
||||
# Display results
|
||||
if [ $PLAY_MODE_EXIT_CODE -eq 0 ]; then
|
||||
echo "Run succeeded, no failures occurred";
|
||||
|
||||
1
media/Discord-Logo.svg
Normal file
1
media/Discord-Logo.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg id="Layer_1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 800 272.1"><style>.st0{fill:#7289DA;}</style><path class="st0" d="M142.8 120.1c-5.7 0-10.2 4.9-10.2 11s4.6 11 10.2 11c5.7 0 10.2-4.9 10.2-11s-4.6-11-10.2-11zM106.3 120.1c-5.7 0-10.2 4.9-10.2 11s4.6 11 10.2 11c5.7 0 10.2-4.9 10.2-11 .1-6.1-4.5-11-10.2-11z"/><path class="st0" d="M191.4 36.9h-134c-11.3 0-20.5 9.2-20.5 20.5v134c0 11.3 9.2 20.5 20.5 20.5h113.4l-5.3-18.3 12.8 11.8 12.1 11.1 21.6 18.7V57.4c-.1-11.3-9.3-20.5-20.6-20.5zm-38.6 129.5s-3.6-4.3-6.6-8c13.1-3.7 18.1-11.8 18.1-11.8-4.1 2.7-8 4.6-11.5 5.9-5 2.1-9.8 3.4-14.5 4.3-9.6 1.8-18.4 1.3-25.9-.1-5.7-1.1-10.6-2.6-14.7-4.3-2.3-.9-4.8-2-7.3-3.4-.3-.2-.6-.3-.9-.5-.2-.1-.3-.2-.4-.2-1.8-1-2.8-1.7-2.8-1.7s4.8 7.9 17.5 11.7c-3 3.8-6.7 8.2-6.7 8.2-22.1-.7-30.5-15.1-30.5-15.1 0-31.9 14.4-57.8 14.4-57.8 14.4-10.7 28-10.4 28-10.4l1 1.2c-18 5.1-26.2 13-26.2 13s2.2-1.2 5.9-2.8c10.7-4.7 19.2-5.9 22.7-6.3.6-.1 1.1-.2 1.7-.2 6.1-.8 13-1 20.2-.2 9.5 1.1 19.7 3.9 30.1 9.5 0 0-7.9-7.5-24.9-12.6l1.4-1.6s13.7-.3 28 10.4c0 0 14.4 25.9 14.4 57.8 0-.1-8.4 14.3-30.5 15zM303.8 79.7h-33.2V117l22.1 19.9v-36.2h11.8c7.5 0 11.2 3.6 11.2 9.4v27.7c0 5.8-3.5 9.7-11.2 9.7h-34v21.1h33.2c17.8.1 34.5-8.8 34.5-29.2v-29.8c.1-20.8-16.6-29.9-34.4-29.9zm174 59.7v-30.6c0-11 19.8-13.5 25.8-2.5l18.3-7.4c-7.2-15.8-20.3-20.4-31.2-20.4-17.8 0-35.4 10.3-35.4 30.3v30.6c0 20.2 17.6 30.3 35 30.3 11.2 0 24.6-5.5 32-19.9l-19.6-9c-4.8 12.3-24.9 9.3-24.9-1.4zM417.3 113c-6.9-1.5-11.5-4-11.8-8.3.4-10.3 16.3-10.7 25.6-.8l14.7-11.3c-9.2-11.2-19.6-14.2-30.3-14.2-16.3 0-32.1 9.2-32.1 26.6 0 16.9 13 26 27.3 28.2 7.3 1 15.4 3.9 15.2 8.9-.6 9.5-20.2 9-29.1-1.8l-14.2 13.3c8.3 10.7 19.6 16.1 30.2 16.1 16.3 0 34.4-9.4 35.1-26.6 1-21.7-14.8-27.2-30.6-30.1zm-67 55.5h22.4V79.7h-22.4v88.8zM728 79.7h-33.2V117l22.1 19.9v-36.2h11.8c7.5 0 11.2 3.6 11.2 9.4v27.7c0 5.8-3.5 9.7-11.2 9.7h-34v21.1H728c17.8.1 34.5-8.8 34.5-29.2v-29.8c0-20.8-16.7-29.9-34.5-29.9zm-162.9-1.2c-18.4 0-36.7 10-36.7 30.5v30.3c0 20.3 18.4 30.5 36.9 30.5 18.4 0 36.7-10.2 36.7-30.5V109c0-20.4-18.5-30.5-36.9-30.5zm14.4 60.8c0 6.4-7.2 9.7-14.3 9.7-7.2 0-14.4-3.1-14.4-9.7V109c0-6.5 7-10 14-10 7.3 0 14.7 3.1 14.7 10v30.3zM682.4 109c-.5-20.8-14.7-29.2-33-29.2h-35.5v88.8h22.7v-28.2h4l20.6 28.2h28L665 138.1c10.7-3.4 17.4-12.7 17.4-29.1zm-32.6 12h-13.2v-20.3h13.2c14.1 0 14.1 20.3 0 20.3z"/></svg>
|
||||
|
After Width: | Height: | Size: 2.3 KiB |
45
package.json
45
package.json
@@ -7,35 +7,36 @@
|
||||
"author": "Webber <webber@takken.io>",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"prebuild": "yarn",
|
||||
"build": "ncc build src --out action --minify",
|
||||
"lint": "prettier --check \"src/**/*.js\" && eslint src",
|
||||
"test": "jest"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.1",
|
||||
"@actions/exec": "1.0.3",
|
||||
"@actions/github": "^2.0.1"
|
||||
"@actions/core": "^1.2.6",
|
||||
"@actions/exec": "1.0.4",
|
||||
"@actions/github": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "7.8.4",
|
||||
"@babel/core": "7.8.4",
|
||||
"@babel/preset-env": "7.8.4",
|
||||
"@zeit/ncc": "0.21.0",
|
||||
"babel-eslint": "10.0.3",
|
||||
"eslint": "6.8.0",
|
||||
"eslint-config-airbnb": "18.0.1",
|
||||
"eslint-config-prettier": "6.10.0",
|
||||
"eslint-plugin-flowtype": "4.6.0",
|
||||
"eslint-plugin-import": "2.20.1",
|
||||
"eslint-plugin-jsx-a11y": "6.2.3",
|
||||
"eslint-plugin-prettier": "3.1.2",
|
||||
"eslint-plugin-react": "7.18.3",
|
||||
"eslint-plugin-unicorn": "16.0.0",
|
||||
"husky": "4.2.1",
|
||||
"jest": "25.1.0",
|
||||
"lint-staged": "10.0.7",
|
||||
"lodash-es": "4.17.15",
|
||||
"prettier": "1.19.1"
|
||||
"@babel/cli": "7.12.10",
|
||||
"@babel/core": "7.12.10",
|
||||
"@babel/preset-env": "7.12.11",
|
||||
"@zeit/ncc": "0.22.3",
|
||||
"babel-eslint": "10.1.0",
|
||||
"eslint": "7.17.0",
|
||||
"eslint-config-airbnb": "18.2.1",
|
||||
"eslint-config-prettier": "7.1.0",
|
||||
"eslint-plugin-flowtype": "5.2.0",
|
||||
"eslint-plugin-import": "2.22.1",
|
||||
"eslint-plugin-jsx-a11y": "6.4.1",
|
||||
"eslint-plugin-prettier": "3.3.1",
|
||||
"eslint-plugin-react": "7.22.0",
|
||||
"eslint-plugin-unicorn": "25.0.1",
|
||||
"husky": "4.3.7",
|
||||
"jest": "26.6.3",
|
||||
"lint-staged": "10.5.3",
|
||||
"lodash-es": "4.17.20",
|
||||
"prettier": "2.2.1"
|
||||
},
|
||||
"husky": {
|
||||
"hooks": {
|
||||
|
||||
@@ -7,12 +7,14 @@ async function action() {
|
||||
const { dockerfile, workspace, actionFolder } = Action;
|
||||
const {
|
||||
unityVersion,
|
||||
customImage,
|
||||
projectPath,
|
||||
testMode,
|
||||
artifactsPath,
|
||||
useHostNetwork,
|
||||
customParameters,
|
||||
} = Input.getFromUser();
|
||||
const baseImage = ImageTag.createForBase(unityVersion);
|
||||
const baseImage = ImageTag.createForBase({ version: unityVersion, customImage });
|
||||
|
||||
// Build docker image
|
||||
const actionImage = await Docker.build({ path: actionFolder, dockerfile, baseImage });
|
||||
@@ -24,6 +26,7 @@ async function action() {
|
||||
projectPath,
|
||||
testMode,
|
||||
artifactsPath,
|
||||
useHostNetwork,
|
||||
customParameters,
|
||||
});
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ class Docker {
|
||||
--build-arg IMAGE=${baseImage} \
|
||||
--tag ${tag}`;
|
||||
|
||||
await exec(command, null, { silent });
|
||||
await exec(command, undefined, { silent });
|
||||
|
||||
return tag;
|
||||
}
|
||||
@@ -24,6 +24,7 @@ class Docker {
|
||||
projectPath,
|
||||
testMode,
|
||||
artifactsPath,
|
||||
useHostNetwork,
|
||||
customParameters,
|
||||
} = parameters;
|
||||
|
||||
@@ -31,6 +32,7 @@ class Docker {
|
||||
--workdir /github/workspace \
|
||||
--rm \
|
||||
--env UNITY_LICENSE \
|
||||
--env UNITY_LICENSE_FILE \
|
||||
--env UNITY_EMAIL \
|
||||
--env UNITY_PASSWORD \
|
||||
--env UNITY_SERIAL \
|
||||
@@ -59,9 +61,10 @@ class Docker {
|
||||
--volume "/home/runner/work/_temp/_github_home":"/github/home" \
|
||||
--volume "/home/runner/work/_temp/_github_workflow":"/github/workflow" \
|
||||
--volume "${workspace}":"/github/workspace" \
|
||||
${useHostNetwork ? '--net=host' : ''} \
|
||||
${image}`;
|
||||
|
||||
await exec(command, null, { silent });
|
||||
await exec(command, undefined, { silent });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,15 +6,20 @@ describe('Docker', () => {
|
||||
it('builds', async () => {
|
||||
const path = Action.actionFolder;
|
||||
const dockerfile = `${path}/Dockerfile`;
|
||||
const baseImage = new ImageTag({
|
||||
const image = new ImageTag({
|
||||
repository: '',
|
||||
name: 'alpine',
|
||||
version: '3',
|
||||
});
|
||||
|
||||
const baseImage = {
|
||||
toString: () => image.toString().slice(0, image.toString().lastIndexOf('-base-0')),
|
||||
version: image.version,
|
||||
};
|
||||
|
||||
const tag = await Docker.build({ path, dockerfile, baseImage }, true);
|
||||
|
||||
expect(tag).toBeInstanceOf(ImageTag);
|
||||
expect(tag.toString()).toStrictEqual('unity-action:3');
|
||||
expect(tag.toString()).toStrictEqual('unity-action:3-base-0');
|
||||
}, 240000);
|
||||
});
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { trimStart } from 'lodash-es';
|
||||
|
||||
class ImageTag {
|
||||
static createForBase(version) {
|
||||
const repository = 'gableroux';
|
||||
const name = 'unity3d';
|
||||
return new this({ repository, name, version });
|
||||
static createForBase({ version, customImage }) {
|
||||
const repository = 'unityci';
|
||||
const name = 'editor';
|
||||
return new this({ repository, name, version, customImage });
|
||||
}
|
||||
|
||||
static createForAction(version) {
|
||||
@@ -13,12 +13,12 @@ class ImageTag {
|
||||
return new this({ repository, name, version });
|
||||
}
|
||||
|
||||
constructor({ repository = '', name, version }) {
|
||||
constructor({ repository = '', name, version, customImage }) {
|
||||
if (!ImageTag.versionPattern.test(version)) {
|
||||
throw new Error(`Invalid version "${version}".`);
|
||||
}
|
||||
|
||||
Object.assign(this, { repository, name, version });
|
||||
Object.assign(this, { repository, name, version, customImage });
|
||||
}
|
||||
|
||||
static get versionPattern() {
|
||||
@@ -34,7 +34,11 @@ class ImageTag {
|
||||
}
|
||||
|
||||
toString() {
|
||||
return `${this.image}:${this.tag}`;
|
||||
if (this.customImage && this.customImage !== '') {
|
||||
return this.customImage;
|
||||
}
|
||||
|
||||
return `${this.image}:${this.tag}-base-0`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import ImageTag from './image-tag';
|
||||
|
||||
describe('UnityImageVersion', () => {
|
||||
describe('ImageTag', () => {
|
||||
describe('constructor', () => {
|
||||
const some = {
|
||||
name: 'someName',
|
||||
@@ -23,16 +23,25 @@ describe('UnityImageVersion', () => {
|
||||
expect(() => new ImageTag({ version })).not.toThrow();
|
||||
});
|
||||
|
||||
test.each(['some version', '', 1, null])('throws for incorrect versions %p', version => {
|
||||
test.each(['some version', '', 1, undefined])('throws for incorrect versions %p', version => {
|
||||
expect(() => new ImageTag({ version })).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('toString', () => {
|
||||
it('returns the correct version', () => {
|
||||
const image = ImageTag.createForBase('2099.1.1111');
|
||||
const image = ImageTag.createForBase({ version: '2099.1.1111' });
|
||||
|
||||
expect(image.toString()).toStrictEqual(`gableroux/unity3d:2099.1.1111`);
|
||||
expect(image.toString()).toStrictEqual(`unityci/editor:2099.1.1111-base-0`);
|
||||
});
|
||||
|
||||
it('returns customImage if given', () => {
|
||||
const image = ImageTag.createForBase({
|
||||
version: '2099.1.1111',
|
||||
customImage: 'unityci/editor:2099.1.1111-base-0',
|
||||
});
|
||||
|
||||
expect(image.toString()).toStrictEqual(image.customImage);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { getInput } from '@actions/core';
|
||||
import { includes } from 'lodash-es';
|
||||
import UnityVersionParser from './unity-version-parser';
|
||||
|
||||
class Input {
|
||||
static get testModes() {
|
||||
@@ -7,17 +8,19 @@ class Input {
|
||||
}
|
||||
|
||||
static isValidFolderName(folderName) {
|
||||
const validFolderName = new RegExp(/^(\.|\.\/)?(\.?\w+([-_]?\w+)*\/?)*$/);
|
||||
const validFolderName = new RegExp(/^(\.|\.\/)?(\.?\w+([_-]?\w+)*\/?)*$/);
|
||||
|
||||
return validFolderName.test(folderName);
|
||||
}
|
||||
|
||||
static getFromUser() {
|
||||
// Input variables specified in workflow using "with" prop.
|
||||
const unityVersion = getInput('unityVersion') || '2019.2.11f1';
|
||||
const rawUnityVersion = getInput('unityVersion') || 'auto';
|
||||
const customImage = getInput('customImage') || '';
|
||||
const testMode = getInput('testMode') || 'all';
|
||||
const rawProjectPath = getInput('projectPath') || '.';
|
||||
const rawArtifactsPath = getInput('artifactsPath') || 'artifacts';
|
||||
const rawUseHostNetwork = getInput('useHostNetwork') || 'false';
|
||||
const customParameters = getInput('customParameters') || '';
|
||||
|
||||
// Validate input
|
||||
@@ -33,16 +36,25 @@ class Input {
|
||||
throw new Error(`Invalid projectPath "${rawProjectPath}"`);
|
||||
}
|
||||
|
||||
if (rawUseHostNetwork !== 'true' && rawUseHostNetwork !== 'false') {
|
||||
throw new Error(`Invalid useHostNetwork "${rawUseHostNetwork}"`);
|
||||
}
|
||||
|
||||
// Sanitise input
|
||||
const projectPath = rawProjectPath.replace(/\/$/, '');
|
||||
const artifactsPath = rawArtifactsPath.replace(/\/$/, '');
|
||||
const useHostNetwork = rawUseHostNetwork === 'true';
|
||||
const unityVersion =
|
||||
rawUnityVersion === 'auto' ? UnityVersionParser.read(projectPath) : rawUnityVersion;
|
||||
|
||||
// Return sanitised input
|
||||
return {
|
||||
unityVersion,
|
||||
customImage,
|
||||
projectPath,
|
||||
testMode,
|
||||
artifactsPath,
|
||||
useHostNetwork,
|
||||
customParameters,
|
||||
};
|
||||
}
|
||||
|
||||
26
src/model/unity-version-parser.js
Normal file
26
src/model/unity-version-parser.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
class UnityVersionParser {
|
||||
static get versionPattern() {
|
||||
return /20\d{2}\.\d\.\w{3,4}|3/;
|
||||
}
|
||||
|
||||
static parse(projectVersionTxt) {
|
||||
const matches = projectVersionTxt.match(UnityVersionParser.versionPattern);
|
||||
if (!matches || matches.length === 0) {
|
||||
throw new Error(`Failed to parse version from "${projectVersionTxt}".`);
|
||||
}
|
||||
return matches[0];
|
||||
}
|
||||
|
||||
static read(projectPath) {
|
||||
const filePath = path.join(projectPath, 'ProjectSettings', 'ProjectVersion.txt');
|
||||
if (!fs.existsSync(filePath)) {
|
||||
return 'auto';
|
||||
}
|
||||
return UnityVersionParser.parse(fs.readFileSync(filePath, 'utf8'));
|
||||
}
|
||||
}
|
||||
|
||||
export default UnityVersionParser;
|
||||
25
src/model/unity-version-parser.test.js
Normal file
25
src/model/unity-version-parser.test.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import UnityVersionParser from './unity-version-parser';
|
||||
|
||||
describe('UnityVersionParser', () => {
|
||||
describe('parse', () => {
|
||||
it('throws for empty string', () => {
|
||||
expect(() => UnityVersionParser.parse('')).toThrow(Error);
|
||||
});
|
||||
|
||||
it('parses from ProjectVersion.txt', () => {
|
||||
const projectVersionContents = `m_EditorVersion: 2019.2.11f1
|
||||
m_EditorVersionWithRevision: 2019.2.11f1 (5f859a4cfee5)`;
|
||||
expect(UnityVersionParser.parse(projectVersionContents)).toBe('2019.2.11f1');
|
||||
});
|
||||
});
|
||||
|
||||
describe('read', () => {
|
||||
it('does not throw', () => {
|
||||
expect(() => UnityVersionParser.read('')).not.toThrow();
|
||||
});
|
||||
|
||||
it('reads from unity-project-with-correct-tests', () => {
|
||||
expect(UnityVersionParser.read('./unity-project-with-correct-tests')).toBe('2019.2.11f1');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class SampleComponent : MonoBehaviour
|
||||
{
|
||||
public BasicCounter Counter;
|
||||
|
||||
void Start()
|
||||
{
|
||||
Counter = new BasicCounter(5);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
Counter.Increment();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7a5f63b9ea4b465194653c4d681faf42
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,18 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class TimerComponent : MonoBehaviour
|
||||
{
|
||||
public BasicCounter Counter = new BasicCounter();
|
||||
public float Timer = 1f;
|
||||
|
||||
void Update()
|
||||
{
|
||||
Timer -= Time.deltaTime;
|
||||
|
||||
if (Timer > 0)
|
||||
return;
|
||||
|
||||
Counter.Increment();
|
||||
Timer = 1f;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b668d68a45bb48108ccda73269e3da7b
|
||||
timeCreated: 1610056748
|
||||
@@ -2,7 +2,8 @@
|
||||
"name": "PlayModeTests",
|
||||
"references": [
|
||||
"UnityEngine.TestRunner",
|
||||
"UnityEditor.TestRunner"
|
||||
"UnityEditor.TestRunner",
|
||||
"MyScripts"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
@@ -16,4 +17,4 @@
|
||||
"UNITY_INCLUDE_TESTS"
|
||||
],
|
||||
"versionDefines": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
using System.Collections;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace Tests
|
||||
{
|
||||
public class SampleComponentTest
|
||||
{
|
||||
private GameObject target;
|
||||
private SampleComponent component;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
target = GameObject.Instantiate(new GameObject());
|
||||
component = target.AddComponent<SampleComponent>();
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator TestIncrementOnUpdateAfterNextFrame()
|
||||
{
|
||||
// Save the current value, since it was updated after component Start() method called
|
||||
var count = component.Counter.Count;
|
||||
|
||||
// Skip frame and assert the new value
|
||||
yield return null;
|
||||
Assert.AreEqual(count + 1, component.Counter.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c688799d17b14d35ad515bff9de8d12c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,7 +1,5 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace Tests
|
||||
@@ -12,8 +10,14 @@ namespace Tests
|
||||
[Test]
|
||||
public void NewTestScriptSimplePasses()
|
||||
{
|
||||
// Use the Assert class to test conditions
|
||||
Assert.True(true);
|
||||
// Given
|
||||
var counter = new BasicCounter(0);
|
||||
|
||||
// When
|
||||
counter.Increment();
|
||||
|
||||
// Then
|
||||
Assert.AreEqual(1, counter.Count);
|
||||
}
|
||||
|
||||
// A UnityTest behaves like a coroutine in Play Mode. In Edit Mode you can use
|
||||
@@ -21,9 +25,18 @@ namespace Tests
|
||||
[UnityTest]
|
||||
public IEnumerator NewTestScriptWithEnumeratorPasses()
|
||||
{
|
||||
// Given
|
||||
var counter = new BasicCounter(3);
|
||||
|
||||
// Use the Assert class to test conditions.
|
||||
// Use yield to skip a frame.
|
||||
yield return null;
|
||||
|
||||
// When
|
||||
counter.Increment();
|
||||
|
||||
// Then
|
||||
Assert.AreEqual(4, counter.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
using System.Collections;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace Tests
|
||||
{
|
||||
public class TimerComponentTest
|
||||
{
|
||||
private GameObject target;
|
||||
private TimerComponent component;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
target = GameObject.Instantiate(new GameObject());
|
||||
component = target.AddComponent<TimerComponent>();
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator TestIncrementAfterSomeTime()
|
||||
{
|
||||
// Save the current value, since it was updated after component Start() method called
|
||||
var count = component.Counter.Count;
|
||||
|
||||
// Skip frame and assert the new value
|
||||
yield return null;
|
||||
Assert.AreEqual(count, component.Counter.Count);
|
||||
|
||||
yield return new WaitForSeconds(1.1f);
|
||||
Assert.AreEqual(count + 1, component.Counter.Count);
|
||||
|
||||
yield return new WaitForSeconds(1.1f);
|
||||
Assert.AreEqual(count + 2, component.Counter.Count);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator TestTimeScaleIsAffectingIncrement()
|
||||
{
|
||||
// Save the current value, since it was updated after component Start() method called
|
||||
var count = component.Counter.Count;
|
||||
Time.timeScale = .5f;
|
||||
|
||||
// Skip frame and assert the new value
|
||||
yield return null;
|
||||
Assert.AreEqual(count, component.Counter.Count);
|
||||
|
||||
yield return WaitForRealSeconds(1.1f);
|
||||
Assert.AreEqual(count, component.Counter.Count);
|
||||
|
||||
yield return WaitForRealSeconds(1.1f);
|
||||
Assert.AreEqual(count + 1, component.Counter.Count);
|
||||
}
|
||||
|
||||
// Skipping time ignoring Time.scale
|
||||
// https://answers.unity.com/questions/301868/yield-waitforseconds-outside-of-timescale.html
|
||||
public static IEnumerator WaitForRealSeconds(float time)
|
||||
{
|
||||
float start = Time.realtimeSinceStartup;
|
||||
while (Time.realtimeSinceStartup < start + time)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 818b22370d404398b87b47a922a435c9
|
||||
timeCreated: 1610056889
|
||||
Reference in New Issue
Block a user