Skip to content

Commit

Permalink
fixup! test: run legacy-cli e2e tests via bazel
Browse files Browse the repository at this point in the history
fixup: add ChromeHeadlessNoSandbox browser to to karma builder
  • Loading branch information
jbedard authored and angular-robot[bot] committed Nov 28, 2022
1 parent 794e33a commit 9e57770
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ function getBuiltInKarmaConfig(
logLevel: karma.constants.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
customLaunchers: {
ChromeHeadlessNoSandbox: {
base: 'ChromeHeadless',
flags: ['--no-sandbox', '--headless', '--disable-gpu', '--disable-dev-shm-usage'],
},
},
restartOnFileChange: true,
};
}
Expand Down
13 changes: 12 additions & 1 deletion tests/legacy-cli/e2e/assets/13.0-project/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,18 @@ module.exports = function (config) {
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
browsers: ['ChromeHeadlessNoSandbox'],
customLaunchers: {
ChromeHeadlessNoSandbox: {
base: 'ChromeHeadless',
flags: [
'--no-sandbox',
'--headless',
'--disable-gpu',
'--disable-dev-shm-usage',
],
}
},
singleRun: false,
restartOnFileChange: true
});
Expand Down
66 changes: 0 additions & 66 deletions tests/legacy-cli/e2e/utils/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,45 +187,6 @@ export function useCIDefaults(projectName = 'test-project'): Promise<void> {
});
}

const KARMA_CONF_DEFAULT = `
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
jasmine: {},
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
jasmineHtmlReporter: {
suppressAll: true // removes the duplicated traces
},
coverageReporter: {
dir: require('path').join(__dirname, './coverage/$PROJECT_NAME$'),
subdir: '.',
reporters: [
{ type: 'html' },
{ type: 'text-summary' }
]
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
restartOnFileChange: true
});
};
`;

export async function useCIChrome(projectName: string, projectDir = ''): Promise<void> {
const protractorConf = path.join(projectDir, 'protractor.conf.js');
if (fs.existsSync(protractorConf)) {
Expand All @@ -245,38 +206,11 @@ export async function useCIChrome(projectName: string, projectDir = ''): Promise
);
}

const karmaConf = path.join(projectDir, 'karma.conf.js');

// Create one with default config if it doesn't exist
if (!fs.existsSync(karmaConf)) {
await writeFile(karmaConf, KARMA_CONF_DEFAULT.replace('$PROJECT_NAME$', projectName));
}

// Update to use the headless sandboxed chrome
await replaceInFile(
karmaConf,
/browsers:.*\]\s*,/,
`
browsers: ['ChromeHeadlessNoSandbox'],
customLaunchers: {
ChromeHeadlessNoSandbox: {
base: 'ChromeHeadless',
flags: [
'--no-sandbox',
'--headless',
'--disable-gpu',
'--disable-dev-shm-usage',
],
}
},
`,
);

return updateJsonFile('angular.json', (workspaceJson) => {
const project = workspaceJson.projects[projectName];
const appTargets = project.targets || project.architect;
appTargets.test.options.browsers = 'ChromeHeadlessNoSandbox';
appTargets.test.options.karmaConfig = karmaConf;
});
}

Expand Down

0 comments on commit 9e57770

Please sign in to comment.