Add Jest for testing with one test

This commit is contained in:
James Skemp 2020-08-02 22:11:03 -05:00
parent 25bd910eb4
commit 49850634e1
9 changed files with 4201 additions and 5 deletions

3
.gitignore vendored
View File

@ -19,3 +19,6 @@ yarn-error.log*
*.njsproj
*.sln
*.sw?
# Jest coverage report
/coverage

View File

@ -26,6 +26,13 @@ This custom one uses eslint directly, and doesn't automatically fix issues.
npm run eslint
```
### Jest testing
```
npm run test
npm run test:coverage
```
#### Check for specific issues
```
npm run lint | grep require-returns

View File

@ -0,0 +1,7 @@
import World from 'src/models/World';
const world = new World();
test('World has empty journal', () => {
expect(world.journal.count()).toBe(0);
});

26
jest.config.js Normal file
View File

@ -0,0 +1,26 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
roots: [
'<rootDir>'
],
modulePaths: [
'<rootDir>'
],
// An array of glob patterns indicating a set of files for which coverage information should be collected
collectCoverageFrom: [
"<rootDir>/src/**/*.ts",
"!<rootDir>/src/**/*.d.ts"
],
// The directory where Jest should output its coverage files
//coverageDirectory: "coverage",
/*moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1'
},*/
globals: {
'ts-jest': {
}
}
};

4131
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -6,8 +6,10 @@
"serve": "vue-cli-service serve",
"build": "vue-cli-service build --modern",
"lint": "vue-cli-service lint",
"eslint": "eslint ./src --ext .js,.jsx,.ts,.tsx,.vue || (exit 0)",
"docs": "typedoc --out docs src && http-server docs"
"eslint": "eslint ./src --ext .js,.jsx,.ts,.tsx,.vue || (exit 0)",
"docs": "typedoc --out docs src && http-server docs",
"test": "jest",
"test:coverage": "jest --coverage"
},
"dependencies": {
"@vue/eslint-config-typescript": "^5.0.2",
@ -19,6 +21,7 @@
"vue-property-decorator": "^9.0.0"
},
"devDependencies": {
"@types/jest": "^26.0.8",
"@typescript-eslint/eslint-plugin": "^3.7.1",
"@typescript-eslint/parser": "^3.7.1",
"@vue/cli-plugin-eslint": "^4.4.6",
@ -27,6 +30,8 @@
"eslint": "^7.5.0",
"eslint-plugin-jsdoc": "^30.0.3",
"eslint-plugin-vue": "^6.1.2",
"jest": "^26.2.2",
"ts-jest": "^26.1.4",
"typescript": "^3.9.7",
"vue-template-compiler": "^2.6.11"
}

View File

@ -17,6 +17,15 @@ export default class Journal {
this.entries.push(new JournalEntry(currentMoment, message));
}
/**
* Get the number of entries in the journal.
*
* @returns Number of entries.
*/
public count(): number {
return this.entries.length;
}
/**
* Removes all entries from the journal.
*/

7
tsconfig.build.json Normal file
View File

@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"exclude": [
"**/*.spec.ts",
"**/*.test.ts",
]
}

View File

@ -13,7 +13,8 @@
"sourceMap": true,
"baseUrl": ".",
"types": [
"webpack-env"
"jest",
"webpack-env"
],
"paths": {
"@/*": [
@ -32,8 +33,8 @@
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue",
"tests/**/*.ts",
"tests/**/*.tsx"
"__tests__/**/*.ts",
"__tests__/**/*.tsx"
],
"exclude": [
"node_modules"