Add Jest to TypeScript (and update dependencies)

This commit is contained in:
Anthony Rey 2021-11-09 18:32:42 +01:00
parent 864f34ccc1
commit b0f4a15245
13 changed files with 9585 additions and 127 deletions

12
TypeScript/.editorconfig Normal file
View 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

View File

@ -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
View 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
View 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
```

13
TypeScript/jest.config.ts Normal file
View 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

File diff suppressed because it is too large Load Diff

View File

@ -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"
}
}

View File

@ -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');
});
});

View File

@ -1,4 +1,4 @@
import { Item, GildedRose } from '../app/gilded-rose';
import { Item, GildedRose } from '@/gilded-rose';
const items = [
new Item("+5 Dexterity Vest", 10, 20), //

View 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');
});
});

View 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');
});
});

View File

@ -4,7 +4,13 @@
"target": "es5",
"strict": true,
"noImplicitAny": false,
"sourceMap": false
"sourceMap": false,
"baseUrl": "./",
"paths": {
"@/*": [
"app/*"
]
}
},
"exclude": [
"node_modules"