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
  • Loading branch information
jbedard committed Nov 8, 2022
1 parent 37c127d commit f7210a0
Showing 1 changed file with 63 additions and 72 deletions.
135 changes: 63 additions & 72 deletions tests/legacy-cli/e2e/utils/project.ts
Expand Up @@ -187,6 +187,45 @@ 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 @@ -207,80 +246,32 @@ export async function useCIChrome(projectName: string, projectDir = ''): Promise
}

const karmaConf = path.join(projectDir, 'karma.conf.js');
// Modify existing karma config
if (fs.existsSync(karmaConf)) {
await replaceInFile(
karmaConf,
/browsers:.*\]\s*,/,
`
browsers: ['ChromeHeadlessNoSandbox'],
customLaunchers: {
ChromeHeadlessNoSandbox: {
base: 'ChromeHeadless',
flags: [
'--no-sandbox',
'--headless',
'--disable-gpu',
'--disable-dev-shm-usage',
],
}
},
`,
);
// Otherwise need to create new standalone config to ensure ChromeHeadlessNoSandbox is used
} else {
await writeFile(
karmaConf,
`
const path = require('path');
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: {
clearContext: false, // leave Jasmine Spec Runner output visible in browser
},
jasmineHtmlReporter: {
suppressAll: true // removes the duplicated traces
},
coverageReporter: {
dir: path.join(__dirname, './coverage'),
subdir: '.',
reporters: [
{type: 'lcov'},
],
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['ChromeHeadlessNoSandbox'],
customLaunchers: {
ChromeHeadlessNoSandbox: {
base: 'ChromeHeadless',
flags: [
'--no-sandbox',
'--headless',
'--disable-gpu',
'--disable-dev-shm-usage',
],
}
},
singleRun: false,
});
};
`,
);

// 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;
Expand Down

0 comments on commit f7210a0

Please sign in to comment.