-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(babel): alternative setup babel/TS (#311)
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
- Loading branch information
Showing
32 changed files
with
1,987 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
] | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const defaultTestMode = 'ts-jest'; | ||
const envTestModeKey = 'JPA_TEST_MODE'; | ||
|
||
module.exports = { | ||
getTestMode() { | ||
if (process.env && envTestModeKey in process.env && typeof process.env[envTestModeKey] === 'string') { | ||
return process.env[envTestModeKey]; | ||
} | ||
return defaultTestMode; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 0 additions & 15 deletions
15
example/src/app/calc/__snapshots__/calc.component.spec.ts.snap
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
import 'jest-preset-angular'; | ||
import './jestGlobalMocks'; | ||
|
||
// for example app testing only | ||
import { getTestMode } from '../get-test-mode'; | ||
global['JpaTestMode'] = getTestMode() |
Oops, something went wrong.