Skip to content

Commit 7c72e93

Browse files
wthoahnpnl
authored andcommitted
feat: restructure project with src/ and build/ (#307)
To keep source files in a single place, most js files are now located in the src folder as well. The TypeScript compiler transpiles the ts files and copies the js files to the build folder.
1 parent 871e4d4 commit 7c72e93

26 files changed

+44
-31
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules
2+
/build/
23
InlineFilesTransformer.js
34
StripStylesTransformer.js
45
TransformUtils.js

.npmignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
/example
2-
/__tests__
32
/src
43
circle.yml

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
* (**BREAKING**): Refine ast-transformer behavior: only transform `styles`-assignments inside @Component ([#261](https://github.com/thymikee/jest-preset-angular/pull/261)) and TypeScript v2.9 `createStringLiteral` is polyfilled if an older version is used ([#272](https://github.com/thymikee/jest-preset-angular/issues/272)).
44

5+
* (**BREAKING**): Restructure project with `src` and `build` folder ([#307](https://github.com/thymikee/jest-preset-angular/pull/307)).
6+
57
#### Migration Guide
6-
* If the `astTransformers` are referenced in a custom `jest` config, `[ 'jest-preset-angular/InlineFilesTransformer', 'jest-preset-angular/StripStylesTransformer']` have to be set instead.
8+
* If the `astTransformers` are referenced in a custom `jest` config, `[ 'jest-preset-angular/build/InlineFilesTransformer', 'jest-preset-angular/build/StripStylesTransformer']` have to be set instead.
9+
* Serializers, transformers and `setupJest` have to be referenced from the `jest-preset-angular/build/`-folder in a custom config. Existing references have to be aligned.
710

811
### v7.1.0
912

README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ module.exports = {
5353
'ts-jest': {
5454
tsConfig: '<rootDir>/src/tsconfig.spec.json',
5555
stringifyContentPathRegex: '\\.html$',
56-
astTransformers: [require.resolve('./InlineHtmlStripStylesTransformer')],
56+
astTransformers: [
57+
require.resolve('./build/InlineFilesTransformer'),
58+
require.resolve('./build/StripStylesTransformer')
59+
],
5760
},
5861
},
5962
transform: {
@@ -69,8 +72,8 @@ module.exports = {
6972
},
7073
transformIgnorePatterns: ['node_modules/(?!@ngrx)'],
7174
snapshotSerializers: [
72-
'jest-preset-angular/AngularSnapshotSerializer.js',
73-
'jest-preset-angular/HTMLCommentSerializer.js',
75+
'jest-preset-angular/build/AngularSnapshotSerializer.js',
76+
'jest-preset-angular/build/HTMLCommentSerializer.js',
7477
],
7578
};
7679
```
@@ -305,14 +308,17 @@ Override `globals` object in Jest config:
305308
"ts-jest": {
306309
"tsConfig": "<rootDir>/src/tsconfig.custom.json",
307310
"stringifyContentPathRegex": "\\.html$",
308-
"astTransformers": ["jest-preset-angular/InlineHtmlStripStylesTransformer"],
311+
"astTransformers": [
312+
"jest-preset-angular/build/InlineFilesTransformer",
313+
"jest-preset-angular/build/StripStylesTransformer"
314+
],
309315
}
310316
}
311317
}
312318
}
313319
```
314320

315-
If you choose to overide `globals` in order to point at a specific tsconfig, you will need to add `"astTransformers": ["jest-preset-angular/InlineHtmlStripStylesTransformer"]` to the `globals.ts-jest` section too, otherwise you will get parse errors on any html templates.
321+
If you choose to overide `globals` in order to point at a specific tsconfig, you will need to add the `astTransformers` to the `globals.ts-jest` section too, otherwise you will get parse errors on any html templates.
316322

317323
### Unexpected token [import|export|other]
318324

@@ -411,7 +417,7 @@ module.exports = function(api) {
411417
{
412418
"jest": {
413419
"transform": {
414-
"^.+\\.(ts|html)$": "<rootDir>/node_modules/jest-preset-angular/preprocessor.js",
420+
"^.+\\.(ts|html)$": "ts-jest",
415421
"^.+\\.js$": "babel-jest"
416422
},
417423
}

example/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@
4545
"jest": {
4646
"preset": "jest-preset-angular",
4747
"snapshotSerializers": [
48-
"jest-preset-angular/AngularNoNgAttributesSnapshotSerializer.js",
49-
"jest-preset-angular/AngularSnapshotSerializer.js",
50-
"jest-preset-angular/HTMLCommentSerializer.js"
48+
"jest-preset-angular/build/AngularNoNgAttributesSnapshotSerializer.js",
49+
"jest-preset-angular/build/AngularSnapshotSerializer.js",
50+
"jest-preset-angular/build/HTMLCommentSerializer.js"
5151
],
5252
"moduleNameMapper": {
5353
"\\.(jpg|jpeg|png)$": "<rootDir>/__mocks__/image.js",

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = require('./setupJest.js');
1+
module.exports = require('./build/setupJest.js');

jest-preset.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ module.exports = {
44
tsConfig: '<rootDir>/src/tsconfig.spec.json',
55
stringifyContentPathRegex: '\\.html$',
66
astTransformers: [
7-
require.resolve('./InlineFilesTransformer'),
8-
require.resolve('./StripStylesTransformer'),
7+
require.resolve('./build/InlineFilesTransformer'),
8+
require.resolve('./build/StripStylesTransformer'),
99
],
1010
},
1111
},
@@ -22,8 +22,8 @@ module.exports = {
2222
},
2323
transformIgnorePatterns: ['node_modules/(?!@ngrx)'],
2424
snapshotSerializers: [
25-
// 'jest-preset-angular/AngularNoNgAttributesSnapshotSerializer.js',
26-
'jest-preset-angular/AngularSnapshotSerializer.js',
27-
'jest-preset-angular/HTMLCommentSerializer.js',
25+
// 'jest-preset-angular/build/AngularNoNgAttributesSnapshotSerializer.js',
26+
'jest-preset-angular/build/AngularSnapshotSerializer.js',
27+
'jest-preset-angular/build/HTMLCommentSerializer.js',
2828
],
2929
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"tsConfig": "<rootDir>/tsconfig.spec.json"
3232
}
3333
},
34-
"rootDir": "__tests__"
34+
"rootDir": "src/__tests__"
3535
},
3636
"scripts": {
3737
"build": "tsc",
File renamed without changes.

0 commit comments

Comments
 (0)