Skip to content

Commit

Permalink
feat(babel): alternative setup babel/typescript
Browse files Browse the repository at this point in the history
BREAKING CHANGE: add an alternative preset for babel and restructures
the whole repository to treat babel and ts-jest equally.

The jest config of users will have to be adjusted, see the CHANGELOG.md
for migration information.
  • Loading branch information
wtho committed Oct 22, 2019
1 parent f925564 commit d0f4ce0
Show file tree
Hide file tree
Showing 26 changed files with 1,785 additions and 71 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Changelog (master)

#### Features
* (**BREAKING?**): Add preset `babel` as transpilation alternative to `ts-jest` ([#317](https://github.com/thymikee/jest-preset-angular/pull/317)).

### v8.0.0

#### Features
Expand Down
12 changes: 12 additions & 0 deletions example/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { babelAngularConfig } = require('jest-preset-angular/build/babel/babel.config')
module.exports = api => {
api.cache(false)
return {
presets: babelAngularConfig.presets,
plugins: [
...babelAngularConfig.plugins,
// your plugins
]
}
}

3 changes: 2 additions & 1 deletion example/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
preset: "jest-preset-angular",
preset: "jest-preset-angular/build/ts-jest",
// preset: "jest-preset-angular/build/babel",
snapshotSerializers: [
"jest-preset-angular/build/AngularNoNgAttributesSnapshotSerializer.js",
"jest-preset-angular/build/AngularSnapshotSerializer.js",
Expand Down
9 changes: 9 additions & 0 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,19 @@
"@angular/cli": "~8.3.4",
"@angular/compiler-cli": "~8.2.5",
"@angular/language-service": "~8.2.5",
"@babel/core": "^7.6.2",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/plugin-proposal-decorators": "^7.6.0",
"@babel/preset-env": "^7.6.2",
"@babel/preset-typescript": "^7.6.0",
"@types/jest": "^24.0.0",
"@types/node": "^11.0.0",
"babel-jest": "^24.9.0",
"babel-plugin-const-enum": "^0.0.2",
"babel-plugin-transform-typescript-metadata": "^0.2.2",
"jest": "^24.0.0",
"jest-preset-angular": "file:../",
"ts-jest": "^24.1.0",
"ts-node": "^8.0.3",
"typescript": "~3.5.3"
}
Expand Down
31 changes: 31 additions & 0 deletions example/src/app/hero-category/hero-category.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Injectable } from "@angular/core";
import { HeroCategory, HeroColor } from "./hero-properties";

@Injectable({
providedIn: "root"
})
export class HeroCategoryService {
getCategoryForHero(heroName: string): HeroCategory {
switch (heroName) {
case "Joker":
return HeroCategory.Evil;
case "Batman":
return HeroCategory.Good;
default:
return HeroCategory.Neutral;
}
}

getColorForHero(heroName: string): HeroColor {
switch (heroName) {
case "Joker":
return HeroColor.Purple;
case "Batman":
return HeroColor.Black;
case "Catwoman":
return HeroColor.Black;
default:
return HeroColor.Transparent;
}
}
}
27 changes: 27 additions & 0 deletions example/src/app/hero-category/hero-category.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { async } from "@angular/core/testing";

import { HeroCategoryService } from "./hero-category.service";
import { HeroCategory, HeroColor } from './hero-properties';

describe("HeroCategoryService", () => {
let service: HeroCategoryService;

beforeEach(() => (service = new HeroCategoryService()));

it("should create", () => {
expect(service).toBeTruthy();
});

it("should return the right category for heroes", () => {
expect(service.getCategoryForHero("Batman")).toEqual(HeroCategory.Good);
expect(service.getCategoryForHero("Joker")).toEqual(HeroCategory.Evil);
expect(service.getCategoryForHero("Catwoman")).toEqual(HeroCategory.Neutral);
});

it("should return the right color for heroes", () => {
expect(service.getColorForHero("Batman")).toEqual(HeroColor.Black);
expect(service.getColorForHero("Joker")).toEqual(HeroColor.Purple);
expect(service.getColorForHero("The Penguin")).toEqual(HeroColor.Transparent);
});

});
12 changes: 12 additions & 0 deletions example/src/app/hero-category/hero-properties.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

export enum HeroCategory {
Evil,
Good,
Neutral
}

export const enum HeroColor {
Black = "#000000",
Purple = "#551A8B",
Transparent = "#00000000"
}
Loading

0 comments on commit d0f4ce0

Please sign in to comment.