Skip to content

Commit

Permalink
fix(transformers): revert #903 as some file extensions are not proces…
Browse files Browse the repository at this point in the history
…sed with their original content
  • Loading branch information
ahnpnl committed Apr 28, 2021
1 parent a14ab84 commit aebc186
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ test(
const elementToFind = fixture.debugElement.nativeElement.querySelector('p');
expect(elementToFind).toBeDefined();
expect(window.getComputedStyle(elementToFind).color).toEqual('red');
expect(window.getComputedStyle(elementToFind).fontSize).toEqual('1.6rem');
expect(window.getComputedStyle(elementToFind).fontSize).toEqual('');
}),
);
4 changes: 2 additions & 2 deletions e2e/ast-transformers/replace-resources/jest-esm.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ module.exports = {
'ts-jest': {
useESM: true,
tsconfig: 'tsconfig-esm.json',
stringifyContentPathRegex: '\\.(html|scss)$',
stringifyContentPathRegex: '\\.html$',
},
},
setupFilesAfterEnv: ['<rootDir>/../../../setup-jest.js'],
testEnvironment: 'jsdom',
transform: {
'^.+\\.(ts|js|html|scss)$': '<rootDir>/../../../build/index.js',
'^.+\\.(ts|js|html)$': '<rootDir>/../../../build/index.js',
},
};
4 changes: 2 additions & 2 deletions e2e/ast-transformers/replace-resources/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"globals": {
"ts-jest": {
"tsconfig": "<rootDir>/../../tsconfig.json",
"stringifyContentPathRegex": "\\.(html|scss)$"
"stringifyContentPathRegex": "\\.html$"
}
},
"setupFilesAfterEnv": ["<rootDir>/../../../setup-jest.js"],
"testEnvironment": "jsdom",
"transform": {
"^.+\\.(ts|js|html|scss)$": "<rootDir>/../../../build/index.js"
"^.+\\.(ts|js|html)$": "<rootDir>/../../../build/index.js"
}
}
}
4 changes: 2 additions & 2 deletions e2e/snapshot-serializers/jest-esm.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
'ts-jest': {
useESM: true,
tsconfig: 'tsconfig-esm.json',
stringifyContentPathRegex: '\\.(html|scss)$',
stringifyContentPathRegex: '\\.html$',
},
},
setupFilesAfterEnv: ['<rootDir>/../../setup-jest.js'],
Expand All @@ -16,6 +16,6 @@ module.exports = {
],
testEnvironment: 'jsdom',
transform: {
'^.+\\.(ts|js|html|scss)$': '<rootDir>/../../build/index.js',
'^.+\\.(ts|js|html)$': '<rootDir>/../../build/index.js',
},
};
4 changes: 2 additions & 2 deletions e2e/snapshot-serializers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"globals": {
"ts-jest": {
"tsconfig": "<rootDir>/../tsconfig.json",
"stringifyContentPathRegex": "\\.(html|scss)$"
"stringifyContentPathRegex": "\\.html$"
}
},
"setupFilesAfterEnv": ["<rootDir>/../../setup-jest.js"],
Expand All @@ -14,7 +14,7 @@
],
"testEnvironment": "jsdom",
"transform": {
"^.+\\.(ts|js|html|scss)$": "<rootDir>/../../build/index.js"
"^.+\\.(ts|js|html)$": "<rootDir>/../../build/index.js"
}
}
}
4 changes: 2 additions & 2 deletions presets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ const basePreset = {
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
stringifyContentPathRegex: '\\.(html|css|sass|scss|less|styl)$',
stringifyContentPathRegex: '\\.html$',
},
},
testEnvironment: 'jsdom',
transform: {
'^.+\\.(ts|js|html|css|sass|scss|less|styl)$': 'jest-preset-angular',
'^.+\\.(ts|js|html)$': 'jest-preset-angular',
},
moduleFileExtensions: ['ts', 'html', 'js', 'json'],
moduleNameMapper: {
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/__snapshots__/jest-preset.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`Jest presets should return the correct jest config 1`] = `
Object {
"globals": Object {
"ts-jest": Object {
"stringifyContentPathRegex": "\\\\.(html|css|sass|scss|less|styl)$",
"stringifyContentPathRegex": "\\\\.html$",
"tsconfig": "<rootDir>/tsconfig.spec.json",
},
},
Expand All @@ -27,7 +27,7 @@ Object {
],
"testEnvironment": "jsdom",
"transform": Object {
"^.+\\\\.(ts|js|html|css|sass|scss|less|styl)$": "jest-preset-angular",
"^.+\\\\.(ts|js|html)$": "jest-preset-angular",
},
}
`;
Expand All @@ -39,7 +39,7 @@ Object {
],
"globals": Object {
"ts-jest": Object {
"stringifyContentPathRegex": "\\\\.(html|css|sass|scss|less|styl)$",
"stringifyContentPathRegex": "\\\\.html$",
"tsconfig": "<rootDir>/tsconfig.spec.json",
"useESM": true,
},
Expand All @@ -64,7 +64,7 @@ Object {
],
"testEnvironment": "jsdom",
"transform": Object {
"^.+\\\\.(ts|js|html|css|sass|scss|less|styl)$": "jest-preset-angular",
"^.+\\\\.(ts|js|html)$": "jest-preset-angular",
},
"transformIgnorePatterns": Array [
"node_modules/(?!tslib)",
Expand Down
12 changes: 4 additions & 8 deletions src/__tests__/__snapshots__/replace-resources.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ AppComponent = tslib_1.__decorate([
core_1.Component({
selector: 'app-root',
template: require(\\"./app.component.html\\"),
styles: [\\"\\\\n h1 {\\\\n font-size: 1.6rem;\\\\n }\\\\n \\", require(\\"./app.component.scss\\"), require(\\"./foo.component.css\\")]
styles: [\\"\\\\n h1 {\\\\n font-size: 1.6rem;\\\\n }\\\\n \\"]
})
], AppComponent);
exports.AppComponent = AppComponent;
Expand All @@ -25,8 +25,6 @@ exports.AppComponent = AppComponent;
exports[`should keep styles/template and transform styleUrls/templateUrl to proper syntax for CommonJS/ESM: app.component.ts-with-esm-true 1`] = `
"import { __decorate } from \\"tslib\\";
import __NG_CLI_RESOURCE__0 from \\"./app.component.html\\";
import __NG_CLI_RESOURCE__1 from \\"./app.component.scss\\";
import __NG_CLI_RESOURCE__2 from \\"./foo.component.css\\";
import { Component } from '@angular/core';
let AppComponent = class AppComponent {
constructor() {
Expand All @@ -37,7 +35,7 @@ AppComponent = __decorate([
Component({
selector: 'app-root',
template: __NG_CLI_RESOURCE__0,
styles: [\\"\\\\n h1 {\\\\n font-size: 1.6rem;\\\\n }\\\\n \\", __NG_CLI_RESOURCE__1, __NG_CLI_RESOURCE__2]
styles: [\\"\\\\n h1 {\\\\n font-size: 1.6rem;\\\\n }\\\\n \\"]
})
], AppComponent);
export { AppComponent };
Expand All @@ -59,7 +57,7 @@ FooComponent = tslib_1.__decorate([
core_1.Component({
selector: 'app-root',
template: \`<h1>Foo Bar</h1>\`,
styles: [\\"\\\\n h1 {\\\\n font-size: 1.6rem;\\\\n }\\\\n \\", require(\\"./app.component.scss\\"), require(\\"./foo.component.css\\")]
styles: [\\"\\\\n h1 {\\\\n font-size: 1.6rem;\\\\n }\\\\n \\"]
})
], FooComponent);
exports.FooComponent = FooComponent;
Expand All @@ -68,8 +66,6 @@ exports.FooComponent = FooComponent;
exports[`should keep styles/template and transform styleUrls/templateUrl to proper syntax for CommonJS/ESM: foo.component.ts-with-esm-true 1`] = `
"import { __decorate } from \\"tslib\\";
import __NG_CLI_RESOURCE__0 from \\"./app.component.scss\\";
import __NG_CLI_RESOURCE__1 from \\"./foo.component.css\\";
import { Component } from '@angular/core';
let FooComponent = class FooComponent {
constructor() {
Expand All @@ -80,7 +76,7 @@ FooComponent = __decorate([
Component({
selector: 'app-root',
template: \`<h1>Foo Bar</h1>\`,
styles: [\\"\\\\n h1 {\\\\n font-size: 1.6rem;\\\\n }\\\\n \\", __NG_CLI_RESOURCE__0, __NG_CLI_RESOURCE__1]
styles: [\\"\\\\n h1 {\\\\n font-size: 1.6rem;\\\\n }\\\\n \\"]
})
], FooComponent);
export { FooComponent };
Expand Down
7 changes: 6 additions & 1 deletion src/transformers/replace-resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ function visitComponentMetadata(
: ts.updatePropertyAssignment(node, ts.createIdentifier(TEMPLATE), importName);

case STYLES:
case STYLE_URLS:
if (!ts.isArrayLiteralExpression(node.initializer)) {
return node;
}
Expand Down Expand Up @@ -240,6 +239,12 @@ function visitComponentMetadata(
styleReplacements.push(...styles);
}

return undefined;
case STYLE_URLS:
if (!ts.isArrayLiteralExpression(node.initializer)) {
return node;
}

return undefined;
default:
return node;
Expand Down
5 changes: 2 additions & 3 deletions website/docs/guides/testing-css-styles.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ id: testing-css-styles
title: Testing CSS Styles
---

Starting from **v9.0.0**, `jest-preset-angular` supports testing CSS styles. The supported style extensions following
Angular support, which are: `css`, `sass`, `scss`, `less` and `styl`. This is provided default by `jest-preset-angular`.
Starting from **v9.0.0**, `jest-preset-angular` supports testing CSS styles for `styles` property in `@Component` metadata. This is provided default by `jest-preset-angular`.

One now can use [window.getComputedStyle](https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle)
to check styling of DOM elements. The styles which are returned by `window.getComputedStyle` come from styling files.
to check styling of DOM elements. The styles which are returned by `window.getComputedStyle` come from `styles` property.

## Example

Expand Down

0 comments on commit aebc186

Please sign in to comment.