Angular-cli: Multi App Test Command - Doesn't pick up app name

Created on 28 Aug 2017  路  8Comments  路  Source: angular/angular-cli

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Versions.

@angular/cli: 1.3.0
node: 8.2.0
os: win32 x64
@angular/animations: 4.3.6
@angular/common: 4.3.6
@angular/compiler: 4.3.6
@angular/core: 4.3.6
@angular/forms: 4.3.6
@angular/http: 4.3.6
@angular/platform-browser: 4.3.6
@angular/platform-browser-dynamic: 4.3.6
@angular/router: 4.3.6
@angular/cli: 1.3.0
@angular/compiler-cli: 4.3.6
@angular/language-service: 4.3.6

Repro steps.

If you put two apps into the generated angular cli project you can suppply the --app parameter and get each app to serve.

However I can't seem to get this to do the same thing with a test the following steps are contained in this repo:

https://github.com/sethreidnz/angular-cli-multi-app-test-repro

But repeated here:

First clone this repo:

git clone https://github.com/sethreidnz/angular-cli-multi-app-test-repro

Install the npm packages:

npm install
``

If you serve them with the following commands they run fine:

```bash
ng serve --app app1
ng serve --app app2

You will see that the apps have different titles, this is the only difference between their files contained in folders /app1 and /app2.

However if you try to run the tests as in the test help command:

ng test -h

With the parameter --app like so:

ng test --sr --app app1
ng test --sr --app app2

You will get the exact same error:

Expected 'APP 1!' to equal 'app'.

Even though they both have a different title property in their respective app/app.component.ts. You would expect the app2 test to have an error like:

Expected 'app 2!' to equal 'app'.

Desired functionality.

Be able to run each projects test by passing the --app parameter equal to the app definition in the .angular-cli.json file.

1 (urgent) broken bufix

All 8 comments

Any ideas on why this is happening? Do you want a contrib?

I ran into this problem today, it looks like it always takes the first app when building the webpack config for testing,

https://github.com/angular/angular-cli/blob/1.4.x/packages/%40angular/cli/models/webpack-configs/test.ts#L22

I ended up working around this problem by providing another karma.config.js for the second app that overrides the webpack.entry config with the correct entries.

@rorticus Could you please provide a karma.conf.js snippet for your webpack entries?

I have two apps in separate folders (say app1, app2). The angular-cli.json is in their parent folder.
I have two karma.config.js files in the two folders, this seems to work (app1 and app2 respectively):

var path = require('path');
module.exports = function (config) {
config.set({
...
webpack: {
entry: {
main: [path.resolve('.','app2', 'test.ts')]
}
},

But still needed to import polyfills in the beginning of test.ts for it to work. Why is that?

@csaadaam I think you need to include an extra entry for the polyfills,

webpack: {
    entry: {
        main: path.resolve('./app2/src/test.ts'),
        polyfills: [path.resolve('./app2/src/polyfills.ts')]
    }
}

It works this way as well, thanks!

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings