Skip to content

ng test losing typings after retrigger #5332

Closed

Description

@tmansson

OS?

Linux (Ubuntu 16.04)

Versions.

@angular/cli: 1.0.0-rc.1
node: 6.10.0
os: linux x64
@angular/common: 2.4.9
@angular/compiler: 2.4.9
@angular/core: 2.4.9
@angular/forms: 2.4.9
@angular/http: 2.4.9
@angular/platform-browser: 2.4.9
@angular/platform-browser-dynamic: 2.4.9
@angular/router: 3.4.9
@angular/cli: 1.0.0-rc.1
@angular/compiler-cli: 2.4.9

Repro steps.

  • ng new ngTest
  • cd ngTest
  • yarn
  • Create folder typings in src
  • Create file common.d.ts in src/typings with content:
declare module Common {
  export interface IAction {
    type: string;
  }
}
  • In app.component.ts add a constructor
constructor() {
  const action: Common.IAction = { type: 'test' };
}
  • Running ng test once works
  • Saving app.component.ts (retriggering ng test) fails to find type definition, but test succeeds

The log given by the failure.

ERROR in /home/tobias/projects/external/ngTest/src/app/app.component.ts (12,19): Cannot find namespace 'Common'.)
Chrome 56.0.2924 (Linux 0.0.0): Executed 3 of 3 SUCCESS (0.222 secs / 0.215 secs)

Activity

  1. tmansson commented on Mar 9, 2017

    @tmansson
    Author

    After fiddling some more with this I notice that the typing error actually stops the rebuild, and runs the test again with the previous build.

    This make it look like the test succeeds even though the typing fails, but it's just showing a result from a previous build.

    To be able to run tests that actually tests my current code, I need to use ng test --single-run true.

  2. added this to the milestone on Mar 18, 2017
  3. self-assigned this
    on Mar 18, 2017
  4. added 10 commits that reference this issue on Mar 18, 2017
    4f05519
    ad58c18
    73211d6
    e6cfb77
    eb63b6f
    5ab01b7
    e549f72
    f8a34c1
    31ece40
    2d6d4e2
  5. 1 remaining item

  6. added a commit that references this issue on Mar 20, 2017
    adabd88
  7. added a commit that references this issue on Mar 20, 2017
    303b2c0
  8. tmansson commented on Mar 21, 2017

    @tmansson
    Author

    I'm sorry to say that it still doesn't work with the application I created for this issue. I updated to rc4 as shown here:

        _                      _                 ____ _     ___
       / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
      / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
     / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
    /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                   |___/
    @angular/cli: 1.0.0-rc.4
    node: 6.10.0
    os: linux x64
    @angular/common: 2.4.10
    @angular/compiler: 2.4.10
    @angular/core: 2.4.10
    @angular/forms: 2.4.10
    @angular/http: 2.4.10
    @angular/platform-browser: 2.4.10
    @angular/platform-browser-dynamic: 2.4.10
    @angular/router: 3.4.10
    @angular/cli: 1.0.0-rc.4
    @angular/compiler-cli: 2.4.10
    

    The change I see is that the test no longer succeeds, which is certainly an improvement. :)

    Am I doing something wrong by adding a d.ts file like this. ng serve and ng build works fine with this setup, just like before.

  9. filipesilva commented on Mar 24, 2017

    @filipesilva
    Contributor

    @bialad it should be working now... can you show me your src/tsconfig.spec.json?

    As part of the changes in that PR, we modified the default unit test tsconfig to actually include .d.ts files, which it didn't before.

      "include": [
        "**/*.spec.ts",
        "**/*.d.ts"
      ]
    

    We added it to https://github.com/angular/angular-cli/wiki/stories-1.0-update but I should have come back here to tell you that.

    If you do this change, does it work?

  10. tmansson commented on Mar 25, 2017

    @tmansson
    Author

    @filipesilva The results are different now, but still not correct.

    Even though it's a standard cli application, I created a repo to base the discussion on. I recreated the application from scratch with the CLI 1.0.0 and Anuglar 4.0.0 version, to be sure I'm not encountering any bugs because of mismatching version when updating.

    • Now when I run ng test the first time, everything work. As it did before.

    • Then changing the code in app.component.ts behaves as expected. For example changing 'test' to 1 fails. Great so far. :)

    • If I keep 'test' in AppComponent, and instead change the type property in common.d.ts from string to number, it successes. Not good.

    • If I keep the type change and stop and restart ng test it still succeeds, which it shouldn't...

    • Then changing 'test' i AppComponent to 1 succeeds (as it now should), BUT when changing 1 back to 'test' it falis (as it should).

    This is very confusing to me, especially when the behavior isn't consistent. My guess is some sort of type caching not updating correctly...

    Hope you could follow my steps here, and am able to reproduce this issue. Otherwise it must be something in my platform. The fact the I can now run my tests without single-run as long as I don't change my typings is i big step forward and a time saver.

  11. boldwade commented on Mar 26, 2017

    @boldwade

    I'm experiencing a similar issue as well. I'm on cli, 1.0.0-rc.2 but our ng version is at 2.4.9. Karma is 1.5, typescript is 2.1.6. Running a test the first time works as expected, make a simple change to kick off another test run and the build will randomly fail with some random typescript error, such as 'HTMLInputElement' not found, for what appears to be a problem with the typings get lost. This doesn't appear to be an issue that occurs every time, seems to be a bit random. I've been noticing this off and on for about a week. Not sure the root cause, but the above sounds like a match.

  12. filipesilva commented on Mar 26, 2017

    @filipesilva
    Contributor

    @bialad ah, that exist exists but it's a different one! #5634 seems to be related to interfaces and probably all .d.ts files instead. We're tracking it there instead.

    @boldwade unfortunately to fix this you really need to update to 1.0.0, that's when the fix landed.

  13. angular-automatic-lock-bot commented on Sep 6, 2019

    @angular-automatic-lock-bot

    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.

  14. locked and limited conversation to collaborators on Sep 6, 2019
  15. added a commit that references this issue on May 29, 2026
    586606e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions