browser-extension-manager 1.7.1 → 1.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/test/runner.js
CHANGED
|
@@ -402,6 +402,11 @@ function filterBySource(source, files, sourceFilter, pathPart) {
|
|
|
402
402
|
});
|
|
403
403
|
}
|
|
404
404
|
|
|
405
|
+
// Glob ignore patterns implementing the "underscore = not a suite" convention:
|
|
406
|
+
// `_`-prefixed FILES (e.g. test/_init.js) and everything under a `_`-prefixed
|
|
407
|
+
// DIRECTORY at any depth (helpers, fixtures — e.g. test/_helpers/harness.js).
|
|
408
|
+
const DISCOVERY_IGNORE = ['**/_*.js', '**/_*/**'];
|
|
409
|
+
|
|
405
410
|
function discoverTestFiles(target) {
|
|
406
411
|
const { source: sourceFilter, pathPart } = parseTarget(target);
|
|
407
412
|
const framework = [];
|
|
@@ -425,7 +430,7 @@ function discoverTestFiles(target) {
|
|
|
425
430
|
// Consumers write their own boot tests under <cwd>/test/boot/.
|
|
426
431
|
const frameworkSuitesDir = path.join(__dirname, 'suites');
|
|
427
432
|
if (jetpack.exists(frameworkSuitesDir)) {
|
|
428
|
-
const ignore = [
|
|
433
|
+
const ignore = [...DISCOVERY_IGNORE];
|
|
429
434
|
if (!isFrameworkSelfTest) ignore.push('boot/**');
|
|
430
435
|
glob('**/*.js', { cwd: frameworkSuitesDir, ignore }).sort().forEach((rel) => {
|
|
431
436
|
framework.push(path.join(frameworkSuitesDir, rel));
|
|
@@ -434,9 +439,10 @@ function discoverTestFiles(target) {
|
|
|
434
439
|
|
|
435
440
|
// Consumer project suites — CWD/test/**/*.js. Skip when running from inside the
|
|
436
441
|
// framework's own dist tree (where consumer-tests-dir === framework-tests-parent).
|
|
442
|
+
// Excludes `_`-prefixed files and directories (see DISCOVERY_IGNORE).
|
|
437
443
|
const projectTestsDir = path.join(process.cwd(), 'test');
|
|
438
444
|
if (jetpack.exists(projectTestsDir) && projectTestsDir !== path.dirname(frameworkSuitesDir)) {
|
|
439
|
-
glob('**/*.js', { cwd: projectTestsDir, ignore: [
|
|
445
|
+
glob('**/*.js', { cwd: projectTestsDir, ignore: [...DISCOVERY_IGNORE] }).sort().forEach((rel) => {
|
|
440
446
|
project.push(path.join(projectTestsDir, rel));
|
|
441
447
|
});
|
|
442
448
|
}
|
|
@@ -512,4 +518,4 @@ async function runInitSetups() {
|
|
|
512
518
|
}
|
|
513
519
|
}
|
|
514
520
|
|
|
515
|
-
module.exports = { run, SkipError };
|
|
521
|
+
module.exports = { run, SkipError, DISCOVERY_IGNORE };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Build-layer tests for test-suite discovery — specifically the
|
|
2
|
+
// "underscore = not a suite" convention: `_`-prefixed files and everything
|
|
3
|
+
// under `_`-prefixed directories (at ANY depth) must be excluded, so consumers
|
|
4
|
+
// can keep helpers and fixture trees (e.g. test/_helpers/harness.js)
|
|
5
|
+
// next to their suites.
|
|
6
|
+
|
|
7
|
+
const path = require('path');
|
|
8
|
+
|
|
9
|
+
module.exports = {
|
|
10
|
+
type: 'suite',
|
|
11
|
+
layer: 'build',
|
|
12
|
+
description: 'test discovery — underscore exclusion convention',
|
|
13
|
+
tests: [
|
|
14
|
+
{
|
|
15
|
+
name: 'runner exports DISCOVERY_IGNORE',
|
|
16
|
+
run: (ctx) => {
|
|
17
|
+
const runner = require(path.join(__dirname, '..', '..', 'runner.js'));
|
|
18
|
+
ctx.expect(Array.isArray(runner.DISCOVERY_IGNORE)).toBe(true);
|
|
19
|
+
ctx.expect(runner.DISCOVERY_IGNORE.length >= 2).toBe(true);
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: 'glob with DISCOVERY_IGNORE skips _ files and _ dirs at any depth',
|
|
24
|
+
run: (ctx) => {
|
|
25
|
+
const fs = require('fs');
|
|
26
|
+
const os = require('os');
|
|
27
|
+
const glob = require('glob').globSync;
|
|
28
|
+
const { DISCOVERY_IGNORE } = require(path.join(__dirname, '..', '..', 'runner.js'));
|
|
29
|
+
|
|
30
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'bxm-discovery-test-'));
|
|
31
|
+
const write = (rel) => {
|
|
32
|
+
const file = path.join(tmp, rel);
|
|
33
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
34
|
+
fs.writeFileSync(file, 'module.exports = {};\n');
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// Should be DISCOVERED:
|
|
38
|
+
write('build/config.test.js');
|
|
39
|
+
write('page/runner.test.js');
|
|
40
|
+
write('boot/nested/deep.test.js');
|
|
41
|
+
|
|
42
|
+
// Should be EXCLUDED:
|
|
43
|
+
write('_init.js'); // top-level _ file
|
|
44
|
+
write('page/_helper.js'); // nested _ file
|
|
45
|
+
write('_helpers/harness.js'); // file in top-level _ dir
|
|
46
|
+
write('_fixtures/packages/runner/mod/index.js'); // deep inside a _ dir
|
|
47
|
+
write('boot/_private/util.js'); // _ dir below a layer dir
|
|
48
|
+
|
|
49
|
+
const found = glob('**/*.js', { cwd: tmp, ignore: [...DISCOVERY_IGNORE] }).sort();
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
ctx.expect(found).toEqual([
|
|
53
|
+
'boot/nested/deep.test.js',
|
|
54
|
+
'build/config.test.js',
|
|
55
|
+
'page/runner.test.js',
|
|
56
|
+
]);
|
|
57
|
+
} finally {
|
|
58
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
};
|
package/docs/test-framework.md
CHANGED
|
@@ -157,7 +157,7 @@ Consumers writing their own tests get this automatically when running through `n
|
|
|
157
157
|
- **Framework defaults**: `<BXM>/dist/test/suites/**/*.js`
|
|
158
158
|
- **Consumer suites**: `<cwd>/test/**/*.js`
|
|
159
159
|
|
|
160
|
-
**The underscore convention
|
|
160
|
+
**The underscore convention** (`DISCOVERY_IGNORE` in `src/test/runner.js`): `_`-prefixed FILES (`test/_init.js`, `test/page/_helper.js`) and everything under a `_`-prefixed DIRECTORY at **any depth** (`test/_fixtures/**`, `test/boot/_private/**`) are excluded from suite discovery. Put shared helpers, fixture data, and non-test support files in `_`-prefixed paths — e.g. `test/_fixtures/`, `test/_helpers/`. The runner still specifically loads `test/_init.js` as the lifecycle hook. Matches the same convention in BEM/EM/UJM. Files load alphabetically.
|
|
161
161
|
|
|
162
162
|
**Framework's boot suites are scoped to BXM self-test runs only.** When a consumer runs `npx bxm test`, the framework's `dist/test/suites/boot/**` is excluded from discovery (those tests assert on BXM's internal fixture extension). Consumers write their own boot tests under `<cwd>/test/boot/`. See [test-boot-layer.md](test-boot-layer.md).
|
|
163
163
|
|