Skip to content

Commit

Permalink
update settings for slack.
Browse files Browse the repository at this point in the history
  • Loading branch information
sassembla committed Dec 6, 2017
1 parent 177bebf commit d0a95b7
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 25 deletions.
9 changes: 0 additions & 9 deletions Assets/MiyamasuTestRunner/Runtime/Generated.meta

This file was deleted.

35 changes: 21 additions & 14 deletions Assets/MiyamasuTestRunner/Runtime/MainThreadRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,17 @@ public class MainThreadRunner : MonoBehaviour, IUUebViewEventHandler {
private string htmlContent = @"<!DOCTYPE uuebview href='resources://Views/ConsoleTag/UUebTags'>";

IEnumerator Start () {
var scene = UnityEngine.SceneManagement.SceneManager.GetActiveScene();
if (scene.name.StartsWith("InitTestScene") && "InitTestScene".Length < scene.name.Length) {
Destroy(this);
yield break;
}

while (testEnumerators == null) {
// wait to set enumGens;
yield return null;
}

// wait for check UnityTest is running or not.
yield return new WaitForSeconds(1);

Debug.Log("Editorの一覧からテストを実行した場合にテストを開始すると重複するので、停止させる、みたいな奴。");
// if (isRunning) {
// Destroy(this);
// yield break;
// }

var canvasCor = Resources.LoadAsync<GameObject>("MiyamasuPrefabs/MiyamasuCanvas");

while (!canvasCor.isDone) {
Expand Down Expand Up @@ -174,7 +171,6 @@ public void AddLog (ReportSource reportSource, ReportType type, Exception e, str
var id = Guid.NewGuid().ToString();
error = @" button='true' src='" + Base64Encode(e.ToString()) + @"' id='" + id + @"'";
}

logList.Add(@"
<bg" + error + @">
<textbg>
Expand All @@ -183,17 +179,18 @@ public void AddLog (ReportSource reportSource, ReportType type, Exception e, str
<iconbg><" + icon + @"/></iconbg>
</bg><br>");

var coroutines = new List<IEnumerator>();

// send result to slack.
switch (type) {
case ReportType.AssertionFailed:
case ReportType.FailedByTimeout:
case ReportType.Error: {
StartCoroutine(new SlackIntegration._SendLog("device:" + SystemInfo.deviceName + " failed " + reportSource.Description() + "\n" + e.ToString(), 0));
coroutines.Add(new SlackIntegration._SendLog("device:" + SystemInfo.deviceName + " failed " + reportSource.Description() + "\n" + e.ToString(), 0));
break;
}
case ReportType.Passed: {
StartCoroutine(new SlackIntegration._SendLog("device:" + SystemInfo.deviceName + " passed " + reportSource.Description(), 0));
coroutines.Add(new SlackIntegration._SendLog("device:" + SystemInfo.deviceName + " passed " + reportSource.Description(), 0));
break;
}
default: {
Expand All @@ -218,7 +215,11 @@ public void AddLog (ReportSource reportSource, ReportType type, Exception e, str

if (testEnumerators.Count == 0) {
var reportEndCor = new SlackIntegration._SendLog("all " + testCount + " tests finished. passed:" + passed + " failed:" + failed, 0);
StartCoroutine(reportEndCor);
coroutines.Add(reportEndCor);
}

if (coroutines.Any()) {
StartCoroutine(RunLogCoroutines(coroutines));
}

// restart test.
Expand All @@ -236,6 +237,12 @@ public void AddLog (ReportSource reportSource, ReportType type, Exception e, str
}
}

private IEnumerator RunLogCoroutines (List<IEnumerator> coroutines) {
foreach (var cor in coroutines) {
yield return cor;
}
}

private static string Base64Encode(string plainText) {
var plainTextBytes = Encoding.UTF8.GetBytes(plainText);
return Convert.ToBase64String(plainTextBytes);
Expand Down Expand Up @@ -345,4 +352,4 @@ void IUUebViewEventHandler.OnElementLongTapped (ContentType type, string param,
// throw new NotImplementedException();
}
}
}
}
Binary file not shown.
23 changes: 21 additions & 2 deletions Assets/MiyamasuTestRunner/Runtime/SlackIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private IEnumerator _WaitCor (string message, int type) {

/**
take screenshot then send to server.
*/
*/
public class _SendScreenshot : CustomYieldInstruction {
private readonly IEnumerator t;

Expand All @@ -105,12 +105,31 @@ private IEnumerator _WaitCor (string message) {
var fileName = message.Replace(" ", "_") + "_screenshot_" + DateTime.Now.ToString().Replace(":", "_").Replace(" ", "_").Replace("/", "_");
var basePath = Path.Combine(Application.persistentDataPath, fileName);

// hide miyamasu UI.
var testCanvas = GameObject.Find("MiyamasuCanvas");
if (testCanvas != null) {
var canvasAlpha = testCanvas.GetComponent<CanvasGroup>();
canvasAlpha.alpha = 0;
}

// 古いUnityだと、end of frameで処理をしないとUIが撮影できない、みたいなことがあるかもしれない。
// Unity5.6だとそのまま実行してUIが映る。

if (Application.isMobilePlatform) {
Application.CaptureScreenshot(fileName);// supersize = 0.
} else {
Application.CaptureScreenshot(basePath);// supersize = 0.
}

// wait 1 frame.
yield return null;

// show Miyamasu UI.
if (testCanvas != null) {
var canvasAlpha = testCanvas.GetComponent<CanvasGroup>();
canvasAlpha.alpha = 1;
}

while (!File.Exists(basePath)) {
yield return null;
}
Expand Down Expand Up @@ -247,4 +266,4 @@ private void SendScreenshotBytesAsync (byte[] bytes, Stream writeStream, FileStr
);
}
}
}
}
5 changes: 5 additions & 0 deletions Assets/MiyamasuTestRunnerTests/Editor/PackageGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ public class PackageGenerator {
// remove generated entry points.
Directory.Delete("Assets/MiyamasuTestRunner/Runtime/Generated", true);

var settings = Miyamasu.Settings.LoadSettings();
File.Delete("Assets/MiyamasuTestRunner/Runtime/Resources/MiyamasuSettings.txt");
Miyamasu.Settings.WriteSettings(new Miyamasu.RunnerSettings());

var assetPaths = new List<string>();
var packageSourcePath = "Assets/MiyamasuTestRunner";

CollectPathsRecursively(packageSourcePath, assetPaths);

AssetDatabase.ExportPackage(assetPaths.ToArray(), "MiyamasuTestRunner.unitypackage", ExportPackageOptions.IncludeDependencies);
Miyamasu.Settings.WriteSettings(settings);
}

private static void CollectPathsRecursively (string path, List<string> assetPaths) {
Expand Down
Binary file modified MiyamasuTestRunner.unitypackage
Binary file not shown.

0 comments on commit d0a95b7

Please sign in to comment.