Skip to content

Commit

Permalink
refactor(transformers): move transformers to transformers dir (#455)
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
One is using all `jest-preset-angular` transformers should change jest config to have:
```
// jest.config.js
const customTransformers = require('./build/transformers');

module.exports = {
     // [...]
     globals: {
        'ts-jest': {
            tsConfig: '<rootDir>/tsconfig.spec.json',
            stringifyContentPathRegex: '\\.html$',
            astTransformers: {
               before: customTransformers,
            },
         },
     },
}
```

One is using one of `jest-preset-angular` transformers should change jest config to have:
```
// jest.config.js
module.exports = {
     // [...]
     globals: {
        'ts-jest': {
            tsConfig: '<rootDir>/tsconfig.spec.json',
            stringifyContentPathRegex: '\\.html$',
            astTransformers: {
               before: [
                  'jest-preset-angular/build/transformers/inline-files'
               ],
            },
         },
     },
}
```
or
```
// package.json
{
     "jest" {
         // [...]
         "globals": {
              "ts-jest": {
                   "tsConfig": "<rootDir>/tsconfig.spec.json",
                   "stringifyContentPathRegex": "\\.html$",
                   "astTransformers": {
                        "before": [
                            "jest-preset-angular/build/transformers/inline-files"
                        ]
                   }
              }
         }
     }
}
```
  • Loading branch information
ahnpnl committed Sep 1, 2020
1 parent 00437b2 commit 5cfe109
Show file tree
Hide file tree
Showing 11 changed files with 9 additions and 20 deletions.
@@ -1,14 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`inlining template and stripping styles should not transform styles outside decorator 1`] = `
"var assignmentsToNotBeTransformed = {
styles: [{
color: 'red'
}]
};
"
`;

exports[`inlining template and stripping styles should not strip styleUrls assignment 1`] = `
"\\"use strict\\";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
Expand Down
Expand Up @@ -5,7 +5,7 @@
*/

import * as tsc from 'typescript';
import * as transformer from '../InlineFilesTransformer';
import * as transformer from '../transformers/inline-files';

const CODE_WITH_TEMPLATE_URL = `
import { Component } from '@angular/core';
Expand Down
Expand Up @@ -5,7 +5,7 @@
*/

import * as tsc from 'typescript';
import * as transformer from '../StripStylesTransformer';
import * as transformer from '../transformers/strip-styles';

const CODE_WITH_STYLES_AND_OTHER_ASSIGNMENTS = `
import { Component } from '@angular/core';
Expand Down
6 changes: 2 additions & 4 deletions src/jest-preset.js
@@ -1,15 +1,13 @@
const snapshotSerializers = require('./build/serializers');
const customTransformers = require('./build/transformers');

module.exports = {
globals: {
'ts-jest': {
tsConfig: '<rootDir>/tsconfig.spec.json',
stringifyContentPathRegex: '\\.html$',
astTransformers: {
before: [
'jest-preset-angular/build/InlineFilesTransformer',
'jest-preset-angular/build/StripStylesTransformer',
],
before: customTransformers,
},
},
},
Expand Down
1 change: 1 addition & 0 deletions src/transformers/index.ts
@@ -0,0 +1 @@
export = ['jest-preset-angular/build/transformers/inline-files', 'jest-preset-angular/build/transformers/strip-styles'];
Expand Up @@ -32,7 +32,7 @@ import type {
PropertyAssignment,
LiteralLikeNode,
} from 'typescript';
import { getCreateStringLiteral, ConfigSet } from './TransformUtils';
import { getCreateStringLiteral, ConfigSet } from './transform-utils';

// replace original ts-jest ConfigSet with this simple interface, as it would require
// jest-preset-angular to add several babel devDependencies to get the other types
Expand Down
Expand Up @@ -34,7 +34,7 @@ import type {
CallExpression,
ObjectLiteralExpression,
} from 'typescript';
import type { ConfigSet } from './TransformUtils';
import type { ConfigSet } from './transform-utils';

/** Angular component decorator Styles property name */
const STYLES = 'styles';
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tsconfig.json
Expand Up @@ -13,6 +13,6 @@
"target": "es2015",
"module": "CommonJS",
"lib": ["esnext", "dom"],
"types": ["node"]
"types": ["node", "jest"]
}
}
3 changes: 1 addition & 2 deletions tsconfig.spec.json
@@ -1,8 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"target": "ES5",
"types": ["jest", "node"]
"target": "ES5"
},
"include": [] // boost test's speed trick
}

0 comments on commit 5cfe109

Please sign in to comment.