Skip to content
Open
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: 0 additions & 6 deletions packages/test-runner-core/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,6 @@ A test session is a combination of a combination of a browser and a testfile. Fo

The `TestSession` data structure represents these individual combinations, and contains information about the status and test results. The status property is updated over time as the test session executed. It's implemented as a regular javascript object, and should be treated as immutable.

### TestSessionGroup

A test group is a way to group together related tests which share the same configuration options. A user can do this from the config, using the `groups` entry. For example to execute a group of tests only on a certain browser, or to execute tests in a different HTML environment.

A default group is always created as well, this contains all the default options from the top level config.

### TestScheduler

The scheduler is created by the test runner, and is not exposed as a public property. It manages the actual execution of a test session, and communicates with the browser launcher.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { TestRunnerCoreConfig } from './TestRunnerCoreConfig.js';

export interface TestRunnerGroupConfig {
name: string;
configFilePath?: string;
files?: string | string[];
browsers?: BrowserLauncher[];
testRunnerHtml?: (
Expand Down
7 changes: 2 additions & 5 deletions packages/test-runner-core/src/runner/TestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ export class TestRunner extends EventEmitter<EventMap> {
throw new Error('The open option requires the manual option to be set.');
}

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

this.testFiles = testFiles;
Expand All @@ -65,7 +62,7 @@ export class TestRunner extends EventEmitter<EventMap> {
this.browsers.findIndex(br => br.name === a) - this.browsers.findIndex(br => br.name === b),
);

this.sessions = new TestSessionManager(sessionGroups, testSessions);
this.sessions = new TestSessionManager(testSessions);
this.scheduler = new TestScheduler(config, this.sessions, browsers);
this.server = new TestRunnerServer(
this.config,
Expand Down
33 changes: 7 additions & 26 deletions packages/test-runner-core/src/runner/createSessionGroups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import { TestRunnerCoreConfig } from '../config/TestRunnerCoreConfig.js';
import { TestRunnerGroupConfig } from '../config/TestRunnerGroupConfig.js';
import { BrowserLauncher } from '../browser-launcher/BrowserLauncher.js';
import { collectTestFiles } from './collectTestFiles.js';
import { TestSessionGroup } from '../test-session/TestSessionGroup.js';

interface GroupConfigWithoutOptionals extends TestRunnerGroupConfig {
name: string;
configFilePath?: string;
files: string | string[];
browsers: BrowserLauncher[];
}
Expand All @@ -34,7 +32,6 @@ export function createTestSessions(
// merge group with config defaults
const mergedGroupConfig: GroupConfigWithoutOptionals = {
name: groupConfig.name,
configFilePath: groupConfig.configFilePath,
testRunnerHtml: config.testRunnerHtml,
browsers: config.browsers,
files: config.files ?? [],
Expand All @@ -59,14 +56,12 @@ export function createTestSessions(
groups.push(mergedGroupConfig);
}

const sessionGroups: TestSessionGroup[] = [];
const testSessions: TestSession[] = [];
const testFiles = new Set<string>();
const browsers = new Set<BrowserLauncher>();

for (const group of groups) {
const baseDir = group.configFilePath ? path.dirname(group.configFilePath) : process.cwd();
const testFilesForGroup = collectTestFiles(group.files, baseDir)
const testFilesForGroup = collectTestFiles(group.files)
// Normalize file path because glob returns windows paths with forward slashes:
// C:/foo/bar -> C:\foo\bar
.map(testFile => path.normalize(testFile));
Expand All @@ -75,27 +70,17 @@ export function createTestSessions(
throw new Error(`Could not find any test files with pattern(s): ${group.files}`);
}

for (const file of testFilesForGroup) {
testFiles.add(file);
}

const sessionGroup: TestSessionGroup = {
name: group.name,
browsers: group.browsers,
testFiles: testFilesForGroup,
testRunnerHtml: group.testRunnerHtml,
sessionIds: [],
};

for (const browser of group.browsers) {
for (const browser of browsers) {
browsers.add(browser);
}

for (const testFile of testFilesForGroup) {
testFiles.add(testFile);

for (const browser of group.browsers) {
const session: TestSession = {
testSessions.push({
id: nanoid(),
group: sessionGroup,
group,
debug: false,
testRun: -1,
browser,
Expand All @@ -104,10 +89,7 @@ export function createTestSessions(
errors: [],
logs: [],
request404s: [],
};

testSessions.push(session);
sessionGroup.sessionIds.push(session.id);
});
}
}
}
Expand All @@ -117,7 +99,6 @@ export function createTestSessions(
}

return {
sessionGroups,
testSessions,
testFiles: Array.from(testFiles),
browsers: Array.from(browsers),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { BrowserLauncher } from '../browser-launcher/BrowserLauncher';
import { TestSessionGroup } from './TestSessionGroup.js';

export interface BasicTestSession {
id: string;
group: TestSessionGroup;
group: { name: string };
debug: boolean;
browser: BrowserLauncher;
testFile: string;
Expand Down
15 changes: 0 additions & 15 deletions packages/test-runner-core/src/test-session/TestSessionGroup.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { TestSession } from './TestSession.js';
import { TestSessionStatus } from './TestSessionStatus.js';
import { EventEmitter } from '../utils/EventEmitter.js';
import { DebugTestSession } from './DebugTestSession.js';
import { TestSessionGroup } from './TestSessionGroup.js';
import { BrowserLauncher } from '../browser-launcher/BrowserLauncher.js';

interface EventMap {
Expand All @@ -19,13 +18,11 @@ function* filtered<T>(it: Iterator<T>, filter: (value: T) => unknown) {
}

export class TestSessionManager extends EventEmitter<EventMap> {
private _groups: TestSessionGroup[];
private sessionsMap = new Map<string, TestSession>();
private debugSessions = new Map<string, DebugTestSession>();

constructor(groups: TestSessionGroup[], sessions: TestSession[]) {
constructor(sessions: TestSession[]) {
super();
this._groups = groups;
for (const session of sessions) {
this.sessionsMap.set(session.id, session);
}
Expand All @@ -51,10 +48,6 @@ export class TestSessionManager extends EventEmitter<EventMap> {
this.emit('session-updated', undefined);
}

groups() {
return this._groups;
}

get(id: string) {
return this.sessionsMap.get(id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('TestScheduler', () => {
const session = createSession({ id, browser });
sessions.push(session);
}
const sessionManager = new TestSessionManager([], sessions);
const sessionManager = new TestSessionManager(sessions);
const scheduler = new TestScheduler(mockConfig, sessionManager, [browser]);
return [scheduler, sessionManager, sessions, browserStubs];
}
Expand Down Expand Up @@ -323,7 +323,7 @@ describe('TestScheduler', () => {
}
}

const sessionManager = new TestSessionManager([], sessions);
const sessionManager = new TestSessionManager(sessions);
const scheduler = new TestScheduler(
mockConfig,
sessionManager,
Expand Down
7 changes: 5 additions & 2 deletions packages/test-runner/src/config/collectGroupConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { readConfig, ConfigLoaderError } from '@web/config-loader';
import globby from 'globby';
import { TestRunnerStartError } from '../TestRunnerStartError.js';

function validateGroupConfig(configFilePath: string, config: Partial<TestRunnerGroupConfig>) {
function validateGroupConfig(
configFilePath: string,
config: Partial<TestRunnerGroupConfig>,
): TestRunnerGroupConfig {
if (config.browsers != null && !Array.isArray(config.browsers)) {
throw new TestRunnerStartError(
`Group config at ${configFilePath} has invalid browsers option. It should be an array.`,
Expand All @@ -16,7 +19,7 @@ function validateGroupConfig(configFilePath: string, config: Partial<TestRunnerG
);
}

return { name: configFilePath, configFilePath, ...config } as TestRunnerGroupConfig;
return { name: configFilePath, ...config };
}

export async function collectGroupConfigs(patterns: string[]) {
Expand Down