mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 04:12:13 +00:00
Merge pull request #272 from Gnuk/add-jest-to-typescript
Add Jest to TypeScript (and update dependencies)
This commit is contained in:
commit
128efdfc14
12
TypeScript/.editorconfig
Normal file
12
TypeScript/.editorconfig
Normal file
@ -0,0 +1,12 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
@ -3,8 +3,9 @@
|
||||
module.exports = {
|
||||
require: [
|
||||
"ts-node/register",
|
||||
"tsconfig-paths/register",
|
||||
"source-map-support/register"
|
||||
],
|
||||
recursive: true,
|
||||
spec: "test/*.spec.ts"
|
||||
}
|
||||
spec: "test/mocha/*.spec.ts"
|
||||
}
|
||||
|
||||
17
TypeScript/.nycrc.js
Normal file
17
TypeScript/.nycrc.js
Normal file
@ -0,0 +1,17 @@
|
||||
module.exports = {
|
||||
extension: [
|
||||
".ts"
|
||||
],
|
||||
exclude: [
|
||||
"**/*.d.ts",
|
||||
"test/**",
|
||||
"/*.js"
|
||||
],
|
||||
require: [
|
||||
"ts-node/register"
|
||||
],
|
||||
reporter: [
|
||||
"html",
|
||||
"text"
|
||||
]
|
||||
}
|
||||
33
TypeScript/README.md
Normal file
33
TypeScript/README.md
Normal file
@ -0,0 +1,33 @@
|
||||
# Gilded Rose
|
||||
|
||||
This is the Gilded Rose kata in TypeScript.
|
||||
|
||||
## Getting started
|
||||
|
||||
Install dependencies
|
||||
|
||||
```sh
|
||||
npm install
|
||||
```
|
||||
|
||||
## Running tests
|
||||
|
||||
To run all tests
|
||||
|
||||
### Jest way
|
||||
|
||||
```sh
|
||||
npm run test:jest
|
||||
```
|
||||
|
||||
To run all tests in watch mode
|
||||
|
||||
```sh
|
||||
npm run test:jest:watch
|
||||
```
|
||||
|
||||
### Mocha way
|
||||
|
||||
```sh
|
||||
npm run test:mocha
|
||||
```
|
||||
@ -1,69 +1,69 @@
|
||||
export class Item {
|
||||
name: string;
|
||||
sellIn: number;
|
||||
quality: number;
|
||||
name: string;
|
||||
sellIn: number;
|
||||
quality: number;
|
||||
|
||||
constructor(name, sellIn, quality) {
|
||||
this.name = name;
|
||||
this.sellIn = sellIn;
|
||||
this.quality = quality;
|
||||
}
|
||||
constructor(name, sellIn, quality) {
|
||||
this.name = name;
|
||||
this.sellIn = sellIn;
|
||||
this.quality = quality;
|
||||
}
|
||||
}
|
||||
|
||||
export class GildedRose {
|
||||
items: Array<Item>;
|
||||
items: Array<Item>;
|
||||
|
||||
constructor(items = [] as Array<Item>) {
|
||||
this.items = items;
|
||||
}
|
||||
constructor(items = [] as Array<Item>) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
updateQuality() {
|
||||
for (let i = 0; i < this.items.length; i++) {
|
||||
if (this.items[i].name != 'Aged Brie' && this.items[i].name != 'Backstage passes to a TAFKAL80ETC concert') {
|
||||
if (this.items[i].quality > 0) {
|
||||
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
|
||||
this.items[i].quality = this.items[i].quality - 1
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (this.items[i].quality < 50) {
|
||||
this.items[i].quality = this.items[i].quality + 1
|
||||
if (this.items[i].name == 'Backstage passes to a TAFKAL80ETC concert') {
|
||||
if (this.items[i].sellIn < 11) {
|
||||
if (this.items[i].quality < 50) {
|
||||
this.items[i].quality = this.items[i].quality + 1
|
||||
}
|
||||
}
|
||||
if (this.items[i].sellIn < 6) {
|
||||
if (this.items[i].quality < 50) {
|
||||
this.items[i].quality = this.items[i].quality + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
|
||||
this.items[i].sellIn = this.items[i].sellIn - 1;
|
||||
}
|
||||
if (this.items[i].sellIn < 0) {
|
||||
if (this.items[i].name != 'Aged Brie') {
|
||||
if (this.items[i].name != 'Backstage passes to a TAFKAL80ETC concert') {
|
||||
if (this.items[i].quality > 0) {
|
||||
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
|
||||
this.items[i].quality = this.items[i].quality - 1
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.items[i].quality = this.items[i].quality - this.items[i].quality
|
||||
}
|
||||
} else {
|
||||
if (this.items[i].quality < 50) {
|
||||
this.items[i].quality = this.items[i].quality + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
updateQuality() {
|
||||
for (let i = 0; i < this.items.length; i++) {
|
||||
if (this.items[i].name != 'Aged Brie' && this.items[i].name != 'Backstage passes to a TAFKAL80ETC concert') {
|
||||
if (this.items[i].quality > 0) {
|
||||
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
|
||||
this.items[i].quality = this.items[i].quality - 1
|
||||
}
|
||||
}
|
||||
|
||||
return this.items;
|
||||
} else {
|
||||
if (this.items[i].quality < 50) {
|
||||
this.items[i].quality = this.items[i].quality + 1
|
||||
if (this.items[i].name == 'Backstage passes to a TAFKAL80ETC concert') {
|
||||
if (this.items[i].sellIn < 11) {
|
||||
if (this.items[i].quality < 50) {
|
||||
this.items[i].quality = this.items[i].quality + 1
|
||||
}
|
||||
}
|
||||
if (this.items[i].sellIn < 6) {
|
||||
if (this.items[i].quality < 50) {
|
||||
this.items[i].quality = this.items[i].quality + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
|
||||
this.items[i].sellIn = this.items[i].sellIn - 1;
|
||||
}
|
||||
if (this.items[i].sellIn < 0) {
|
||||
if (this.items[i].name != 'Aged Brie') {
|
||||
if (this.items[i].name != 'Backstage passes to a TAFKAL80ETC concert') {
|
||||
if (this.items[i].quality > 0) {
|
||||
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
|
||||
this.items[i].quality = this.items[i].quality - 1
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.items[i].quality = this.items[i].quality - this.items[i].quality
|
||||
}
|
||||
} else {
|
||||
if (this.items[i].quality < 50) {
|
||||
this.items[i].quality = this.items[i].quality + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.items;
|
||||
}
|
||||
}
|
||||
|
||||
13
TypeScript/jest.config.ts
Normal file
13
TypeScript/jest.config.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { pathsToModuleNameMapper } from "ts-jest/utils";
|
||||
const { compilerOptions } = require("./tsconfig");
|
||||
|
||||
export default {
|
||||
roots: ['<rootDir>/app', '<rootDir>/test/jest'],
|
||||
collectCoverage: true,
|
||||
coverageDirectory: 'coverage',
|
||||
coverageProvider: 'v8',
|
||||
transform: {
|
||||
'^.+\\.tsx?$': 'ts-jest',
|
||||
},
|
||||
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/' } ),
|
||||
};
|
||||
9379
TypeScript/package-lock.json
generated
Normal file
9379
TypeScript/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -6,36 +6,26 @@
|
||||
"precompile": "rimraf app/**/*.js test/**/*.js",
|
||||
"compile": "tsc",
|
||||
"pretest": "rimraf app/**/*.js test/**/*.js",
|
||||
"test": "nyc mocha"
|
||||
"test:jest": "jest",
|
||||
"test:jest:watch": "jest --watchAll",
|
||||
"test:mocha": "nyc mocha"
|
||||
},
|
||||
"license": "MIT",
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"@types/chai": "~3.5.2",
|
||||
"@types/mocha": "~2.2.41",
|
||||
"@types/node": "~7.0.18",
|
||||
"chai": "~4.2.0",
|
||||
"mocha": "~8.2.1",
|
||||
"@types/chai": "^4.2.22",
|
||||
"@types/jest": "^27.0.2",
|
||||
"@types/mocha": "^9.0.0",
|
||||
"@types/node": "^16.11.7",
|
||||
"chai": "^4.3.4",
|
||||
"jest": "^27.3.1",
|
||||
"mocha": "^9.1.3",
|
||||
"nyc": "~15.1.0",
|
||||
"rimraf": "~3.0.2",
|
||||
"source-map-support": "0.5.19",
|
||||
"ts-node": "~9.1.1",
|
||||
"typescript": "~4.1.3"
|
||||
},
|
||||
"nyc": {
|
||||
"extension": [
|
||||
".ts"
|
||||
],
|
||||
"exclude": [
|
||||
"**/*.d.ts",
|
||||
"test/**"
|
||||
],
|
||||
"require": [
|
||||
"ts-node/register"
|
||||
],
|
||||
"reporter": [
|
||||
"html",
|
||||
"text"
|
||||
]
|
||||
"source-map-support": "^0.5.20",
|
||||
"ts-jest": "^27.0.7",
|
||||
"ts-node": "^10.4.0",
|
||||
"tsconfig-paths": "^3.11.0",
|
||||
"typescript": "^4.4.4"
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,12 +0,0 @@
|
||||
import { expect } from 'chai';
|
||||
import { Item, GildedRose } from '../app/gilded-rose';
|
||||
|
||||
describe('Gilded Rose', function () {
|
||||
|
||||
it('should foo', function() {
|
||||
const gildedRose = new GildedRose([ new Item('foo', 0, 0) ]);
|
||||
const items = gildedRose.updateQuality();
|
||||
expect(items[0].name).to.equal('fixme');
|
||||
});
|
||||
|
||||
});
|
||||
@ -1,27 +1,27 @@
|
||||
import { Item, GildedRose } from '../app/gilded-rose';
|
||||
import { Item, GildedRose } from '@/gilded-rose';
|
||||
|
||||
const items = [
|
||||
new Item("+5 Dexterity Vest", 10, 20), //
|
||||
new Item("Aged Brie", 2, 0), //
|
||||
new Item("Elixir of the Mongoose", 5, 7), //
|
||||
new Item("Sulfuras, Hand of Ragnaros", 0, 80), //
|
||||
new Item("Sulfuras, Hand of Ragnaros", -1, 80),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 10, 49),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49),
|
||||
// this conjured item does not work properly yet
|
||||
new Item("Conjured Mana Cake", 3, 6)];
|
||||
new Item("+5 Dexterity Vest", 10, 20), //
|
||||
new Item("Aged Brie", 2, 0), //
|
||||
new Item("Elixir of the Mongoose", 5, 7), //
|
||||
new Item("Sulfuras, Hand of Ragnaros", 0, 80), //
|
||||
new Item("Sulfuras, Hand of Ragnaros", -1, 80),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 10, 49),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49),
|
||||
// this conjured item does not work properly yet
|
||||
new Item("Conjured Mana Cake", 3, 6)];
|
||||
|
||||
|
||||
const gildedRose = new GildedRose(items);
|
||||
var days: number = 2;
|
||||
for (let i = 0; i < days; i++) {
|
||||
console.log("-------- day " + i + " --------");
|
||||
console.log("name, sellIn, quality");
|
||||
items.forEach(element => {
|
||||
console.log(element.name + ' ' + element.sellIn + ' ' + element.quality);
|
||||
console.log("-------- day " + i + " --------");
|
||||
console.log("name, sellIn, quality");
|
||||
items.forEach(element => {
|
||||
console.log(element.name + ' ' + element.sellIn + ' ' + element.quality);
|
||||
|
||||
});
|
||||
console.log();
|
||||
gildedRose.updateQuality();
|
||||
}
|
||||
});
|
||||
console.log();
|
||||
gildedRose.updateQuality();
|
||||
}
|
||||
|
||||
9
TypeScript/test/jest/gilded-rose.spec.ts
Normal file
9
TypeScript/test/jest/gilded-rose.spec.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { Item, GildedRose } from '@/gilded-rose';
|
||||
|
||||
describe('Gilded Rose', () => {
|
||||
it('should foo', () => {
|
||||
const gildedRose = new GildedRose([new Item('foo', 0, 0)]);
|
||||
const items = gildedRose.updateQuality();
|
||||
expect(items[0].name).toBe('fixme');
|
||||
});
|
||||
});
|
||||
10
TypeScript/test/mocha/gilded-rose.spec.ts
Normal file
10
TypeScript/test/mocha/gilded-rose.spec.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { expect } from 'chai';
|
||||
import { Item, GildedRose } from '@/gilded-rose';
|
||||
|
||||
describe('Gilded Rose', () => {
|
||||
it('should foo', () => {
|
||||
const gildedRose = new GildedRose([new Item('foo', 0, 0)]);
|
||||
const items = gildedRose.updateQuality();
|
||||
expect(items[0].name).to.equal('fixme');
|
||||
});
|
||||
});
|
||||
@ -1,12 +1,18 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"strict": true,
|
||||
"noImplicitAny": false,
|
||||
"sourceMap": false
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"strict": true,
|
||||
"noImplicitAny": false,
|
||||
"sourceMap": false,
|
||||
"baseUrl": "./",
|
||||
"paths": {
|
||||
"@/*": [
|
||||
"app/*"
|
||||
]
|
||||
}
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user