diff --git a/addon/package.json b/addon/package.json index 7ddf94c3..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:'", @@ -43,7 +52,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/index.js b/addon/src/index.js index 62da85eb..94fc35aa 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 @@ -190,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 @@ -200,10 +195,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(); } @@ -216,10 +207,6 @@ export function start(options = {}) { setupEmberTesting(); } - if (options.setupEmberOnerrorValidation !== false) { - setupEmberOnerrorValidation(); - } - if ( typeof options.setupTestIsolationValidation !== 'undefined' && options.setupTestIsolationValidation !== false 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/addon/types/index.d.ts b/addon/types/index.d.ts index aa31b9f0..c40da7a5 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. @@ -116,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, @@ -281,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; + } } } 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/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' diff --git a/test-app/tests/test-helper.js b/test-app/tests/test-helper.js index 81843044..476c7085 100644 --- a/test-app/tests/test-helper.js +++ b/test-app/tests/test-helper.js @@ -3,10 +3,13 @@ import config from 'test-app/config/environment'; import * as QUnit from 'qunit'; import { setApplication } from '@ember/test-helpers'; import { setup } from 'qunit-dom'; -import { start } from 'ember-qunit'; +import { loadTests } from 'ember-qunit/test-loader'; +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. */