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

[feature] Added a CLI flag to allow passing without any test files found #2758

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/fair-melons-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@web/test-runner-core': minor
'@web/test-runner': minor
---

Added a command line flag to allow the command to pass when no tests are present.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ coverage/
npm-debug.log
yarn-error.log

## environment
.env*

## temp folders
/.tmp/

Expand Down
4 changes: 4 additions & 0 deletions docs/docs/test-runner/cli-and-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ interface TestRunnerGroupConfig {
name: string;
// globs of files to test in this group, if unset it will be inherited from the main config
files?: string | string[];
// allow tests to pass even if there are no test files found
allowPassWithoutTests?: boolean;
// browsers to test in this group, if unset it will be inherited from the main config
browsers?: BrowserLauncher[];
// HTML used for running HTML tests for this group
Expand All @@ -127,6 +129,8 @@ interface TestRunnerGroupConfig {
interface TestRunnerConfig {
// globs of files to test
files: string | string[];
// allow tests to pass even if there are no test files found
allowPassWithoutTests?: boolean;
// test group configs, can be an array of configs or a string or string array of glob patterns
// which specify where to find the configs
groups?: string | string[] | TestRunnerGroupConfig[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface CoverageConfig {
export interface TestRunnerCoreConfig {
rootDir: string;
files?: string | string[];
allowPassWithoutTests?: boolean;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

related to another question: I'd just make it allowPassWithoutTests: boolean and default to "false", here and below

concurrentBrowsers: number;
concurrency: number;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface TestRunnerGroupConfig {
name: string;
configFilePath?: string;
files?: string | string[];
allowPassWithoutTests?: boolean;
browsers?: BrowserLauncher[];
testRunnerHtml?: (
testRunnerImport: string,
Expand Down
1 change: 1 addition & 0 deletions packages/test-runner-core/src/runner/TestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export class TestRunner extends EventEmitter<EventMap> {
this.pendingSessions.clear();

if (sessionsToRun.length === 0) {
this.stop();
return;
}

Expand Down
9 changes: 7 additions & 2 deletions packages/test-runner-core/src/runner/createSessionGroups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export function createTestSessions(
groups.push({
name: 'default',
files: config.files,
allowPassWithoutTests: config.allowPassWithoutTests,
browsers: config.browsers,
});
}
Expand All @@ -52,6 +53,10 @@ export function createTestSessions(
mergedGroupConfig.files = groupConfig.files;
}

if (groupConfig.allowPassWithoutTests != null) {
mergedGroupConfig.allowPassWithoutTests = groupConfig.allowPassWithoutTests;
}

if (groupConfig.testRunnerHtml != null) {
mergedGroupConfig.testRunnerHtml = groupConfig.testRunnerHtml;
}
Expand All @@ -71,7 +76,7 @@ export function createTestSessions(
// C:/foo/bar -> C:\foo\bar
.map(testFile => path.normalize(testFile));

if (testFilesForGroup.length === 0) {
if (testFilesForGroup.length === 0 && !group.allowPassWithoutTests) {
throw new Error(`Could not find any test files with pattern(s): ${group.files}`);
}

Expand Down Expand Up @@ -112,7 +117,7 @@ export function createTestSessions(
}
}

if (testFiles.size === 0 || testSessions.length === 0) {
if ((testFiles.size === 0 || testSessions.length === 0) && !config.allowPassWithoutTests) {
throw new Error('Did not find any tests to run.');
}

Expand Down
2 changes: 2 additions & 0 deletions packages/test-runner/src/config/parseConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,10 @@ export async function parseConfig(
// we can improve this by relying only on groups inside the test runner itself
if (groupConfig.files == null) {
groupConfig.files = finalConfig.files;
groupConfig.allowPassWithoutTests = finalConfig.allowPassWithoutTests;
}
finalConfig.files = undefined;
finalConfig.allowPassWithoutTests = undefined;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the reason to set it as undefined? isn't it more clear to have it always as a boolean and default to false?


groupConfigs = [groupConfig];
}
Expand Down
6 changes: 6 additions & 0 deletions packages/test-runner/src/config/readCliArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface TestRunnerCliArgs
Pick<
TestRunnerConfig,
| 'files'
| 'allowPassWithoutTests'
| 'rootDir'
| 'watch'
| 'coverage'
Expand Down Expand Up @@ -41,6 +42,11 @@ const options: OptionDefinition[] = [
defaultOption: true,
description: 'Test files to run',
},
{
name: 'allowPassWithoutTests',
type: Boolean,
description: 'Allow pass without any tests',
},
{
name: 'root-dir',
type: String,
Expand Down
Loading