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

@nrwl/angular:karma-project does not get config properly #9234

Closed
ghost opened this issue Mar 8, 2022 · 2 comments · Fixed by #9485
Closed

@nrwl/angular:karma-project does not get config properly #9234

ghost opened this issue Mar 8, 2022 · 2 comments · Fixed by #9485
Assignees
Labels
outdated scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx type: bug

Comments

@ghost
Copy link

ghost commented Mar 8, 2022

Current Behavior

Currently the command creates only one karma.conf.js in the default application folder even if no other configs exist. As well, when you do get a base config created it does not pass the config to any calling config files.

Expected Behavior

Expected behavior is that running nx g @nrwl/angular:karma-project should create a base config if no config exists and the base config should "return" itself to pass itself to any child configs that may exist;

Steps to Reproduce

The output of the command with no preexisting config shows:

CREATE: karma.conf.js
CREATE: test.ts
...

Inside that karma.conf.js:

const { join } = require("path");
const getBaseKarmaConfig = require("../../karma.conf");

module.exports = function (config) {
        // getBaseKarmaConfig is undefined because the base config does not exist
        // running the tests becomes impossible because an error is thrown on the next line
	const baseConfig = getBaseKarmaConfig();
	config.set({
		...baseConfig,
		coverageReporter: {
			...baseConfig.coverageReporter,
			dir: join(__dirname, "../../coverage/apps/portfolio"),
		},
	});
};

running the same command with a config file already existing also creates a situation where running the tests is impossible:
BASE KARMA CONFIG

const { join } = require('path');
const { constants } = require('karma');

module.exports = () => {
	return {
		basePath: '',
		frameworks: ['jasmine', '@angular-devkit/build-angular'],
		plugins: [
			require('karma-jasmine'),
			require('karma-chrome-launcher'),
			require('karma-jasmine-html-reporter'),
			require('@angular-devkit/build-angular/plugins/karma'),
			require('karma-coverage'),
			require('karma-mocha-reporter'),
			require('karma-nunit2-reporter'),
			require('karma-spec-reporter')
		],
		client: {
			clearContext: false,
			jasmine: {
				random: false
			}
		},
		jasmineHtmlReporter: {
			suppressAll: true,
		},
		reporters: ['mocha', 'coverage', 'spec'],
		mochaReporter: {
			output: 'minimal',
			ignoreSkipped: true,
			maxLogLines: 5
		},
		nunitReporter: {
			outputFile: 'src\\e2e\\test-results\\TEST-karma.xml'
		},
		reportSlowerThan: 500,
		port: 9876,
		colors: true,
		logLevel: constants.LOG_INFO,
		autoWatch: true,
		browsers: ['Chrome'],
		singleRun: false,
		restartOnFileChange: true,
		customLaunchers: {
			chromeDebugging: {
				base: 'Chrome',
				flags: ['--remote-debugging-port=9333'],
			},
			headlessChrome: {
				base: 'ChromeHeadless',
				flags: [
					'--no-sandbox',
					'--no-proxy-server',
					'--disable-web-security',
					'--disable-gpu',
					'--js-flags=-max-old-space-size=8196'
				]
			}
		},
		preprocessors: {
			'src/**/*.js': ['coverage'],
		},
	};
        // method ends without passing it's config to the calling method
        // not returning is ok if you are in a project that will only ever have one app and NO libs
};

CHILD KARMA CONFIG

const { join } = require("path");
const getBaseKarmaConfig = require("../../karma.conf");

module.exports = function (config) {
	const baseConfig = getBaseKarmaConfig();
	config.set({
		...baseConfig,
		coverageIstanbulReporter: {
			...baseConfig.coverageIstanbulReporter,
			dir: join(__dirname, "../../coverage/libs/user"),
		},
	});
};

Environment

Node : 16.13.2
OS : win32 x64
npm : 8.3.0

nx : 13.8.5
@nrwl/angular : 13.8.5
@nrwl/cli : 13.8.5
@nrwl/cypress : 13.8.5
@nrwl/detox : undefined
@nrwl/devkit : 13.8.5
@nrwl/eslint-plugin-nx : 13.8.5
@nrwl/express : undefined
@nrwl/jest : 13.8.5
@nrwl/js : undefined
@nrwl/linter : 13.8.5
@nrwl/nest : undefined
@nrwl/next : undefined
@nrwl/node : undefined
@nrwl/nx-cloud : 13.1.6
@nrwl/react : undefined
@nrwl/react-native : undefined
@nrwl/schematics : undefined
@nrwl/storybook : 13.8.5
@nrwl/tao : 13.8.5
@nrwl/web : undefined
@nrwl/workspace : 13.8.5
typescript : 4.5.5
rxjs : 7.4.0

Community plugins:
@angular/animations: 13.2.5
@angular/common: 13.2.5
@angular/compiler: 13.2.5
@angular/core: 13.2.5
@angular/forms: 13.2.5
@angular/platform-browser: 13.2.5
@angular/platform-browser-dynamic: 13.2.5
@angular/router: 13.2.5
@angular-devkit/build-angular: 13.2.5
@angular/cli: 13.2.5
@angular/compiler-cli: 13.2.5
@angular/language-service: 13.2.5

@ghost ghost added the type: bug label Mar 8, 2022
@AgentEnder AgentEnder added the scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx label Mar 14, 2022
@barbados-clemens
Copy link
Contributor

Hi @MasterSaberD1996
I'm not sure I understand the last part of your issue.

running the same command with a config file already existing also creates a situation where running the tests is impossible:

can you explain further how you get your workspace into that state?

creating a project with karma as the test runner will create the root config.
then creating another project without a test runner will not have the project karma config.
using nx g @nrwl/angular:karma-project --project=<project-without-karma> adds the local config and then the tests start working in my experience.

So if you can clarify what you you mean by "running the tests is impossible" so I can figure out how to fix this.

in the mean time I'll update the karma project generator to create the root karma config if it's not present.

Thanks!

barbados-clemens added a commit that referenced this issue Mar 23, 2022
…arma-project generator

when using the karma-project generator directory ensure the karma generator (install deps/root
config) is called if the root karma config isn't present

ISSUES CLOSED: #9234
barbados-clemens added a commit that referenced this issue Mar 24, 2022
…arma-project generator

when using the karma-project generator directory ensure the karma generator (install deps/root
config) is called if the root karma config isn't present

ISSUES CLOSED: #9234
barbados-clemens added a commit that referenced this issue Mar 25, 2022
…arma-project generator

when using the karma-project generator directory ensure the karma generator (install deps/root
config) is called if the root karma config isn't present

ISSUES CLOSED: #9234
barbados-clemens added a commit that referenced this issue Mar 25, 2022
…arma-project generator (#9485)

when using the karma-project generator directory ensure the karma generator (install deps/root
config) is called if the root karma config isn't present

ISSUES CLOSED: #9234
sidmonta pushed a commit to sidmonta/nx that referenced this issue Apr 2, 2022
…arma-project generator (nrwl#9485)

when using the karma-project generator directory ensure the karma generator (install deps/root
config) is called if the root karma config isn't present

ISSUES CLOSED: nrwl#9234
@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants