diff --git a/packages/functional-tests/src/app.ts b/packages/functional-tests/src/app.ts index 4ddc105ae..fd1984fdd 100644 --- a/packages/functional-tests/src/app.ts +++ b/packages/functional-tests/src/app.ts @@ -37,7 +37,6 @@ export class App { private playPauseButton: MRE.Actor; private playPauseText: MRE.Actor; private runnerActors: MRE.Actor[]; - private sharedActors: MRE.Actor[]; private backgroundMaterial: MRE.Material; private testRoot: MRE.Actor; @@ -113,12 +112,6 @@ export class App { } return this.runPromise = this.runTestHelper(user); }) - .then(() => { - if (this.playPauseButton) { - this.playPauseButton.appearance.material.color.set(0, 1, 0, 1); - this.playPauseText.text.contents = "Start"; - } - }) // and log unexpected errors .catch(err => console.log(err)); } @@ -130,6 +123,13 @@ export class App { const test = this.activeTest = this.activeTestFactory(this, this.baseUrl, user); this.setOverrideText(test.expectedResultDescription); + this.testRoot = MRE.Actor.Create(this.context, { + actor: { + name: 'testRoot', + exclusiveToUser: this.exclusiveUser && this.exclusiveUser.id || undefined + } + }); + let success: boolean; try { test.checkPermission(user); @@ -149,20 +149,24 @@ export class App { if (success) { this.setOverrideText(null); } - - test.cleanup(); - - // Delete all actors - destroyActors(this.context.rootActors.filter(x => - !this.runnerActors.includes(x) && !this.sharedActors.includes(x))); } private async stopTest() { if (this.activeTest !== null) { this.activeTest.stop(); await this.runPromise; + this.activeTest.cleanup(); this.activeTest = null; this.runPromise = null; + + // Delete all actors + this.testRoot?.destroy(); + this.testRoot = null; + + if (this.playPauseButton) { + this.playPauseButton.appearance.material.color.set(0, 1, 0, 1); + this.playPauseText.text.contents = "Start"; + } } } @@ -194,17 +198,6 @@ export class App { const wasRunning = !!this.activeTest; await this.stopTest(); - if (this.testRoot) { - this.testRoot.destroy(); - } - - this.testRoot = MRE.Actor.Create(this.context, { - actor: { - name: 'testRoot', - exclusiveToUser: this.exclusiveUser && this.exclusiveUser.id || undefined - } - }); - if (wasRunning) { this.runTest(user); } @@ -251,7 +244,7 @@ export class App { this.exclusiveUserToggle.setBehavior(MRE.ButtonBehavior) .onButton('released', user => this.toggleExclusiveUser(user)); - const floor = MRE.Actor.Create(this.context, { + MRE.Actor.Create(this.context, { actor: { name: 'floor', appearance: { @@ -267,7 +260,7 @@ export class App { } }); - const wall = MRE.Actor.Create(this.context, { + MRE.Actor.Create(this.context, { actor: { name: 'wall', appearance: { @@ -282,8 +275,6 @@ export class App { collider: { geometry: { shape: MRE.ColliderType.Auto } } } }); - - this.sharedActors = [this.exclusiveUserToggle, label, wall, floor]; } private setupRunner() { @@ -306,23 +297,16 @@ export class App { } }); - this.testRoot = MRE.Actor.Create(this.context, { - actor: { - name: 'testRoot', - exclusiveToUser: this.exclusiveUser && this.exclusiveUser.id || undefined - } - }); - if (this.params.nomenu === 'true') { this.runnerActors = [this.contextLabel]; return; } // start or stop the active test - const ppMat = this.assets.createMaterial('pp', { - color: MRE.Color3.Green().toJSON() - }); - const ppMesh = this.assets.createBoxMesh('playpause', 0.7, 0.3, 0.1); + const ppMat = this.assets.materials.find(m => m.name === 'ppMat') || + this.assets.createMaterial('ppMat', { color: MRE.Color3.Green() }); + const ppMesh = this.assets.materials.find(m => m.name === 'ppMesh') || + this.assets.createBoxMesh('ppMesh', 0.7, 0.3, 0.1); this.playPauseButton = MRE.Actor.Create(this.context, { actor: { @@ -363,7 +347,7 @@ export class App { if (this.activeTest === null) { this.runTest(user); } else { - this.stopTest().catch(() => { }); + this.stopTest().catch(err => MRE.log.error('app', err)); } }); diff --git a/packages/functional-tests/src/utils/destroyActors.ts b/packages/functional-tests/src/utils/destroyActors.ts index e8090b8ab..3996d2a25 100644 --- a/packages/functional-tests/src/utils/destroyActors.ts +++ b/packages/functional-tests/src/utils/destroyActors.ts @@ -10,7 +10,7 @@ export default function destroyActors(actors: Actor | Actor[]): Actor[] { actors = [actors]; } for (const actor of actors) { - actor.destroy(); + actor?.destroy(); } return []; }