Merge pull request #272 from Gnuk/add-jest-to-typescript

Add Jest to TypeScript (and update dependencies)
This commit is contained in:
Emily Bache 2021-11-11 16:06:15 +01:00 committed by GitHub
commit 128efdfc14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 = { module.exports = {
require: [ require: [
"ts-node/register", "ts-node/register",
"tsconfig-paths/register",
"source-map-support/register" "source-map-support/register"
], ],
recursive: true, 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", "precompile": "rimraf app/**/*.js test/**/*.js",
"compile": "tsc", "compile": "tsc",
"pretest": "rimraf app/**/*.js test/**/*.js", "pretest": "rimraf app/**/*.js test/**/*.js",
"test": "nyc mocha" "test:jest": "jest",
"test:jest:watch": "jest --watchAll",
"test:mocha": "nyc mocha"
}, },
"license": "MIT", "license": "MIT",
"private": true, "private": true,
"devDependencies": { "devDependencies": {
"@types/chai": "~3.5.2", "@types/chai": "^4.2.22",
"@types/mocha": "~2.2.41", "@types/jest": "^27.0.2",
"@types/node": "~7.0.18", "@types/mocha": "^9.0.0",
"chai": "~4.2.0", "@types/node": "^16.11.7",
"mocha": "~8.2.1", "chai": "^4.3.4",
"jest": "^27.3.1",
"mocha": "^9.1.3",
"nyc": "~15.1.0", "nyc": "~15.1.0",
"rimraf": "~3.0.2", "rimraf": "~3.0.2",
"source-map-support": "0.5.19", "source-map-support": "^0.5.20",
"ts-node": "~9.1.1", "ts-jest": "^27.0.7",
"typescript": "~4.1.3" "ts-node": "^10.4.0",
}, "tsconfig-paths": "^3.11.0",
"nyc": { "typescript": "^4.4.4"
"extension": [
".ts"
],
"exclude": [
"**/*.d.ts",
"test/**"
],
"require": [
"ts-node/register"
],
"reporter": [
"html",
"text"
]
} }
} }

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 = [ const items = [
new Item("+5 Dexterity Vest", 10, 20), // 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", "target": "es5",
"strict": true, "strict": true,
"noImplicitAny": false, "noImplicitAny": false,
"sourceMap": false "sourceMap": false,
"baseUrl": "./",
"paths": {
"@/*": [
"app/*"
]
}
}, },
"exclude": [ "exclude": [
"node_modules" "node_modules"