Skip to content

Commit 18d5ca9

Browse files
authored
Merge pull request #1182 from emberjs/isolate-test-loading
Require explicit calls to loadTests and setupEmberOnerrorValidation
2 parents da520e0 + e4a9efd commit 18d5ca9

File tree

8 files changed

+101
-61
lines changed

8 files changed

+101
-61
lines changed

addon/package.json

+11-3
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,24 @@
2222
"types": "./types/index.d.ts",
2323
"default": "./dist/index.js"
2424
},
25-
"./*": "./dist/*.js",
25+
"./*": {
26+
"types": "./types/*.d.ts",
27+
"default": "./dist/*.js"
28+
},
2629
"./addon-main.js": "./addon-main.cjs"
2730
},
2831
"files": [
2932
"dist",
3033
"types",
3134
"addon-main.cjs"
3235
],
33-
"types": "types/index.d.ts",
36+
"typesVersions": {
37+
"*": {
38+
"*": [
39+
"types/*"
40+
]
41+
}
42+
},
3443
"scripts": {
3544
"build": "rollup --config",
3645
"lint": "concurrently 'npm:lint:*(!fix)' --names 'lint:'",
@@ -43,7 +52,6 @@
4352
"dependencies": {
4453
"@embroider/addon-shim": "^1.8.6",
4554
"@embroider/macros": "^1.13.1",
46-
"ember-cli-test-loader": "^3.1.0",
4755
"qunit-theme-ember": "^1.0.0"
4856
},
4957
"devDependencies": {

addon/src/index.js

-13
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ if (macroCondition(getOwnConfig()?.theme === 'ember')) {
2323
}
2424

2525
export { default as QUnitAdapter, nonTestDoneCallback } from './adapter';
26-
export { loadTests } from './test-loader';
2726

2827
import './qunit-configuration';
2928

@@ -33,7 +32,6 @@ if (typeof Testem !== 'undefined') {
3332

3433
import { _backburner } from '@ember/runloop';
3534
import { resetOnerror, getTestMetadata } from '@ember/test-helpers';
36-
import { loadTests } from './test-loader';
3735
import Ember from 'ember';
3836
import * as QUnit from 'qunit';
3937
import QUnitAdapter from './adapter';
@@ -180,7 +178,6 @@ export function setupTestIsolationValidation(delay) {
180178
/**
181179
@method start
182180
@param {Object} [options] Options to be used for enabling/disabling behaviors
183-
@param {Boolean} [options.loadTests] If `false` tests will not be loaded automatically.
184181
@param {Boolean} [options.setupTestContainer] If `false` the test container will not
185182
be setup based on `devmode`, `dockcontainer`, or `nocontainer` URL params.
186183
@param {Boolean} [options.startTests] If `false` tests will not be automatically started
@@ -190,8 +187,6 @@ export function setupTestIsolationValidation(delay) {
190187
@param {Boolean} [options.setupEmberTesting] `false` opts out of the
191188
default behavior of setting `Ember.testing` to `true` before all tests and
192189
back to `false` after each test will.
193-
@param {Boolean} [options.setupEmberOnerrorValidation] If `false` validation
194-
of `Ember.onerror` will be disabled.
195190
@param {Boolean} [options.setupTestIsolationValidation] If `false` test isolation validation
196191
will be disabled.
197192
@param {Number} [options.testIsolationValidationDelay] When using
@@ -200,10 +195,6 @@ export function setupTestIsolationValidation(delay) {
200195
async to have been completed. The default value is 50.
201196
*/
202197
export function start(options = {}) {
203-
if (options.loadTests !== false) {
204-
loadTests();
205-
}
206-
207198
if (options.setupTestContainer !== false) {
208199
setupTestContainer();
209200
}
@@ -216,10 +207,6 @@ export function start(options = {}) {
216207
setupEmberTesting();
217208
}
218209

219-
if (options.setupEmberOnerrorValidation !== false) {
220-
setupEmberOnerrorValidation();
221-
}
222-
223210
if (
224211
typeof options.setupTestIsolationValidation !== 'undefined' &&
225212
options.setupTestIsolationValidation !== false

addon/src/test-loader.js

+76-17
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,81 @@
1+
/* globals requirejs, require */
2+
13
import * as QUnit from 'qunit';
2-
import AbstractTestLoader, {
3-
addModuleIncludeMatcher,
4-
} from 'ember-cli-test-loader/test-support/index';
54

6-
addModuleIncludeMatcher(function (moduleName) {
7-
return moduleName.match(/\.jshint$/);
8-
});
5+
class TestLoader {
6+
static load() {
7+
new TestLoader().loadModules();
8+
}
9+
10+
constructor() {
11+
this._didLogMissingUnsee = false;
12+
}
13+
14+
shouldLoadModule(moduleName) {
15+
return moduleName.match(/[-_]test$/);
16+
}
17+
18+
listModules() {
19+
return Object.keys(requirejs.entries);
20+
}
21+
22+
listTestModules() {
23+
let moduleNames = this.listModules();
24+
let testModules = [];
25+
let moduleName;
26+
27+
for (let i = 0; i < moduleNames.length; i++) {
28+
moduleName = moduleNames[i];
29+
30+
if (this.shouldLoadModule(moduleName)) {
31+
testModules.push(moduleName);
32+
}
33+
}
34+
35+
return testModules;
36+
}
37+
38+
loadModules() {
39+
let testModules = this.listTestModules();
40+
let testModule;
41+
42+
for (let i = 0; i < testModules.length; i++) {
43+
testModule = testModules[i];
44+
this.require(testModule);
45+
this.unsee(testModule);
46+
}
47+
}
48+
49+
require(moduleName) {
50+
try {
51+
require(moduleName);
52+
} catch (e) {
53+
this.moduleLoadFailure(moduleName, e);
54+
}
55+
}
56+
57+
unsee(moduleName) {
58+
if (typeof require.unsee === 'function') {
59+
require.unsee(moduleName);
60+
} else if (!this._didLogMissingUnsee) {
61+
this._didLogMissingUnsee = true;
62+
if (typeof console !== 'undefined') {
63+
console.warn(
64+
'unable to require.unsee, please upgrade loader.js to >= v3.3.0'
65+
);
66+
}
67+
}
68+
}
69+
70+
moduleLoadFailure(moduleName, error) {
71+
moduleLoadFailures.push(error);
72+
73+
QUnit.module('TestLoader Failures');
74+
QUnit.test(moduleName + ': could not be loaded', function () {
75+
throw error;
76+
});
77+
}
78+
}
979

1080
let moduleLoadFailures = [];
1181

@@ -26,17 +96,6 @@ QUnit.done(function () {
2696
}
2797
});
2898

29-
export class TestLoader extends AbstractTestLoader {
30-
moduleLoadFailure(moduleName, error) {
31-
moduleLoadFailures.push(error);
32-
33-
QUnit.module('TestLoader Failures');
34-
QUnit.test(moduleName + ': could not be loaded', function () {
35-
throw error;
36-
});
37-
}
38-
}
39-
4099
/**
41100
Load tests following the default patterns:
42101

addon/types/index.d.ts

+7-15
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,6 @@ export class QUnitAdapter extends EmberTestAdapter {}
8888
export { module, test, skip, only, todo } from 'qunit';
8989

9090
interface QUnitStartOptions {
91-
/**
92-
* If `false` tests will not be loaded automatically.
93-
*/
94-
loadTests?: boolean | undefined;
95-
9691
/**
9792
* If `false` the test container will not be setup based on `devmode`,
9893
* `dockcontainer`, or `nocontainer` URL params.
@@ -116,17 +111,14 @@ interface QUnitStartOptions {
116111
*/
117112
setupEmberTesting?: boolean | undefined;
118113

119-
/**
120-
* If `false` validation of `Ember.onerror` will be disabled.
121-
*/
122-
setupEmberOnerrorValidation?: boolean | undefined;
123-
124114
/**
125115
* If `false` test isolation validation will be disabled.
126116
*/
127117
setupTestIsolationValidation?: boolean | undefined;
128118
}
129119

120+
export function setupEmberOnerrorValidation(): void;
121+
130122
export function start(options?: QUnitStartOptions): void;
131123

132124
// SAFETY: all of the `TC extends TestContext` generics below are just wildly,
@@ -281,10 +273,10 @@ declare global {
281273

282274
interface EachFunction {
283275
<TC extends TestContext, T>(
284-
name: string,
285-
dataset: T[],
286-
callback: (this: TC, assert: Assert, data: T) => void | Promise<unknown>
287-
): void;
288-
}
276+
name: string,
277+
dataset: T[],
278+
callback: (this: TC, assert: Assert, data: T) => void | Promise<unknown>
279+
): void;
280+
}
289281
}
290282
}

addon/types/test-loader.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export function loadTests(): void;

pnpm-lock.yaml

-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test-app/tests/test-helper.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ import config from 'test-app/config/environment';
33
import * as QUnit from 'qunit';
44
import { setApplication } from '@ember/test-helpers';
55
import { setup } from 'qunit-dom';
6-
import { start } from 'ember-qunit';
6+
import { loadTests } from 'ember-qunit/test-loader';
7+
import { start, setupEmberOnerrorValidation } from 'ember-qunit';
78

89
setApplication(Application.create(config.APP));
910

1011
setup(QUnit.assert);
1112

13+
setupEmberOnerrorValidation();
14+
loadTests();
1215
start();

test-app/types/index.d.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ export class QUnitAdapter extends EmberTestAdapter {}
8787

8888
export { module, test, skip, only, todo } from 'qunit';
8989

90+
export function setupEmberOnerrorValidation(): void;
91+
9092
interface QUnitStartOptions {
9193
/**
9294
* If `false` tests will not be loaded automatically.
@@ -116,11 +118,6 @@ interface QUnitStartOptions {
116118
*/
117119
setupEmberTesting?: boolean | undefined;
118120

119-
/**
120-
* If `false` validation of `Ember.onerror` will be disabled.
121-
*/
122-
setupEmberOnerrorValidation?: boolean | undefined;
123-
124121
/**
125122
* If `false` test isolation validation will be disabled.
126123
*/

0 commit comments

Comments
 (0)