lucono/karma-test-explorer

Many Tests show up as unmapped in version 0.7.4 that were correctly mapped in 0.7.3

paulheg opened this issue ยท 11 comments

When using version 0.7.4 many spec files wouldnt get read correctly, resulting in many unmapped tests.
I switched to 0.7.3 where most of the tests could be mapped again.

I got a bunch of these messages:

[2022-08-28 16:12:29.579] [ERROR] [TestLocator]: Failed to get tests from spec file /home/paul/git/[...].component.spec.ts: SyntaxError: Unexpected token (5:15)
[2022-08-28 16:12:29.580] [ERROR] [TestLocator]: Failed to get tests from spec file /home/paul/git/[...].component.spec.ts: SyntaxError: Unexpected token (6:15)
[2022-08-28 16:12:29.581] [ERROR] [TestLocator]: Failed to get tests from spec file /home/paul/git/[...].component.spec.ts: SyntaxError: Unexpected token (10:15)
[2022-08-28 16:12:29.583] [ERROR] [TestLocator]: Failed to get tests from spec file /home/paul/git/[...].component.spec.ts: SyntaxError: Unexpected token (16:15)

I look into the files, but I cant seem to find anything wrong with them.
So I switched back to 0.7.3 and it worked again.

  • OS: WSL: Ubuntu
  • Karma Version: 0.7.4
  • Frameworks: Angular, Jasmine
  1. Are they JS or TS (or other type of) test file?
  2. What's their file extension?
  3. Are you able to share some of the test files, or a snippet of the sections where the syntax error is being reported?
import { ComponentFixture, TestBed } from '@angular/core/testing';
import Mexp from 'math-expression-evaluator';

import { SolutionFormulaComponent } from './solution-formula.component';

describe('SolutionFormulaComponent', () => {
  let component: SolutionFormulaComponent;
  let fixture: ComponentFixture<SolutionFormulaComponent>;

  beforeEach(async () => {
    await TestBed.configureTestingModule({
      declarations: [SolutionFormulaComponent]
    })
      .compileComponents();
  });

  beforeEach(() => {
    fixture = TestBed.createComponent(SolutionFormulaComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });
});

[2022-08-29 09:48:09.329] [ERROR] [TestLocator]: Failed to get tests from spec file /home/paul/git/[...]/solution-formula.component.spec.ts: SyntaxError: Unexpected token (6:15)

It seems to me that the error always occurs in the describe line.

I am also having this issue, with the same error message. However for me, the Unexpected token occurs on (6:15) then (7:15), (8:15), (9:15) and (10:15) all in the same file. Some of those lines are blank.

Thanks for making this extension, it really helps me a lot :)

The issue I am running into is that it can't find the source code for the tests. They seem to be running ok though

The beta branch has some updates to the parser. Install the visx build of the branch (it should appear as v0.7.5) and post all WARN messages from the log, even if the tests are all mapped.

There seem to be three kinds of errors:

SyntaxError: This experimental syntax requires enabling one of the following parser plugin(s): "decorators", "decorators-legacy". (11:0):
@Component({selector: 'app-notification', template: ''})
^
(Does file extension accurately reflect type of file contents?)
[2022-08-30 08:07:30.087] [WARN] [AstTestFileParser]: Parse operation pxxa1v3o00e: Error parsing file '/home/paul/git/[...]/src/app/app.component.spec.ts' using parser plugins: []:
-----

it seems to dislike : characters

[2022-08-30 08:07:30.491] [WARN] [AstTestFileParser]: Parse operation hfiaz6m2tk: Error parsing file '/home/paul/git/[...]/image.component.spec.ts' using parser plugins: []:
-----
SyntaxError: Unexpected token (5:15):
  let component: ImageComponent;
               ^
(Does file extension accurately reflect type of file contents?)
[2022-08-30 08:07:30.491] [WARN] [AstTestFileParser]: Parse operation hfiaz6m2tk: Error parsing file '/home/paul/git/[...]/image.component.spec.ts' using parser plugins: []:
-----
SyntaxError: Unexpected token (5:15):
  let component: ImageComponent;
               ^
(Does file extension accurately reflect type of file contents?)
[2022-08-30 08:07:30.491] [ERROR] [TestLocator]: Failed to get tests from spec file /home/paul/git/[...]/image.component.spec.ts: Error: Parse operation hfiaz6m2tk: Error parsing file '/home/paul/git/[...]/image.component.spec.ts': 
-----
SyntaxError: Unexpected token (5:15):
  let component: ImageComponent;
               ^
[2022-08-30 08:07:30.492] [WARN] [AstTestFileParser]: Parse operation 27zcqnw2soe: Error parsing file '/home/paul/git/[...]/media-browser.component.spec.ts' using parser plugins: []:
-----
SyntaxError: Unexpected token (9:15):
  let component: MediaBrowserComponent;
               ^
(Does file extension accurately reflect type of file contents?)
[2022-08-30 08:07:30.493] [WARN] [AstTestFileParser]: Parse operation 27zcqnw2soe: Error parsing file '/home/paul/git/[...]/media-browser.component.spec.ts' using parser plugins: []:
-----
SyntaxError: Unexpected token (9:15):
  let component: MediaBrowserComponent;
               ^

These errors occure in files that are referenced in tests but not tests themselfes.

(Does file extension accurately reflect type of file contents?)
[2022-08-30 08:07:30.531] [WARN] [AstTestFileParser]: Parse operation wy7xg00lvq: Error parsing file '/home/paul/git/[...]/src/app/common/test/test-data.ts' using parser plugins: []:
-----
SyntaxError: Unexpected token (8:11):
    public static testTaskImage: MediaAttributes = {
           ^
(Does file extension accurately reflect type of file contents?)
[2022-08-30 08:07:30.531] [ERROR] [TestLocator]: Failed to get tests from spec file /home/paul/git/[...]/src/app/common/test/test-data.ts: Error: Parse operation wy7xg00lvq: Error parsing file '/home/paul/git/[...]/src/app/common/test/test-data.ts': 
-----
SyntaxError: Unexpected token (8:11):
    public static testTaskImage: MediaAttributes = {
           ^

I ran into the same issue, things worked fine with 0.7.3 with the exception of test files containing decorator syntax.

With 0.7.4 almost no tests showed up. I found that the new Enable Parser Plugins setting was empty and after adding typescript, decorators and jsx, all tests seemed to show up, even the ones with decorator syntax.

I ran into the same issue, things worked fine with 0.7.3 with the exception of test files containing decorator syntax.

With 0.7.4 almost no tests showed up. I found that the new Enable Parser Plugins setting was empty and after adding typescript, decorators and jsx, all tests seemed to show up, even the ones with decorator syntax.

Same here. Adding this setting fixed the issues, and all tests are now correctly mapped in my Angular project:
"karmaTestExplorer.enabledParserPlugins": ["typescript", "decorators"]

Remove the karmaTestExplorer.enabledParserPlugins setting if you added it, and try the latest .visx from the beta branch to check if it resolves the issue without the setting. Also post any warnings or errors from the logs.

Released a fix as v0.7.5. Please update and confirm if any other issues.

Thank you for your work. Seems to work fine on my side ๐Ÿ‘