You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BREAKING CHANGE: add an alternative preset for babel and restructures
the whole repository to treat babel and ts-jest equally. Furthermore
`ts-jest` is not a dependency of the preset anymore.
The jest config and package.json of users will have to be adjusted, see
the CHANGELOG.md for migration information.
Closes#308
Copy file name to clipboardExpand all lines: CHANGELOG.md
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,11 @@
1
1
## Changelog (master)
2
2
3
+
#### Features
4
+
* (**BREAKING**): Add preset `babel` as transpilation alternative to `ts-jest` and remove `ts-jest` as dependency ([#317](https://github.com/thymikee/jest-preset-angular/pull/317)).
5
+
6
+
#### Migration Guide
7
+
* The preset reference in the jest config has to be updated from `"jest-preset-angular"` to `"jest-preset-angular/build/ts-jest"`. To use babel, replace `ts-jest` with `babel`. Furthermore, when using `ts-jest`, it has to be added as `devDependency` to the project, or `babel` packages alternatively (see README.md).
Copy file name to clipboardExpand all lines: README.md
+53-3Lines changed: 53 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,9 @@ This is a part of the article: [Testing Angular faster with Jest](https://www.xf
9
9
10
10
_Note: This preset does not suport AngularJS (1.x). If you want to set up Jest with AngularJS, please see [this blog post](https://medium.com/aya-experience/testing-an-angularjs-app-with-jest-3029a613251)._
11
11
12
+
This package actually contains two presets, one for `ts-jest`, which uses the official TypeScript compiler internally, and one for `babel`, which strips away the type annotations and simply transforms the JavaScript. If you are not sure, try to use `ts-jest`, to also type-check your test files.
13
+
14
+
12
15
## Installation
13
16
14
17
```bash
@@ -19,6 +22,26 @@ npm install -D jest jest-preset-angular @types/jest
19
22
20
23
This will install `jest`, `@types/jest`, `ts-jest` as dependencies needed to run with Angular projects.
21
24
25
+
Additionally you need `ts-jest` or `babel` packages.
26
+
27
+
### ts-jest
28
+
```bash
29
+
yarn add -D ts-jest
30
+
#or
31
+
npm install -D ts-jest
32
+
```
33
+
34
+
`ts-jest` uses the TypeScript compiler to generate JavaScript.
`babel` uses the babel compiler to generate JavaScript, without type-checking your test files before doing so. You can still do type-checking using `tsc --noEmit`. For additional TypeScript-supported language features you might have to install even more babel packages. Note that `babel` also can differ slightly from `tsc`, e. g. in compiling a class to a function.
44
+
22
45
## Usage
23
46
24
47
In `src` directory create `setupJest.ts` file with following contents:
@@ -35,17 +58,42 @@ _Note: feel free to copy the [`jestGlobalMocks.ts`](https://github.com/thymikee/
By Angular CLI defaults you'll have a `src/test.ts` file which will be picked up by jest. To circumvent this you can either rename it to `src/karmaTest.ts` or hide it from jest by adding `<rootDir>/src/test.ts` to jest `testPathIgnorePatterns` option.
Note that the [`babel` configuration](https://github.com/thymikee/jest-preset-angular/blob/master/src/babel/jest-preset.js) looks different.
130
+
81
131
### Brief explanation of config
82
132
83
133
-`<rootDir>` is a special syntax for root of your project (here by default it's project's root /)
84
134
- we're using some `"globals"` to pass information about where our tsconfig.json file is that we'd like to be able to transform HTML files through ts-jest
85
-
-`"transform"` – run every TS, JS, or HTML file through so called _preprocessor_ (we'll get there); this lets Jest understand non-JS syntax
135
+
-`"transform"` – run every TS, JS, or HTML file through so called _preprocessor_, in our case just `ts-jest` or `babel-jest`; this lets Jest understand non-JS syntax
86
136
-`"testMatch"` – we want to run Jest on files that matches this glob
87
137
-`"moduleFileExtensions"` – our modules are TypeScript and JavaScript files
88
138
-`"moduleNameMapper"` – if you're using absolute imports here's how to tell Jest where to look for them; uses regex
0 commit comments