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

SyntaxError with Component and multiple styleUrl files #9

Closed
intellix opened this issue Apr 5, 2017 · 7 comments
Closed

SyntaxError with Component and multiple styleUrl files #9

intellix opened this issue Apr 5, 2017 · 7 comments

Comments

@intellix
Copy link
Contributor

intellix commented Apr 5, 2017

When running tests with multiple CSS files we're getting a huge wall of SyntaxErrors. After hunting what is causing it, I've found a few variations which fail:

These work:

@Component({
  selector: 'xc-media-box-h0',
  templateUrl: './media-box-h0.component.html',
  styleUrls: ['../media-box.component.scss', './media-box-h0.component.scss'],
})

@Component({
  selector: 'xc-media-box-h0',
  templateUrl: './media-box-h0.component.html',
  styleUrls: [
    '../media-box.component.scss'
  ],
})

@Component({
  selector: 'xc-media-box-h0',
  templateUrl: './media-box-h0.component.html',
  styleUrls: [
    '../media-box.component.scss'],
})

These fail:

@Component({
  selector: 'xc-media-box-h0',
  templateUrl: './media-box-h0.component.html',
  styleUrls: ['../media-box.component.scss',
  './media-box-h0.component.scss'],
})

@Component({
  selector: 'xc-media-box-h0',
  templateUrl: './media-box-h0.component.html',
  styleUrls: [
    '../media-box.component.scss',
  ],
})

@Component({
  selector: 'xc-media-box-h0',
  templateUrl: './media-box-h0.component.html',
  styleUrls: [
    '../media-box.component.scss',
    './media-box-h0.component.scss'
  ],
})

I'm wondering if it's to do with the commas on separate lines. I have no idea where this error comes from, so apologies if I've create an issue in the wrong package :)

Error:

console.error node_modules/zone.js/dist/zone-node.js:569
    Unhandled Promise rejection: SyntaxError
        at XMLHttpRequest.open (/Users/dominic/Sites/stash/xcaf/r2d2/node_modules/jsdom/lib/jsdom/living/xmlhttprequest.js:486:15)
@thymikee
Copy link
Owner

thymikee commented Apr 5, 2017

This is because of regex I use: https://github.com/thymikee/jest-preset-angular/blob/master/preprocessor.js#L3.
I'd be glad if you could improve it so it's more bulletproof.

@thymikee
Copy link
Owner

thymikee commented Apr 5, 2017

What happens here is we need to replace all styleUrls: [...] with styles: [].

@intellix
Copy link
Contributor Author

intellix commented Apr 5, 2017

I'm baaad, shamone, at regex but will give it a go :) I was hoping to find similar functionality inside Angular CLI but I believe they're using AST for stuff like this

@thymikee
Copy link
Owner

thymikee commented Apr 5, 2017

Ideally we would do this with ASTs, but we would need to cache it.

@thymikee
Copy link
Owner

thymikee commented Apr 5, 2017

@intellix I've submitted a PR for this, can you check if it works for you?

@intellix
Copy link
Contributor Author

intellix commented Apr 5, 2017

@thymikee Much more works now, I noticed this one failed:

@Component({
  selector: 'xc-media-box-h0',
  templateUrl: './media-box-h0.component.html',
  styleUrls: ['../media-box.component.scss',
  './media-box-h0.component.scss'],
})

@thymikee
Copy link
Owner

thymikee commented Apr 5, 2017

Let's move the discussion here: #10

@thymikee thymikee closed this as completed Apr 5, 2017
@thymikee thymikee reopened this Apr 5, 2017
JLHwung added a commit to JLHwung/jest-preset-angular that referenced this issue Dec 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants