From dc63a2449001eca92b2b3933799b073775372226 Mon Sep 17 00:00:00 2001 From: Sergio Arbeo Date: Fri, 9 Mar 2018 18:36:11 +0100 Subject: [PATCH] [BUGFIX] Fix initialiters tests blueprints Fixes #16344 --- .../tests/unit/initializers/__name__-test.js | 4 ++-- blueprints/instance-initializer-test/index.js | 5 ++++- .../tests/unit/instance-initializers/__name__-test.js | 6 +++--- .../tests/unit/instance-initializers/__name__-test.js | 6 +++--- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/blueprints/initializer-test/qunit-rfc-232-files/tests/unit/initializers/__name__-test.js b/blueprints/initializer-test/qunit-rfc-232-files/tests/unit/initializers/__name__-test.js index d4785e0ed6c..40609d2c3cd 100644 --- a/blueprints/initializer-test/qunit-rfc-232-files/tests/unit/initializers/__name__-test.js +++ b/blueprints/initializer-test/qunit-rfc-232-files/tests/unit/initializers/__name__-test.js @@ -3,7 +3,7 @@ import Application from '@ember/application'; import { initialize } from '<%= dasherizedModulePrefix %>/initializers/<%= dasherizedModuleName %>'; import { module, test } from 'qunit'; import { setupTest } from 'ember-qunit'; -import destroyApp from '../../helpers/destroy-app'; +<% if (destroyAppExists) { %>import destroyApp from '../../helpers/destroy-app';<% } else { %>import { run } from '@ember/runloop';<% } %> module('<%= friendlyTestName %>', function(hooks) { setupTest(hooks); @@ -19,7 +19,7 @@ module('<%= friendlyTestName %>', function(hooks) { }); hooks.afterEach(function() { - destroyApp(this.application); + <% if (destroyAppExists) { %>destroyApp(this.application);<% } else { %>run(this.application, 'destroy');<% } %> }); // Replace this with your real tests. diff --git a/blueprints/instance-initializer-test/index.js b/blueprints/instance-initializer-test/index.js index 9bdd983b8d2..1830457ea7c 100644 --- a/blueprints/instance-initializer-test/index.js +++ b/blueprints/instance-initializer-test/index.js @@ -1,5 +1,7 @@ 'use strict'; +const path = require('path'); +const existsSync = require('exists-sync'); const stringUtils = require('ember-cli-string-utils'); const useTestFrameworkDetector = require('../test-framework-detector'); @@ -9,7 +11,8 @@ module.exports = useTestFrameworkDetector({ locals: function(options) { return { friendlyTestName: ['Unit', 'Instance Initializer', options.entity.name].join(' | '), - dasherizedModulePrefix: stringUtils.dasherize(options.project.config().modulePrefix) + dasherizedModulePrefix: stringUtils.dasherize(options.project.config().modulePrefix), + destroyAppExists: existsSync(path.join(this.project.root, '/tests/helpers/destroy-app.js')) }; } }); diff --git a/blueprints/instance-initializer-test/qunit-files/tests/unit/instance-initializers/__name__-test.js b/blueprints/instance-initializer-test/qunit-files/tests/unit/instance-initializers/__name__-test.js index 57b271fe050..7c9825b7ee2 100644 --- a/blueprints/instance-initializer-test/qunit-files/tests/unit/instance-initializers/__name__-test.js +++ b/blueprints/instance-initializer-test/qunit-files/tests/unit/instance-initializers/__name__-test.js @@ -1,8 +1,8 @@ import Application from '@ember/application'; import { run } from '@ember/runloop'; import { initialize } from '<%= dasherizedModulePrefix %>/instance-initializers/<%= dasherizedModuleName %>'; -import { module, test } from 'qunit'; -import destroyApp from '../../helpers/destroy-app'; +import { module, test } from 'qunit';<% if (destroyAppExists) { %> +import destroyApp from '../../helpers/destroy-app';<% } %> module('<%= friendlyTestName %>', { beforeEach() { @@ -13,7 +13,7 @@ module('<%= friendlyTestName %>', { }, afterEach() { run(this.appInstance, 'destroy'); - destroyApp(this.application); + <% if (destroyAppExists) { %>destroyApp(this.application);<% } else { %>run(this.application, 'destroy');<% } %> } }); diff --git a/blueprints/instance-initializer-test/qunit-rfc-232-files/tests/unit/instance-initializers/__name__-test.js b/blueprints/instance-initializer-test/qunit-rfc-232-files/tests/unit/instance-initializers/__name__-test.js index 9782808f480..0e67d1414d7 100644 --- a/blueprints/instance-initializer-test/qunit-rfc-232-files/tests/unit/instance-initializers/__name__-test.js +++ b/blueprints/instance-initializer-test/qunit-rfc-232-files/tests/unit/instance-initializers/__name__-test.js @@ -3,7 +3,7 @@ import Application from '@ember/application'; import { initialize } from '<%= dasherizedModulePrefix %>/instance-initializers/<%= dasherizedModuleName %>'; import { module, test } from 'qunit'; import { setupTest } from 'ember-qunit'; -import destroyApp from '../../helpers/destroy-app'; +<% if (destroyAppExists) { %>import destroyApp from '../../helpers/destroy-app';<% } else { %>import { run } from '@ember/runloop';<% } %> module('<%= friendlyTestName %>', function(hooks) { setupTest(hooks); @@ -18,8 +18,8 @@ module('<%= friendlyTestName %>', function(hooks) { this.instance = this.application.buildInstance(); }); hooks.afterEach(function() { - destroyApp(this.application); - destroyApp(this.instance); + <% if (destroyAppExists) { %>destroyApp(this.application);<% } else { %>run(this.application, 'destroy');<% } %> + <% if (destroyAppExists) { %>destroyApp(this.instance);<% } else { %>run(this.instance, 'destroy');<% } %> }); // Replace this with your real tests.