From 3428b769dc432449ff940760e08a96698b20d33f Mon Sep 17 00:00:00 2001 From: Edward Faulkner Date: Tue, 17 Dec 2024 10:41:29 -0500 Subject: [PATCH 1/4] Inline ember-cli-test-loader implementation --- addon/package.json | 1 - addon/src/test-loader.js | 93 ++++++++++++++++++++++++++++++++-------- pnpm-lock.yaml | 7 --- 3 files changed, 76 insertions(+), 25 deletions(-) diff --git a/addon/package.json b/addon/package.json index 7ddf94c3..8dcbe0a7 100644 --- a/addon/package.json +++ b/addon/package.json @@ -43,7 +43,6 @@ "dependencies": { "@embroider/addon-shim": "^1.8.6", "@embroider/macros": "^1.13.1", - "ember-cli-test-loader": "^3.1.0", "qunit-theme-ember": "^1.0.0" }, "devDependencies": { diff --git a/addon/src/test-loader.js b/addon/src/test-loader.js index 4b51ca04..b3daeeba 100644 --- a/addon/src/test-loader.js +++ b/addon/src/test-loader.js @@ -1,11 +1,81 @@ +/* globals requirejs, require */ + import * as QUnit from 'qunit'; -import AbstractTestLoader, { - addModuleIncludeMatcher, -} from 'ember-cli-test-loader/test-support/index'; -addModuleIncludeMatcher(function (moduleName) { - return moduleName.match(/\.jshint$/); -}); +class TestLoader { + static load() { + new TestLoader().loadModules(); + } + + constructor() { + this._didLogMissingUnsee = false; + } + + shouldLoadModule(moduleName) { + return moduleName.match(/[-_]test$/); + } + + listModules() { + return Object.keys(requirejs.entries); + } + + listTestModules() { + let moduleNames = this.listModules(); + let testModules = []; + let moduleName; + + for (let i = 0; i < moduleNames.length; i++) { + moduleName = moduleNames[i]; + + if (this.shouldLoadModule(moduleName)) { + testModules.push(moduleName); + } + } + + return testModules; + } + + loadModules() { + let testModules = this.listTestModules(); + let testModule; + + for (let i = 0; i < testModules.length; i++) { + testModule = testModules[i]; + this.require(testModule); + this.unsee(testModule); + } + } + + require(moduleName) { + try { + require(moduleName); + } catch (e) { + this.moduleLoadFailure(moduleName, e); + } + } + + unsee(moduleName) { + if (typeof require.unsee === 'function') { + require.unsee(moduleName); + } else if (!this._didLogMissingUnsee) { + this._didLogMissingUnsee = true; + if (typeof console !== 'undefined') { + console.warn( + 'unable to require.unsee, please upgrade loader.js to >= v3.3.0' + ); + } + } + } + + moduleLoadFailure(moduleName, error) { + moduleLoadFailures.push(error); + + QUnit.module('TestLoader Failures'); + QUnit.test(moduleName + ': could not be loaded', function () { + throw error; + }); + } +} let moduleLoadFailures = []; @@ -26,17 +96,6 @@ QUnit.done(function () { } }); -export class TestLoader extends AbstractTestLoader { - moduleLoadFailure(moduleName, error) { - moduleLoadFailures.push(error); - - QUnit.module('TestLoader Failures'); - QUnit.test(moduleName + ': could not be loaded', function () { - throw error; - }); - } -} - /** Load tests following the default patterns: diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 74a5387f..2cf3e6de 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -16,9 +16,6 @@ importers: '@embroider/macros': specifier: ^1.13.1 version: 1.13.1 - ember-cli-test-loader: - specifier: ^3.1.0 - version: 3.1.0 qunit-theme-ember: specifier: ^1.0.0 version: 1.0.0 @@ -3680,9 +3677,6 @@ packages: /ajv-formats@2.1.1: resolution: {integrity: sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==} - peerDependenciesMeta: - ajv: - optional: true dependencies: ajv: 8.11.0 @@ -13902,7 +13896,6 @@ packages: resolution: {directory: addon, type: directory} id: file:addon name: ember-qunit - version: 8.1.0 peerDependencies: '@ember/test-helpers': '>=3.0.3' ember-source: '>=4.0.0' From d716b61cfd32a184aab82006ecfdebfd742ab7d3 Mon Sep 17 00:00:00 2001 From: Edward Faulkner Date: Tue, 17 Dec 2024 10:53:52 -0500 Subject: [PATCH 2/4] Separate test loading from start --- addon/package.json | 13 +++++++++++-- addon/src/index.js | 7 ------- addon/types/index.d.ts | 5 ----- addon/types/test-loader.d.ts | 1 + test-app/tests/test-helper.js | 2 ++ 5 files changed, 14 insertions(+), 14 deletions(-) create mode 100644 addon/types/test-loader.d.ts diff --git a/addon/package.json b/addon/package.json index 8dcbe0a7..5f8ef31a 100644 --- a/addon/package.json +++ b/addon/package.json @@ -22,7 +22,10 @@ "types": "./types/index.d.ts", "default": "./dist/index.js" }, - "./*": "./dist/*.js", + "./*": { + "types": "./types/*.d.ts", + "default": "./dist/*.js" + }, "./addon-main.js": "./addon-main.cjs" }, "files": [ @@ -30,7 +33,13 @@ "types", "addon-main.cjs" ], - "types": "types/index.d.ts", + "typesVersions": { + "*": { + "*": [ + "types/*" + ] + } + }, "scripts": { "build": "rollup --config", "lint": "concurrently 'npm:lint:*(!fix)' --names 'lint:'", diff --git a/addon/src/index.js b/addon/src/index.js index 62da85eb..7de58495 100644 --- a/addon/src/index.js +++ b/addon/src/index.js @@ -23,7 +23,6 @@ if (macroCondition(getOwnConfig()?.theme === 'ember')) { } export { default as QUnitAdapter, nonTestDoneCallback } from './adapter'; -export { loadTests } from './test-loader'; import './qunit-configuration'; @@ -33,7 +32,6 @@ if (typeof Testem !== 'undefined') { import { _backburner } from '@ember/runloop'; import { resetOnerror, getTestMetadata } from '@ember/test-helpers'; -import { loadTests } from './test-loader'; import Ember from 'ember'; import * as QUnit from 'qunit'; import QUnitAdapter from './adapter'; @@ -180,7 +178,6 @@ export function setupTestIsolationValidation(delay) { /** @method start @param {Object} [options] Options to be used for enabling/disabling behaviors - @param {Boolean} [options.loadTests] If `false` tests will not be loaded automatically. @param {Boolean} [options.setupTestContainer] If `false` the test container will not be setup based on `devmode`, `dockcontainer`, or `nocontainer` URL params. @param {Boolean} [options.startTests] If `false` tests will not be automatically started @@ -200,10 +197,6 @@ export function setupTestIsolationValidation(delay) { async to have been completed. The default value is 50. */ export function start(options = {}) { - if (options.loadTests !== false) { - loadTests(); - } - if (options.setupTestContainer !== false) { setupTestContainer(); } diff --git a/addon/types/index.d.ts b/addon/types/index.d.ts index aa31b9f0..f4003444 100644 --- a/addon/types/index.d.ts +++ b/addon/types/index.d.ts @@ -88,11 +88,6 @@ export class QUnitAdapter extends EmberTestAdapter {} export { module, test, skip, only, todo } from 'qunit'; interface QUnitStartOptions { - /** - * If `false` tests will not be loaded automatically. - */ - loadTests?: boolean | undefined; - /** * If `false` the test container will not be setup based on `devmode`, * `dockcontainer`, or `nocontainer` URL params. diff --git a/addon/types/test-loader.d.ts b/addon/types/test-loader.d.ts new file mode 100644 index 00000000..2e71ab62 --- /dev/null +++ b/addon/types/test-loader.d.ts @@ -0,0 +1 @@ +export function loadTests(): void; diff --git a/test-app/tests/test-helper.js b/test-app/tests/test-helper.js index 81843044..d6a034f1 100644 --- a/test-app/tests/test-helper.js +++ b/test-app/tests/test-helper.js @@ -3,10 +3,12 @@ import config from 'test-app/config/environment'; import * as QUnit from 'qunit'; import { setApplication } from '@ember/test-helpers'; import { setup } from 'qunit-dom'; +import { loadTests } from 'ember-qunit/test-loader'; import { start } from 'ember-qunit'; setApplication(Application.create(config.APP)); setup(QUnit.assert); +loadTests(); start(); From 634761bc1eb7785879ed915dab32eb130e1eeb34 Mon Sep 17 00:00:00 2001 From: Edward Faulkner Date: Tue, 17 Dec 2024 11:46:16 -0500 Subject: [PATCH 3/4] separate onerror validation too --- addon/src/index.js | 6 ------ test-app/tests/test-helper.js | 3 ++- test-app/types/index.d.ts | 7 ++----- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/addon/src/index.js b/addon/src/index.js index 7de58495..94fc35aa 100644 --- a/addon/src/index.js +++ b/addon/src/index.js @@ -187,8 +187,6 @@ export function setupTestIsolationValidation(delay) { @param {Boolean} [options.setupEmberTesting] `false` opts out of the default behavior of setting `Ember.testing` to `true` before all tests and back to `false` after each test will. - @param {Boolean} [options.setupEmberOnerrorValidation] If `false` validation - of `Ember.onerror` will be disabled. @param {Boolean} [options.setupTestIsolationValidation] If `false` test isolation validation will be disabled. @param {Number} [options.testIsolationValidationDelay] When using @@ -209,10 +207,6 @@ export function start(options = {}) { setupEmberTesting(); } - if (options.setupEmberOnerrorValidation !== false) { - setupEmberOnerrorValidation(); - } - if ( typeof options.setupTestIsolationValidation !== 'undefined' && options.setupTestIsolationValidation !== false diff --git a/test-app/tests/test-helper.js b/test-app/tests/test-helper.js index d6a034f1..476c7085 100644 --- a/test-app/tests/test-helper.js +++ b/test-app/tests/test-helper.js @@ -4,11 +4,12 @@ import * as QUnit from 'qunit'; import { setApplication } from '@ember/test-helpers'; import { setup } from 'qunit-dom'; import { loadTests } from 'ember-qunit/test-loader'; -import { start } from 'ember-qunit'; +import { start, setupEmberOnerrorValidation } from 'ember-qunit'; setApplication(Application.create(config.APP)); setup(QUnit.assert); +setupEmberOnerrorValidation(); loadTests(); start(); diff --git a/test-app/types/index.d.ts b/test-app/types/index.d.ts index d11b83d5..5976747a 100644 --- a/test-app/types/index.d.ts +++ b/test-app/types/index.d.ts @@ -87,6 +87,8 @@ export class QUnitAdapter extends EmberTestAdapter {} export { module, test, skip, only, todo } from 'qunit'; +export function setupEmberOnerrorValidation(): void; + interface QUnitStartOptions { /** * If `false` tests will not be loaded automatically. @@ -116,11 +118,6 @@ interface QUnitStartOptions { */ setupEmberTesting?: boolean | undefined; - /** - * If `false` validation of `Ember.onerror` will be disabled. - */ - setupEmberOnerrorValidation?: boolean | undefined; - /** * If `false` test isolation validation will be disabled. */ From e4a9efd750dbeab67a03a6032a6613fc1dc40ff7 Mon Sep 17 00:00:00 2001 From: Edward Faulkner Date: Tue, 17 Dec 2024 12:04:38 -0500 Subject: [PATCH 4/4] fix missing type --- addon/types/index.d.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/addon/types/index.d.ts b/addon/types/index.d.ts index f4003444..c40da7a5 100644 --- a/addon/types/index.d.ts +++ b/addon/types/index.d.ts @@ -111,17 +111,14 @@ interface QUnitStartOptions { */ setupEmberTesting?: boolean | undefined; - /** - * If `false` validation of `Ember.onerror` will be disabled. - */ - setupEmberOnerrorValidation?: boolean | undefined; - /** * If `false` test isolation validation will be disabled. */ setupTestIsolationValidation?: boolean | undefined; } +export function setupEmberOnerrorValidation(): void; + export function start(options?: QUnitStartOptions): void; // SAFETY: all of the `TC extends TestContext` generics below are just wildly, @@ -276,10 +273,10 @@ declare global { interface EachFunction { ( - name: string, - dataset: T[], - callback: (this: TC, assert: Assert, data: T) => void | Promise - ): void; - } + name: string, + dataset: T[], + callback: (this: TC, assert: Assert, data: T) => void | Promise + ): void; + } } }