Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ const KarmaTestRunner: TestRunner = {
checker.check('karma');
checker.check('karma-jasmine');

// Check for browser launchers
if (options.browsers?.length) {
for (const browser of options.browsers) {
const launcherName = `karma-${browser.toLowerCase().split('headless')[0]}-launcher`;
checker.check(launcherName);
}
// A custom configuration loads its own launcher plugins and may define custom launchers.
// The built-in configuration only loads the Chrome launcher, which also provides Chromium.
if (!options.runnerConfig) {
checker.check('karma-chrome-launcher');
}

if (options.coverage.enabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ import KarmaTestRunner from './index';

describe('KarmaTestRunner', () => {
describe('validateDependencies', () => {
function createOptions(coverageEnabled: boolean): NormalizedUnitTestBuilderOptions {
function createOptions(
coverageEnabled: boolean,
options: Partial<NormalizedUnitTestBuilderOptions> = {},
): NormalizedUnitTestBuilderOptions {
return {
projectSourceRoot: '/non-existent',
coverage: { enabled: coverageEnabled },
...options,
} as NormalizedUnitTestBuilderOptions;
}

Expand All @@ -29,5 +33,24 @@ describe('KarmaTestRunner', () => {
/karma-coverage/,
);
});

it('requires karma-chrome-launcher for Chromium with the built-in configuration', () => {
const options = createOptions(false, { browsers: ['ChromiumHeadless'] });

expect(() => KarmaTestRunner.validateDependencies?.(options)).toThrowError(
/^(?!.*karma-chromium-launcher).*karma-chrome-launcher/s,
);
});

it('does not require launchers for the browsers of a custom configuration', () => {
const options = createOptions(false, {
browsers: ['ChromeNoSandbox'],
runnerConfig: 'karma.conf.js',
});

expect(() => KarmaTestRunner.validateDependencies?.(options)).toThrowError(
/^(?!.*-launcher)/s,
);
});
});
});
Loading