Skip to content

Commit c275166

Browse files
authored
feat: allow css testing with @Component property styleUrls (#903)
1 parent 867d5e0 commit c275166

File tree

13 files changed

+32
-116
lines changed

13 files changed

+32
-116
lines changed

e2e/ast-transformers/replace-resources/__tests__/bar.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,7 @@ test(
2828
const elementToFind = fixture.debugElement.nativeElement.querySelector('p');
2929
expect(elementToFind).toBeDefined();
3030
expect(window.getComputedStyle(elementToFind).color).toEqual('red');
31+
console.warn(window.getComputedStyle(elementToFind));
32+
expect(window.getComputedStyle(elementToFind).fontSize).toEqual('1.6rem');
3133
}),
3234
);

e2e/ast-transformers/replace-resources/jest-esm.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ module.exports = {
55
'ts-jest': {
66
useESM: true,
77
tsconfig: 'tsconfig-esm.json',
8-
stringifyContentPathRegex: '\\.html$',
8+
stringifyContentPathRegex: '\\.(html|scss)$',
99
},
1010
},
1111
setupFilesAfterEnv: ['<rootDir>/../../../setup-jest.js'],
1212
testEnvironment: 'jsdom',
1313
transform: {
14-
'^.+\\.(ts|js|html)$': '<rootDir>/../../../build/index.js',
14+
'^.+\\.(ts|js|html|scss)$': '<rootDir>/../../../build/index.js',
1515
},
1616
};

e2e/ast-transformers/replace-resources/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
"globals": {
44
"ts-jest": {
55
"tsconfig": "<rootDir>/../../tsconfig.json",
6-
"stringifyContentPathRegex": "\\.html$"
6+
"stringifyContentPathRegex": "\\.(html|scss)$"
77
}
88
},
99
"setupFilesAfterEnv": ["<rootDir>/../../../setup-jest.js"],
1010
"testEnvironment": "jsdom",
1111
"transform": {
12-
"^.+\\.(ts|js|html)$": "<rootDir>/../../../build/index.js"
12+
"^.+\\.(ts|js|html|scss)$": "<rootDir>/../../../build/index.js"
1313
}
1414
}
1515
}

e2e/snapshot-serializers/jest-esm.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = {
55
'ts-jest': {
66
useESM: true,
77
tsconfig: 'tsconfig-esm.json',
8-
stringifyContentPathRegex: '\\.html$',
8+
stringifyContentPathRegex: '\\.(html|scss)$',
99
},
1010
},
1111
setupFilesAfterEnv: ['<rootDir>/../../setup-jest.js'],
@@ -16,6 +16,6 @@ module.exports = {
1616
],
1717
testEnvironment: 'jsdom',
1818
transform: {
19-
'^.+\\.(ts|js|html)$': '<rootDir>/../../build/index.js',
19+
'^.+\\.(ts|js|html|scss)$': '<rootDir>/../../build/index.js',
2020
},
2121
};

e2e/snapshot-serializers/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"globals": {
44
"ts-jest": {
55
"tsconfig": "<rootDir>/../tsconfig.json",
6-
"stringifyContentPathRegex": "\\.html$"
6+
"stringifyContentPathRegex": "\\.(html|scss)$"
77
}
88
},
99
"setupFilesAfterEnv": ["<rootDir>/../../setup-jest.js"],
@@ -14,7 +14,7 @@
1414
],
1515
"testEnvironment": "jsdom",
1616
"transform": {
17-
"^.+\\.(ts|js|html)$": "<rootDir>/../../build/index.js"
17+
"^.+\\.(ts|js|html|scss)$": "<rootDir>/../../build/index.js"
1818
}
1919
}
2020
}

presets/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ const basePreset = {
44
globals: {
55
'ts-jest': {
66
tsconfig: '<rootDir>/tsconfig.spec.json',
7-
stringifyContentPathRegex: '\\.html$',
7+
stringifyContentPathRegex: '\\.(html|css|sass|scss|less|styl)$',
88
},
99
},
1010
testEnvironment: 'jsdom',
1111
transform: {
12-
'^.+\\.(ts|js|html)$': 'jest-preset-angular',
12+
'^.+\\.(ts|js|html|css|sass|scss|less|styl)$': 'jest-preset-angular',
1313
},
1414
moduleFileExtensions: ['ts', 'html', 'js', 'json'],
1515
moduleNameMapper: {

src/__tests__/__snapshots__/jest-preset.spec.ts.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ exports[`Jest presets should return the correct jest config 1`] = `
44
Object {
55
"globals": Object {
66
"ts-jest": Object {
7-
"stringifyContentPathRegex": "\\\\.html$",
7+
"stringifyContentPathRegex": "\\\\.(html|css|sass|scss|less|styl)$",
88
"tsconfig": "<rootDir>/tsconfig.spec.json",
99
},
1010
},
@@ -27,7 +27,7 @@ Object {
2727
],
2828
"testEnvironment": "jsdom",
2929
"transform": Object {
30-
"^.+\\\\.(ts|js|html)$": "jest-preset-angular",
30+
"^.+\\\\.(ts|js|html|css|sass|scss|less|styl)$": "jest-preset-angular",
3131
},
3232
}
3333
`;
@@ -39,7 +39,7 @@ Object {
3939
],
4040
"globals": Object {
4141
"ts-jest": Object {
42-
"stringifyContentPathRegex": "\\\\.html$",
42+
"stringifyContentPathRegex": "\\\\.(html|css|sass|scss|less|styl)$",
4343
"tsconfig": "<rootDir>/tsconfig.spec.json",
4444
"useESM": true,
4545
},
@@ -64,7 +64,7 @@ Object {
6464
],
6565
"testEnvironment": "jsdom",
6666
"transform": Object {
67-
"^.+\\\\.(ts|js|html)$": "jest-preset-angular",
67+
"^.+\\\\.(ts|js|html|css|sass|scss|less|styl)$": "jest-preset-angular",
6868
},
6969
"transformIgnorePatterns": Array [
7070
"node_modules/(?!tslib)",

src/__tests__/__snapshots__/presets.spec.ts.snap

Lines changed: 0 additions & 73 deletions
This file was deleted.

src/__tests__/__snapshots__/replace-resources.spec.ts.snap

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`should keep styles but not styleUrls, keep template and transform templateUrl to proper syntax for CommonJS/ESM: app.component.ts-with-esm-false 1`] = `
3+
exports[`should keep styles/template and transform styleUrls/templateUrl to proper syntax for CommonJS/ESM: app.component.ts-with-esm-false 1`] = `
44
"\\"use strict\\";
55
Object.defineProperty(exports, \\"__esModule\\", { value: true });
66
exports.AppComponent = void 0;
@@ -15,16 +15,18 @@ AppComponent = tslib_1.__decorate([
1515
core_1.Component({
1616
selector: 'app-root',
1717
template: require(\\"./app.component.html\\"),
18-
styles: [\\"\\\\n h1 {\\\\n font-size: 1.6rem;\\\\n }\\\\n \\"]
18+
styles: [\\"\\\\n h1 {\\\\n font-size: 1.6rem;\\\\n }\\\\n \\", require(\\"./app.component.scss\\"), require(\\"./foo.component.css\\")]
1919
})
2020
], AppComponent);
2121
exports.AppComponent = AppComponent;
2222
//# "
2323
`;
2424

25-
exports[`should keep styles but not styleUrls, keep template and transform templateUrl to proper syntax for CommonJS/ESM: app.component.ts-with-esm-true 1`] = `
25+
exports[`should keep styles/template and transform styleUrls/templateUrl to proper syntax for CommonJS/ESM: app.component.ts-with-esm-true 1`] = `
2626
"import { __decorate } from \\"tslib\\";
2727
import __NG_CLI_RESOURCE__0 from \\"./app.component.html\\";
28+
import __NG_CLI_RESOURCE__1 from \\"./app.component.scss\\";
29+
import __NG_CLI_RESOURCE__2 from \\"./foo.component.css\\";
2830
import { Component } from '@angular/core';
2931
let AppComponent = class AppComponent {
3032
constructor() {
@@ -35,14 +37,14 @@ AppComponent = __decorate([
3537
Component({
3638
selector: 'app-root',
3739
template: __NG_CLI_RESOURCE__0,
38-
styles: [\\"\\\\n h1 {\\\\n font-size: 1.6rem;\\\\n }\\\\n \\"]
40+
styles: [\\"\\\\n h1 {\\\\n font-size: 1.6rem;\\\\n }\\\\n \\", __NG_CLI_RESOURCE__1, __NG_CLI_RESOURCE__2]
3941
})
4042
], AppComponent);
4143
export { AppComponent };
4244
//# "
4345
`;
4446

45-
exports[`should keep styles but not styleUrls, keep template and transform templateUrl to proper syntax for CommonJS/ESM: foo.component.ts-with-esm-false 1`] = `
47+
exports[`should keep styles/template and transform styleUrls/templateUrl to proper syntax for CommonJS/ESM: foo.component.ts-with-esm-false 1`] = `
4648
"\\"use strict\\";
4749
Object.defineProperty(exports, \\"__esModule\\", { value: true });
4850
exports.FooComponent = void 0;
@@ -57,15 +59,17 @@ FooComponent = tslib_1.__decorate([
5759
core_1.Component({
5860
selector: 'app-root',
5961
template: \`<h1>Foo Bar</h1>\`,
60-
styles: [\\"\\\\n h1 {\\\\n font-size: 1.6rem;\\\\n }\\\\n \\"]
62+
styles: [\\"\\\\n h1 {\\\\n font-size: 1.6rem;\\\\n }\\\\n \\", require(\\"./app.component.scss\\"), require(\\"./foo.component.css\\")]
6163
})
6264
], FooComponent);
6365
exports.FooComponent = FooComponent;
6466
//# "
6567
`;
6668
67-
exports[`should keep styles but not styleUrls, keep template and transform templateUrl to proper syntax for CommonJS/ESM: foo.component.ts-with-esm-true 1`] = `
69+
exports[`should keep styles/template and transform styleUrls/templateUrl to proper syntax for CommonJS/ESM: foo.component.ts-with-esm-true 1`] = `
6870
"import { __decorate } from \\"tslib\\";
71+
import __NG_CLI_RESOURCE__0 from \\"./app.component.scss\\";
72+
import __NG_CLI_RESOURCE__1 from \\"./foo.component.css\\";
6973
import { Component } from '@angular/core';
7074
let FooComponent = class FooComponent {
7175
constructor() {
@@ -76,7 +80,7 @@ FooComponent = __decorate([
7680
Component({
7781
selector: 'app-root',
7882
template: \`<h1>Foo Bar</h1>\`,
79-
styles: [\\"\\\\n h1 {\\\\n font-size: 1.6rem;\\\\n }\\\\n \\"]
83+
styles: [\\"\\\\n h1 {\\\\n font-size: 1.6rem;\\\\n }\\\\n \\", __NG_CLI_RESOURCE__0, __NG_CLI_RESOURCE__1]
8084
})
8185
], FooComponent);
8286
export { FooComponent };

src/__tests__/presets.spec.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)