From ed979a8bccf26968d51f0119b1bf9dcaf6250e9b Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Mon, 16 Aug 2021 17:10:20 -0600 Subject: [PATCH 1/3] Enable embroider-safe ember-try scenario --- .github/workflows/ci-build.yml | 1 + config/ember-try.js | 53 +++++++++++++++++++ ember-cli-build.js | 25 ++++----- .../vendor/ember-cli/test-support-suffix.js | 16 ++++++ tests/index.html | 10 ++-- tests/test-helper.js | 7 +++ vendor/.gitkeep | 0 vendor/shims/qunit.js | 18 ------- 8 files changed, 95 insertions(+), 35 deletions(-) create mode 100644 tests/dummy/vendor/ember-cli/test-support-suffix.js delete mode 100644 vendor/.gitkeep delete mode 100644 vendor/shims/qunit.js diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 8afa8509..e0c52ad7 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -58,6 +58,7 @@ jobs: - ember-canary - ember-classic - ember-default-with-jquery + - embroider-safe steps: - uses: actions/checkout@v2 diff --git a/config/ember-try.js b/config/ember-try.js index a5e2a0da..94dba77d 100644 --- a/config/ember-try.js +++ b/config/ember-try.js @@ -2,6 +2,45 @@ const getChannelURL = require('ember-source-channel-url'); +const EMBROIDER_VERSION = '^0.43.4'; +const embroider = { + safe: { + name: 'embroider-safe', + npm: { + devDependencies: { + '@embroider/core': EMBROIDER_VERSION, + '@embroider/webpack': EMBROIDER_VERSION, + '@embroider/compat': EMBROIDER_VERSION, + '@embroider/test-setup': EMBROIDER_VERSION, + + // Webpack is a peer dependency of `@embroider/webpack` + webpack: '^5.0.0', + }, + }, + env: { + EMBROIDER_TEST_SETUP_OPTIONS: 'safe', + }, + }, + + optimized: { + name: 'embroider-optimized', + npm: { + devDependencies: { + '@embroider/core': EMBROIDER_VERSION, + '@embroider/webpack': EMBROIDER_VERSION, + '@embroider/compat': EMBROIDER_VERSION, + '@embroider/test-setup': EMBROIDER_VERSION, + + // Webpack is a peer dependency of `@embroider/webpack` + webpack: '^5.0.0', + }, + }, + env: { + EMBROIDER_TEST_SETUP_OPTIONS: 'optimized', + }, + }, +}; + module.exports = async function () { return { useYarn: true, @@ -103,6 +142,20 @@ module.exports = async function () { devDependencies: {}, }, }, + embroider.safe, + // disable embroider optimized test scenarios, as the dynamism these + // tests use is not compatible with embroider we are still exploring + // appropriate paths forward. + // + // Steps to re-enable: + // + // 1. have a strategy to make this work + // 2. uncomment the next line + // embroider.optimized, + // + // 3. add "embroider-optimized" to .github/workflows/ci-build.yml's + // ember-try-scenario list. + // ], }; }; diff --git a/ember-cli-build.js b/ember-cli-build.js index 3f60c2bc..3b9d5119 100644 --- a/ember-cli-build.js +++ b/ember-cli-build.js @@ -3,21 +3,22 @@ const EmberAddon = require('ember-cli/lib/broccoli/ember-addon'); module.exports = function (defaults) { - let app = new EmberAddon(defaults, { - autoImport: { - exclude: ['qunit'], - }, - }); - - app.import('node_modules/qunit/qunit/qunit.js', { - type: 'test', - }); + let app = new EmberAddon(defaults); app.import('node_modules/qunit/qunit/qunit.css', { type: 'test', }); - app.import('vendor/shims/qunit.js', { type: 'test' }); - - return app.toTree(); + try { + const { maybeEmbroider } = require('@embroider/test-setup'); // eslint-disable-line node/no-missing-require + return maybeEmbroider(app); + } catch (e) { + // This exists, so that we can continue to support node 10 for some of our + // test scenarios. Specifically those not scenario testing embroider. As + // @embroider/test-setup and @embroider in no longer supports node 10 + if (e !== null && typeof e === 'object' && e.code === 'MODULE_NOT_FOUND') { + return app.toTree(); + } + throw e; + } }; diff --git a/tests/dummy/vendor/ember-cli/test-support-suffix.js b/tests/dummy/vendor/ember-cli/test-support-suffix.js new file mode 100644 index 00000000..c2b2eab9 --- /dev/null +++ b/tests/dummy/vendor/ember-cli/test-support-suffix.js @@ -0,0 +1,16 @@ +// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars +/* global runningTests: true */ + +/* + used to determine if the application should be booted immediately when `app-name.js` is evaluated + when `runningTests` the `app-name.js` file will **not** import the applications `app/app.js` and + call `Application.create(...)` on it. Additionally, applications can opt-out of this behavior by + setting `autoRun` to `false` in their `ember-cli-build.js` +*/ +runningTests = true; +/* + This file overrides a file built into ember-cli's build pipeline and prevents + this built-in `Testem.hookIntoTestFramework` invocation: + + https://github.com/ember-cli/ember-cli/blob/v3.20.0/lib/broccoli/test-support-suffix.js#L3-L5 +*/ diff --git a/tests/index.html b/tests/index.html index efa55899..6d13069a 100644 --- a/tests/index.html +++ b/tests/index.html @@ -22,13 +22,13 @@ {{content-for "test-body"}}
-
- -
-
+
+
+
+
- + diff --git a/tests/test-helper.js b/tests/test-helper.js index 4167cb36..6b22b261 100644 --- a/tests/test-helper.js +++ b/tests/test-helper.js @@ -1,3 +1,5 @@ +/* globals Testem */ + import QUnit from 'qunit'; import AbstractTestLoader from 'ember-cli-test-loader/test-support/index'; import { polyfill } from 'es6-promise'; @@ -34,3 +36,8 @@ QUnit.testDone(function () { let testElementReset = testElementContainer.outerHTML; testElementContainer.innerHTML = testElementReset; }); + +QUnit.start(); +if (typeof Testem !== 'undefined') { + Testem.hookIntoTestFramework(); +} diff --git a/vendor/.gitkeep b/vendor/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/vendor/shims/qunit.js b/vendor/shims/qunit.js deleted file mode 100644 index f680cd71..00000000 --- a/vendor/shims/qunit.js +++ /dev/null @@ -1,18 +0,0 @@ -/* globals define, self */ - -(function() { - function vendorModule() { - 'use strict'; - - return { - default: self.QUnit, - module: self.QUnit.module, - test: self.QUnit.test, - todo: self.QUnit.todo, - skip: self.QUnit.skip, - __esModule: true, - }; - } - - define('qunit', [], vendorModule); -})(); From cc9314908a096d493f3b624f1dc7d71149f435c7 Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Tue, 17 Aug 2021 11:04:17 -0600 Subject: [PATCH 2/3] Use same polyfil as @ember/test-helpers & unit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit note: This fixes an embroider related issue, where when IE11 was included as a build target (in CI mode) es6-promise, babel, and webpack didn’t get along. (As described [here](https://github.com/embroider-build/embroider/issues/731#issuecomment-808788950)) --- package.json | 2 +- tests/test-helper.js | 5 ++--- yarn.lock | 7 ++++++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index eed171a6..73b64706 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,6 @@ "ember-source": "~3.24.1", "ember-source-channel-url": "^3.0.0", "ember-try": "^1.4.0", - "es6-promise": "^4.2.8", "eslint": "^7.32.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-ember": "^7.8.1", @@ -85,6 +84,7 @@ "loader.js": "^4.7.0", "npm-run-all": "^4.1.5", "prettier": "^2.2.1", + "promise-polyfill": "^8.2.0", "qunit": "^2.16.0", "release-it": "^14.11.5", "release-it-lerna-changelog": "^3.1.0", diff --git a/tests/test-helper.js b/tests/test-helper.js index 6b22b261..04860d0f 100644 --- a/tests/test-helper.js +++ b/tests/test-helper.js @@ -2,12 +2,11 @@ import QUnit from 'qunit'; import AbstractTestLoader from 'ember-cli-test-loader/test-support/index'; -import { polyfill } from 'es6-promise'; - +import PromisePolyfill from 'promise-polyfill'; // When running under IE11, our tests are transpiled to use `Promise` (due to // asyncToGenerator helper in Babel) if (typeof Promise === 'undefined') { - polyfill(); + self.Promise = PromisePolyfill; } let moduleLoadFailures = []; diff --git a/yarn.lock b/yarn.lock index e206681e..c7779ac7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6733,7 +6733,7 @@ es-to-primitive@^1.2.1: is-date-object "^1.0.1" is-symbol "^1.0.2" -es6-promise@^4.0.3, es6-promise@^4.2.8: +es6-promise@^4.0.3: version "4.2.8" resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-4.2.8.tgz#4eb21594c972bc40553d276e510539143db53e0a" integrity sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w== @@ -11286,6 +11286,11 @@ promise-map-series@^0.3.0: resolved "https://registry.yarnpkg.com/promise-map-series/-/promise-map-series-0.3.0.tgz#41873ca3652bb7a042b387d538552da9b576f8a1" integrity sha512-3npG2NGhTc8BWBolLLf8l/92OxMGaRLbqvIh9wjCHhDXNvk4zsxaTaCpiCunW09qWPrN2zeNSNwRLVBrQQtutA== +promise-polyfill@^8.2.0: + version "8.2.0" + resolved "https://registry.yarnpkg.com/promise-polyfill/-/promise-polyfill-8.2.0.tgz#367394726da7561457aba2133c9ceefbd6267da0" + integrity sha512-k/TC0mIcPVF6yHhUvwAp7cvL6I2fFV7TzF1DuGPI8mBh4QQazf36xCKEHKTZKRysEoTQoQdKyP25J8MPJp7j5g== + promise-retry@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/promise-retry/-/promise-retry-1.1.1.tgz#6739e968e3051da20ce6497fb2b50f6911df3d6d" From ae85ebf041b0fca31d58f05de883008a8f9d9ffb Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Tue, 17 Aug 2021 11:38:48 -0600 Subject: [PATCH 3/3] Add embroider-optimized scenario --- .github/workflows/ci-build.yml | 1 + config/ember-try.js | 14 +------------- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index e0c52ad7..e1d0fa17 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -59,6 +59,7 @@ jobs: - ember-classic - ember-default-with-jquery - embroider-safe + - embroider-optimized steps: - uses: actions/checkout@v2 diff --git a/config/ember-try.js b/config/ember-try.js index 94dba77d..cf81a258 100644 --- a/config/ember-try.js +++ b/config/ember-try.js @@ -143,19 +143,7 @@ module.exports = async function () { }, }, embroider.safe, - // disable embroider optimized test scenarios, as the dynamism these - // tests use is not compatible with embroider we are still exploring - // appropriate paths forward. - // - // Steps to re-enable: - // - // 1. have a strategy to make this work - // 2. uncomment the next line - // embroider.optimized, - // - // 3. add "embroider-optimized" to .github/workflows/ci-build.yml's - // ember-try-scenario list. - // + embroider.optimized, ], }; };