Skip to content

Commit

Permalink
Overhaul regex for styleUrls (#10)
Browse files Browse the repository at this point in the history
* Overhaul regex for styleUrls

* Add tests
  • Loading branch information
thymikee authored Apr 5, 2017
1 parent 5d143c9 commit f6cbde3
Show file tree
Hide file tree
Showing 6 changed files with 436 additions and 28 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/example
/__tests__
circle.yml
43 changes: 43 additions & 0 deletions __tests__/preprocessor.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const {process} = require('../preprocessor');

const sources = [
`@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'],
})`,
`@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'
],
})`
];

const config = {
"globals": {
"__TS_CONFIG__": "example/src/tsconfig.spec.json",
"__TRANSFORM_HTML__": true
},
}

sources.forEach(source => {
test(`works with ${source}`, () => {
expect(process(source, '', config)).toMatch('styles: []');
});
});
1 change: 1 addition & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ dependencies:
- cd example && yarn install --no-progress
test:
override:
- yarn run test:ci
- yarn link && cd example && yarn run test:ci
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@
"author": "Michał Pierzchała <thymikee@gmail.com>",
"license": "BSD-3",
"dependencies": {
"jest-zone-patch": "^0.0.5",
"ts-jest": "^19.0.6"
"jest-zone-patch": "^0.0.5"
},
"devDependencies": {
"jest": "^19.0.2",
"ts-jest": "^19.0.7",
"typescript": "^2.2.2"
},
"scripts": {
"test": "jest",
"test:ci": "jest -i"
}
}
2 changes: 1 addition & 1 deletion preprocessor.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const {process} = require('ts-jest/preprocessor.js');
const TEMPLATE_URL_REGEX = /templateUrl:\s*((?:'|").*(?:'|"))/g;
const STYLE_URLS_REGEX = /styleUrls:\s*\[\s*((?:'|").*(?:'|"))\s*\]/g;
const STYLE_URLS_REGEX = /styleUrls:\s*\[\s*((?:'|").*\s*(?:'|")).*\s*.*\]/g;

module.exports.process = (src, path, config) => {
// Replace `templateUrl: ''` calls with `template: require('')`
Expand Down
Loading

0 comments on commit f6cbde3

Please sign in to comment.