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

Feat/manual flag #671

Merged
merged 2 commits into from
Oct 2, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/khaki-carpets-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@web/test-runner': patch
'@web/test-runner-core': patch
---

improve error message when no browsers are configured
7 changes: 7 additions & 0 deletions .changeset/orange-carpets-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@web/test-runner-cli': patch
'@web/test-runner-core': patch
'@web/test-runner': patch
---

added manual testing and open browser options
5 changes: 5 additions & 0 deletions docs/docs/test-runner/cli-and-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ interface TestRunnerConfig {
// configuration for code coverage
coverageConfig?: CoverageConfig;

/** Starts test runner in manual testing mode. Ignores browsers option and prints manual testing URL. */
manual?: boolean;
/** Opens browser for manual testing. Requires the manual option to be set. */
open?: boolean;

// how long a browser can take to start up before failing. defaults to 30000
browserStartTimeout?: number;
// how long a test file can take to load. defaults to 10000
Expand Down
28 changes: 19 additions & 9 deletions packages/test-runner-cli/src/cli/TestRunnerCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ import { TestRunnerLogger } from '../logger/TestRunnerLogger';
import { BufferedLogger } from '../reporter/BufferedLogger';
import { getManualDebugMenu } from './getManualDebugMenu';

export type MenuType = 'overview' | 'focus' | 'debug' | 'manual-debug';
export type MenuType = 'none' | 'overview' | 'focus' | 'debug' | 'manual-debug';

export const MENUS = {
NONE: 'none' as MenuType,
OVERVIEW: 'overview' as MenuType,
FOCUS_SELECT_FILE: 'focus' as MenuType,
DEBUG_SELECT_FILE: 'debug' as MenuType,
Expand All @@ -41,7 +42,7 @@ export class TestRunnerCli {
private terminal = new DynamicTerminal();
private reportedFilesByTestRun = new Map<number, Set<string>>();
private sessions: TestSessionManager;
private activeMenu: MenuType = MENUS.OVERVIEW;
private activeMenu: MenuType = MENUS.NONE;
private menuSucceededAndPendingFiles: string[] = [];
private menuFailedFiles: string[] = [];
private testCoverage?: TestCoverage;
Expand All @@ -67,9 +68,6 @@ export class TestRunnerCli {
this.setupRunnerEvents();

this.terminal.start();
if (this.config.watch) {
this.terminal.clear();
}

for (const reporter of this.config.reporters) {
reporter.start?.({
Expand All @@ -81,16 +79,19 @@ export class TestRunnerCli {
});
}

this.reportTestResults();
this.reportTestProgress();
this.switchMenu(this.config.manual ? MENUS.MANUAL_DEBUG : MENUS.OVERVIEW);

if (this.config.watch) {
if (this.config.watch || (this.config.manual && this.terminal.isInteractive)) {
this.terminal.observeDirectInput();
}

if (this.config.staticLogging || !this.terminal.isInteractive) {
this.logger.log(chalk.bold(`Running ${this.runner.testFiles.length} test files...\n`));
}

if (this.config.open) {
openBrowser(this.localAddress);
}
}

private setupTerminalEvents() {
Expand All @@ -107,7 +108,12 @@ export class TestRunnerCli {
case KEYCODES.CTRL_C:
case KEYCODES.CTRL_D:
case 'Q':
this.runner.stop();
if (
this.activeMenu === MENUS.OVERVIEW ||
(this.config.manual && this.activeMenu === MENUS.MANUAL_DEBUG)
) {
this.runner.stop();
}
return;
case 'D':
if (this.activeMenu === MENUS.OVERVIEW) {
Expand Down Expand Up @@ -297,6 +303,10 @@ export class TestRunnerCli {
}

private reportTestProgress(final = false) {
if (this.config.manual) {
return;
}

const logStatic = this.config.staticLogging || !this.terminal.isInteractive;
if (logStatic && !final) {
// print a static progress log only once every 10000ms
Expand Down
2 changes: 1 addition & 1 deletion packages/test-runner-cli/src/cli/getManualDebugMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ export function getManualDebugMenu(config: TestRunnerCoreConfig): string[] {
`Network address: ${chalk.cyanBright(networkAddress)}`,
' ',
`${chalk.gray('Press')} D ${chalk.gray('to open the browser.')}`,
`${chalk.gray('Press')} ESC ${chalk.gray('to exit manual debug.')}`,
`${chalk.gray('Press')} ${config.manual ? 'Q' : 'ESC'} ${chalk.gray('to exit manual debug.')}`,
].filter(_ => !!_);
}
11 changes: 11 additions & 0 deletions packages/test-runner-cli/src/config/readCliArgsConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ const defaultOptions: OptionDefinition[] = [
type: Boolean,
description: 'Disables rendering a progress bar dynamically to the terminal.',
},
{
name: 'manual',
type: Boolean,
description:
'Starts test runner in manual testing mode. Ignores browsers option and prints manual testing URL.',
},
{
name: 'open',
type: Boolean,
description: 'Opens browser for manual testing. Requires the manual option to be set.',
},
{
name: 'port',
type: Number,
Expand Down
5 changes: 5 additions & 0 deletions packages/test-runner-core/src/config/TestRunnerCoreConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ export interface TestRunnerCoreConfig {
testsFinishTimeout: number;
staticLogging?: boolean;

/** Ignores browsers option and prints manual testing URL. */
manual?: boolean;
/** Opens browser for manual testing. Requires the manual option to be set. */
open?: boolean;

debug?: boolean;
mimeTypes?: Record<string, string>;
plugins?: TestRunnerPlugin[];
Expand Down
33 changes: 24 additions & 9 deletions packages/test-runner-core/src/runner/TestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,24 @@ export class TestRunner extends EventEmitter<EventMap> {

constructor(config: TestRunnerCoreConfig, groupConfigs: TestRunnerGroupConfig[] = []) {
super();
if (!config.manual && (!config.browsers || config.browsers.length === 0)) {
throw new Error('No browsers are configured to run tests');
}

if (config.manual && config.watch) {
throw new Error('Cannot combine the manual and watch options.');
}

if (config.open && !config.manual) {
throw new Error('The open option requires the manual option to be set.');
}

const { sessionGroups, testFiles, testSessions, browsers } = createTestSessions(
config,
groupConfigs,
);
this.config = config;

this.testFiles = testFiles;
this.browsers = browsers;
this.browserNames = Array.from(new Set(this.browsers.map(b => b.name)));
Expand Down Expand Up @@ -73,17 +86,19 @@ export class TestRunner extends EventEmitter<EventMap> {
this.started = true;
this.startTime = Date.now();

for (const browser of this.browsers) {
if (browser.initialize) {
await browser.initialize(this.config, this.testFiles);
}
}
// the browser names can be updated after initialize
this.browserNames = Array.from(new Set(this.browsers.map(b => b.name)));

await this.server.start();

this.runTests(this.sessions.all());
if (!this.config.manual) {
for (const browser of this.browsers) {
if (browser.initialize) {
await browser.initialize(this.config, this.testFiles);
}
}

// the browser names can be updated after initialize
this.browserNames = Array.from(new Set(this.browsers.map(b => b.name)));
this.runTests(this.sessions.all());
}
} catch (error) {
this.stop(error);
}
Expand Down
1 change: 1 addition & 0 deletions packages/test-runner/web-test-runner.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export default {
rootDir: '../../',
preserveSymlinks: true,
nodeResolve: true,
browsers: [],
};