test: add unit test setup (#138)

pull/139/head
Kia King Ishii 4 years ago committed by GitHub
parent fdd498be70
commit 8735fc3096
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

1
.gitignore vendored

@ -1,3 +1,4 @@
/coverage
/src/client/shared /src/client/shared
/src/node/shared /src/node/shared
*.log *.log

@ -0,0 +1,22 @@
import * as Utils from 'client/theme-default/utils'
describe('client/theme-default/utils', () => {
describe('ensureStartingSlash', () => {
it('should add slash to the beginning of the given path', () => {
expect(Utils.ensureStartingSlash('path')).toBe('/path')
expect(Utils.ensureStartingSlash('path/nested')).toBe('/path/nested')
expect(Utils.ensureStartingSlash('/path')).toBe('/path')
expect(Utils.ensureStartingSlash('/path/nested')).toBe('/path/nested')
})
})
describe('ensureEndingSlash', () => {
it('should add slash to the end of the given path', () => {
expect(Utils.ensureEndingSlash('path')).toBe('path/')
expect(Utils.ensureEndingSlash('path/nested')).toBe('path/nested/')
expect(Utils.ensureEndingSlash('path/')).toBe('path/')
expect(Utils.ensureEndingSlash('path/nested/')).toBe('path/nested/')
expect(Utils.ensureEndingSlash('path/page.html')).toBe('path/page.html')
})
})
})

@ -0,0 +1,13 @@
module.exports = {
preset: 'ts-jest',
rootDir: __dirname,
moduleNameMapper: {
'^src/(.*)$': '<rootDir>/src/$1',
'^client/(.*)$': '<rootDir>/src/client/$1',
'^node/(.*)$': '<rootDir>/src/node/$1',
'^shared/(.*)$': '<rootDir>/src/shared/$1',
'^tests/(.*)$': '<rootDir>/__tests__/$1'
},
testMatch: ['<rootDir>/__tests__/**/*.spec.ts'],
testPathIgnorePatterns: ['/node_modules/']
}

@ -23,7 +23,8 @@
"build": "rimraf -rf dist && node scripts/copyShared && tsc -p src/client && tsc -p src/node && node scripts/copyClient", "build": "rimraf -rf dist && node scripts/copyShared && tsc -p src/client && tsc -p src/node && node scripts/copyClient",
"lint": "yarn lint:js && yarn lint:ts", "lint": "yarn lint:js && yarn lint:ts",
"lint:js": "prettier --check --write \"{bin,docs,scripts,src}/**/*.js\"", "lint:js": "prettier --check --write \"{bin,docs,scripts,src}/**/*.js\"",
"lint:ts": "prettier --check --write --parser typescript \"{src,docs,types}/**/*.ts\"", "lint:ts": "prettier --check --write --parser typescript \"{__tests__,src,docs,types}/**/*.ts\"",
"test": "jest",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
"release": "node scripts/release.js", "release": "node scripts/release.js",
"docs": "run-p dev docs-dev", "docs": "run-p dev docs-dev",
@ -86,6 +87,7 @@
}, },
"devDependencies": { "devDependencies": {
"@types/fs-extra": "^9.0.1", "@types/fs-extra": "^9.0.1",
"@types/jest": "^26.0.15",
"@types/koa": "^2.11.6", "@types/koa": "^2.11.6",
"@types/koa-static": "^4.0.1", "@types/koa-static": "^4.0.1",
"@types/lru-cache": "^5.1.0", "@types/lru-cache": "^5.1.0",
@ -96,6 +98,7 @@
"conventional-changelog-cli": "^2.1.0", "conventional-changelog-cli": "^2.1.0",
"enquirer": "^2.3.6", "enquirer": "^2.3.6",
"execa": "^4.1.0", "execa": "^4.1.0",
"jest": "^26.6.3",
"koa": "^2.13.0", "koa": "^2.13.0",
"koa-static": "^5.0.0", "koa-static": "^5.0.0",
"lint-staged": "^10.3.0", "lint-staged": "^10.3.0",
@ -103,6 +106,7 @@
"prettier": "^2.0.5", "prettier": "^2.0.5",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"semver": "^7.3.2", "semver": "^7.3.2",
"ts-jest": "^26.4.4",
"typescript": "^3.8.3", "typescript": "^3.8.3",
"yorkie": "^2.0.0" "yorkie": "^2.0.0"
} }

@ -1,5 +1,5 @@
{ {
"extends": "../../tsconfig.base.json", "extends": "../../tsconfig.json",
"compilerOptions": { "compilerOptions": {
"baseUrl": ".", "baseUrl": ".",
"outDir": "../../dist/client", "outDir": "../../dist/client",

@ -1,5 +1,5 @@
{ {
"extends": "../../tsconfig.base.json", "extends": "../../tsconfig.json",
"compilerOptions": { "compilerOptions": {
"baseUrl": ".", "baseUrl": ".",
"outDir": "../../dist/node", "outDir": "../../dist/node",

@ -1,5 +1,5 @@
{ {
"extends": "../../tsconfig.base.json", "extends": "../../tsconfig.json",
"compilerOptions": { "compilerOptions": {
"baseUrl": ".", "baseUrl": ".",
"paths": { "paths": {

@ -1,10 +0,0 @@
{
"compilerOptions": {
"target": "esnext",
"moduleResolution": "node",
"strict": true,
"declaration": true,
"noUnusedLocals": true,
"esModuleInterop": true
}
}

@ -0,0 +1,30 @@
{
"compilerOptions": {
"baseUrl": ".",
"module": "esnext",
"target": "esnext",
"moduleResolution": "node",
"strict": true,
"declaration": true,
"noUnusedLocals": true,
"esModuleInterop": true,
"lib": ["ESNext", "DOM"],
"types": ["node", "jest"],
"paths": {
"src/*": ["src/*"],
"client/*": ["src/client/*"],
"node/*": ["src/node/*"],
"shared/*": ["src/shared/*"],
"tests/*": ["__tests__/*"],
"/@app/*": ["src/client/app/*"],
"/@theme/*": ["src/client/theme-default/*"],
"/@shared/*": ["src/client/shared/*"],
"/@types/*": ["types/*"],
"vitepress": ["src/client/app/exports.ts"]
}
},
"include": [
"src",
"__tests__"
]
}

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save