Don't ignore tests/ directory if meteor.testModule defined.

According to traditional Meteor file loading rules, tests/ directories are
completely ignored: https://guide.meteor.com/structure.html#special-directories

However, if you specify a meteor.testModule in your package.json that
refers to a file inside a tests/ directory, Meteor should permit modules
to be loaded from tests/, as well as any modules that are imported by the
meteor.testModule entry point.

Fixes #9991.
This commit is contained in:
Ben Newman
2018-06-13 17:56:04 -04:00
parent 1c4536072a
commit ea394be6e8

View File

@@ -889,6 +889,7 @@ _.extend(PackageSource.prototype, {
sourceArch: this,
ignoreFiles,
isApp: true,
testModule,
};
// If this architecture has a mainModule defined in
@@ -1025,8 +1026,9 @@ _.extend(PackageSource.prototype, {
return fileOptions;
}
// Files in `imports/` should be lazily loaded *apart* from tests
if (dir === "imports" && ! isTestFile) {
// Files in `imports/` and `tests/` directories should be lazily
// loaded *apart* from tests.
if ((dir === "imports" || dir === "tests") && ! isTestFile) {
fileOptions.lazy = true;
}
@@ -1080,6 +1082,7 @@ _.extend(PackageSource.prototype, {
watchSet,
isApp,
sourceArch,
testModule,
loopChecker = new SymlinkLoopChecker(this.sourceRoot),
ignoreFiles = []
}) {
@@ -1102,10 +1105,10 @@ _.extend(PackageSource.prototype, {
// Unless we're running tests, ignore all test filenames and if we are, ignore the
// type of file we *aren't* running
if (!global.testCommandMetadata || global.testCommandMetadata.isTest) {
Array.prototype.push.apply(sourceReadOptions.exclude, APP_TEST_FILENAME_REGEXPS);
sourceReadOptions.exclude.push(...APP_TEST_FILENAME_REGEXPS);
}
if (!global.testCommandMetadata || global.testCommandMetadata.isAppTest) {
Array.prototype.push.apply(sourceReadOptions.exclude, TEST_FILENAME_REGEXPS);
sourceReadOptions.exclude.push(...TEST_FILENAME_REGEXPS);
}
// Read top-level source files, excluding control files that were not
@@ -1116,13 +1119,21 @@ _.extend(PackageSource.prototype, {
controlFiles.push('package.js');
}
const anyLevelExcludes = [
/^tests\/$/,
const anyLevelExcludes = [];
// If we have a meteor.testModule from package.json, then we don't
// need to exclude tests/ directories from the search, because we
// trust meteor.testModule to identify a single test entry point.
if (! testModule) {
anyLevelExcludes.push(/^tests\/$/);
}
anyLevelExcludes.push(
archinfo.matches(arch, "os")
? /^client\/$/
: /^server\/$/,
...sourceReadOptions.exclude,
];
);
const topLevelExcludes = isApp ? [
...anyLevelExcludes,