refs #850 Allow typescript for unit tests

This commit is contained in:
AkiraFukushima 2019-03-25 21:51:24 +09:00
parent 8437763dd7
commit 946ead49f5
24 changed files with 2656 additions and 2026 deletions

View File

@ -3,16 +3,16 @@
"env": {
"test": {
"presets": [
["env", {
["@babel/preset-env", {
"targets": { "node": 9 }
}],
"stage-0"
"@babel/preset-typescript"
],
"plugins": ["istanbul"]
},
"main": {
"presets": [
["env", {
["@babel/preset-env", {
"targets": { "node": 9 }
}],
"stage-0"
@ -20,20 +20,20 @@
},
"renderer": {
"presets": [
["env", {
"modules": false
["@babel/preset-env", {
"modules": false,
"targets": { "node": "current" }
}],
"stage-0"
"@babel/preset-typescript"
]
},
"web": {
"presets": [
["env", {
["@babel/preset-env", {
"modules": false
}],
"stage-0"
]
}
},
"plugins": ["transform-runtime"]
}
}

4501
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -97,15 +97,24 @@
}
},
"jest": {
"moduleFileExtensions": [
"ts",
"js"
],
"moduleNameMapper": {
"@/router": "<rootDir>/spec/mock/router.js",
"@/router": "<rootDir>/spec/mock/router.ts",
"^@/(.+)": "<rootDir>/src/renderer/$1",
"^~/(.+)": "<rootDir>/$1",
"electron": "<rootDir>/spec/mock/electron.js"
"electron": "<rootDir>/spec/mock/electron.ts"
},
"testMatch": [
"**/spec/**/*.spec.js?(x)"
]
"**/spec/**/*.spec.ts"
],
"globals": {
"ts-jest": {
"tsConfig": "tsconfig.json"
}
}
},
"dependencies": {
"@panter/vue-i18next": "^0.13.0",
@ -151,19 +160,20 @@
"vuex-router-sync": "^5.0.0"
},
"devDependencies": {
"@babel/preset-env": "^7.4.2",
"@babel/preset-typescript": "^7.3.3",
"@mapbox/stylelint-processor-arbitrary-tags": "^0.2.0",
"@types/i18next": "^12.1.0",
"@types/jest": "^24.0.11",
"@types/node": "^11.11.4",
"@vue/test-utils": "^1.0.0-beta.28",
"ajv": "^6.6.1",
"babel-core": "^6.26.3",
"babel-eslint": "^10.0.1",
"babel-jest": "^23.6.0",
"babel-loader": "^7.1.4",
"babel-jest": "^24.5.0",
"babel-loader": "^8.0.5",
"babel-minify-webpack-plugin": "^0.3.1",
"babel-plugin-istanbul": "^5.1.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.7.0",
"babel-preset-stage-0": "^6.24.1",
"babel-register": "^6.26.0",
"cfonts": "^2.3.0",
@ -191,7 +201,7 @@
"eslint-plugin-standard": "^4.0.0",
"file-loader": "^2.0.0",
"html-webpack-plugin": "^3.2.0",
"jest": "^23.6.0",
"jest": "^24.5.0",
"jsdom": "^13.0.0",
"karma": "^3.1.3",
"karma-chai": "^0.1.0",
@ -211,8 +221,10 @@
"style-loader": "^0.23.1",
"stylelint": "^9.9.0",
"stylelint-config-standard": "^18.2.0",
"ts-jest": "^24.0.0",
"ts-loader": "^5.3.3",
"ttfinfo": "^0.2.0",
"typescript": "^3.3.4000",
"url-loader": "^1.1.2",
"vue-html-loader": "^1.2.4",
"vue-loader": "^15.2.4",

View File

@ -1,4 +0,0 @@
const { ipcRenderer, ipcMain } = require('electron-ipc-mock')()
module.exports.ipcRenderer = ipcRenderer
module.exports.ipcMain = ipcMain

6
spec/mock/electron.ts Normal file
View File

@ -0,0 +1,6 @@
import mock from 'electron-ipc-mock'
const instance = mock()
const ipcMain = instance.ipcMain
const ipcRenderer = instance.ipcRenderer
export { ipcMain, ipcRenderer }

View File

@ -1,11 +1,12 @@
import Authorize from '@/store/Authorize'
import { ipcMain } from '~/spec/mock/electron'
describe('Authorize', () => {
describe.skip('Authorize', () => {
// TODO: integration
describe('actions', () => {
describe('error', () => {
it('should return error', async () => {
ipcMain.once('get-access-token', (event, code) => {
ipcMain.once('get-access-token', (event, _) => {
event.sender.send('error-get-access-token', new AccessTokenError())
})
const commitMock = jest.fn()
@ -17,7 +18,7 @@ describe('Authorize', () => {
})
describe('success', () => {
it('should return id', async () => {
ipcMain.once('get-access-token', (event, code) => {
ipcMain.once('get-access-token', (event, _) => {
event.sender.send('response-get-access-token', 'abcd')
})
const commitMock = jest.fn()
@ -28,4 +29,4 @@ describe('Authorize', () => {
})
})
class AccessTokenError extends Error {}
class AccessTokenError extends Error { }

View File

@ -1,12 +1,13 @@
import axios from 'axios'
import Login from '@/store/Login'
import axios from 'axios'
import { ipcMain } from '~/spec/mock/electron'
jest.mock('axios')
axios.get = jest.fn()
describe('Login', () => {
describe('mutations', () => {
let state
let state: any
beforeEach(() => {
state = {
instances: [],
@ -28,11 +29,12 @@ describe('Login', () => {
})
})
describe('actions', () => {
// TODO: move to integration
describe.skip('actions', () => {
describe('fetchLogin', () => {
describe('error', () => {
it('should return error', async () => {
ipcMain.once('get-auth-url', (event, instance) => {
ipcMain.once('get-auth-url', (event, _) => {
event.sender.send('error-get-auth-url', new AuthError())
})
const commitMock = jest.fn()
@ -44,7 +46,7 @@ describe('Login', () => {
})
describe('success', () => {
it('should return url', async () => {
ipcMain.once('get-auth-url', (event, instance) => {
ipcMain.once('get-auth-url', (event, _) => {
event.sender.send('response-get-auth-url', 'http://example.com/auth')
})
const commitMock = jest.fn()
@ -62,12 +64,11 @@ describe('Login', () => {
})
describe('confirmInstance', () => {
it('should change instance', async () => {
const resp = {
data: 'test'
}
// Provide Promise.resolve for finally keywrod.
// https://github.com/facebook/jest/issues/6552
axios.get.mockReturnValue(Promise.resolve(resp))
(<jest.Mock>axios.get).mockReturnValue(Promise.resolve({
data: 'test'
}))
const commitMock = jest.fn()
const data = await Login.actions.confirmInstance({ commit: commitMock }, 'pleroma.io')
expect(data).toEqual('test')
@ -78,4 +79,4 @@ describe('Login', () => {
})
})
class AuthError extends Error {}
class AuthError extends Error { }

View File

@ -129,8 +129,8 @@ describe('Preferences/Account', () => {
})
})
class LoadAccountsError extends Error {}
class RemoveAccountError extends Error {}
class ForwardAccountError extends Error {}
class BackwardAccountError extends Error {}
class RemoveAllAccountsError extends Error {}
class LoadAccountsError extends Error { }
class RemoveAccountError extends Error { }
class ForwardAccountError extends Error { }
class BackwardAccountError extends Error { }
class RemoveAllAccountsError extends Error { }

View File

@ -89,5 +89,5 @@ describe('Preferences/Appearance', () => {
})
})
class LoadAppearanceError extends Error {}
class ListFontsError extends Error {}
class LoadAppearanceError extends Error { }
class ListFontsError extends Error { }

View File

@ -1,6 +1,6 @@
import * as path from 'path'
import * as i18next from 'i18next'
import * as Backend from 'i18next-sync-fs-backend'
import i18next from 'i18next'
import Backend from 'i18next-sync-fs-backend'
import { InitOptions } from 'i18next'
const options: InitOptions = {

View File

@ -1,62 +1,27 @@
{
"compilerOptions": {
/* Basic Options */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"module": "es2015", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"lib": ["es6"], /* Specify library files to be included in the compilation. */
"allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
"sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
// "outDir": "./lib", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
"removeComments": false, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
"downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
"strictNullChecks": true, /* Enable strict null checks. */
"strictFunctionTypes": true, /* Enable strict checking of function types. */
"strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
"noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
"noUnusedLocals": true, /* Report errors on unused locals. */
"noUnusedParameters": true, /* Report errors on unused parameters. */
"noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
"noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
"baseUrl": "./", /* Base directory to resolve non-absolute module names. */
"target": "es5",
"module": "es2015",
"lib": ["es6"],
"sourceMap": true,
"downlevelIteration": true,
"strict": true,
"noImplicitAny": false,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"noImplicitThis": true,
"alwaysStrict": true,
"allowSyntheticDefaultImports": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"baseUrl": "./",
"paths": {
"@*": ["src/renderer*"],
"~*": ["./*"]
},
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
"typeRoots": ["./types"], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
/* Source Map Options */
// "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
}
}
}