Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop excluding test modules when meteor.testModule found in package.json. #10402

Merged
merged 1 commit into from Jan 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions History.md
Expand Up @@ -8,6 +8,12 @@ N/A

### Changes

- Fixed a bug where modules named with `*.app-tests.js` (or `*.tests.js`)
file extensions sometimes could not be imported by the
`meteor.testModule` entry point when running the `meteor test` command
(or `meteor test --full-app`).
[PR #10402](https://github.com/meteor/meteor/pull/10402)

## v1.8.0.1, 2018-11-23

### Breaking changes
Expand Down
57 changes: 43 additions & 14 deletions tools/isobuild/package-source.js
Expand Up @@ -22,7 +22,8 @@ import { PackageAPI } from "./package-api.js";
import {
TEST_FILENAME_REGEXPS,
APP_TEST_FILENAME_REGEXPS,
isTestFilePath } from './test-files.js';
isTestFilePath,
} from './test-files.js';

import {
convert as convertColonsInPath
Expand Down Expand Up @@ -1102,15 +1103,6 @@ _.extend(PackageSource.prototype, {
// Ignore the usual ignorable files.
sourceReadOptions.exclude.push(...ignoreFiles);

// 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) {
sourceReadOptions.exclude.push(...APP_TEST_FILENAME_REGEXPS);
}
if (!global.testCommandMetadata || global.testCommandMetadata.isAppTest) {
sourceReadOptions.exclude.push(...TEST_FILENAME_REGEXPS);
}

// Read top-level source files, excluding control files that were not
// explicitly included.
const controlFiles = ['mobile-config.js'];
Expand All @@ -1121,11 +1113,48 @@ _.extend(PackageSource.prototype, {

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) {
if (testModule) {
// If we have a meteor.testModule from package.json, then we don't
// need to exclude tests/ directories or *.tests.js files from the
// search, because we trust meteor.testModule to identify a single
// test entry point.
} else {
anyLevelExcludes.push(/^tests\/$/);

const {
isTest = false,
isAppTest = false,
} = global.testCommandMetadata || {};

if (isTest || isAppTest) {
// If we're running `meteor test` without the --full-app option,
// ignore app-test-only files like *.app-tests.js.
if (! isAppTest) {
sourceReadOptions.exclude.push(
...APP_TEST_FILENAME_REGEXPS,
);
}

// If we're running `meteor test` with the --full-app option,
// ignore non-app-test files like *.tests.js. The wisdom of this
// behavior is debatable, since you might want to run non-app
// tests even when you're using the --full-app option, but it's
// legacy behavior at this point, and it doesn't matter if you're
// using meteor.testModule anyway (recommended).
if (! isTest) {
sourceReadOptions.exclude.push(
...TEST_FILENAME_REGEXPS,
);
}

} else {
// If we're not running `meteor test` (and meteor.testModule is
// not defined in package.json), ignore all test files.
sourceReadOptions.exclude.push(
...APP_TEST_FILENAME_REGEXPS,
...TEST_FILENAME_REGEXPS,
);
}
}

anyLevelExcludes.push(
Expand Down
9 changes: 9 additions & 0 deletions tools/tests/apps/modules/imports/imported.tests.js
@@ -0,0 +1,9 @@
import assert from "assert";

export const name = module.id.split("/").pop();

describe(name, () => {
it("should be imported", () => {
assert.strictEqual(name, "imported.tests.js");
});
});
7 changes: 7 additions & 0 deletions tools/tests/apps/modules/tests.js
Expand Up @@ -653,3 +653,10 @@ describe("circular package.json resolution chains", () => {
);
});
});

describe("imported *.tests.js modules", () => {
const { name } = require("./imports/imported.tests.js");
it("should be properly compiled", () => {
assert.strictEqual(name, "imported.tests.js");
});
});
14 changes: 7 additions & 7 deletions tools/tests/test-modes.js
Expand Up @@ -17,17 +17,17 @@ selftest.define("'meteor test --port' accepts/rejects proper values", function (
runAddPackage.expectExit(0);

run = s.run("test", "--port", "3700", "--driver-package", "tmeasday:acceptance-test-driver");
run.waitSecs(120);
run.waitSecs(30);
run.match('App running at: http://localhost:3700/');
run.stop();

run = s.run("test", "--port", "127.0.0.1:3700", "--driver-package", "tmeasday:acceptance-test-driver");
run.waitSecs(120);
run.waitSecs(30);
run.match('App running at: http://127.0.0.1:3700/');
run.stop();

run = s.run("test", "--port", "[::]:3700", "--driver-package", "tmeasday:acceptance-test-driver");
run.waitSecs(120);
run.waitSecs(30);
run.match('App running at: http://[::]:3700/');
run.stop();
});
Expand Down Expand Up @@ -80,15 +80,15 @@ selftest.define("'meteor test' eagerly loads correct files", () => {

// `meteor` should load app files, but not test files or app-test files
run = s.run();
run.waitSecs(120);
run.waitSecs(30);
run.match('index.js');
run.stop();
run.forbid('foo.test.js');
run.forbid('foo.app-test.js');

// `meteor test` should load test files, but not app files or app-test files
run = s.run('test', '--driver-package', 'tmeasday:acceptance-test-driver');
run.waitSecs(120);
run.waitSecs(30);
run.match('foo.test.js');
run.stop();
run.forbid('index.js');
Expand All @@ -102,9 +102,9 @@ selftest.define("'meteor test' eagerly loads correct files", () => {
'tmeasday:acceptance-test-driver',
'--full-app',
);
run.waitSecs(120);
run.waitSecs(30);
run.match('foo.app-test.js');
run.match('index.js');
run.stop();
run.forbid('foo.test.js');
})
});