Skip to content
Snippets Groups Projects
Commit 8d742d3b authored by squidfunk's avatar squidfunk
Browse files

Fixed type errors in Karma configuration and added aliases for tests

parent d5a9361a
No related branches found
No related tags found
No related merge requests found
......@@ -22,7 +22,14 @@
import * as path from "path"
import { Config, ConfigOptions } from "karma"
import {
Config as KarmaConfig,
ConfigOptions as KarmaConfigOptions
} from "karma"
import {
Configuration as WebpackConfig,
NewModule
} from "webpack"
/* ----------------------------------------------------------------------------
* Plugins
......@@ -34,48 +41,16 @@ import EventHooksPlugin = require("event-hooks-webpack-plugin")
* Configuration
* ------------------------------------------------------------------------- */
export default (config: Config & ConfigOptions) => {
config.set({
basePath: __dirname,
/* Frameworks to be used */
frameworks: [
"jasmine",
"jasmine-diff",
"viewport"
],
/* Entrypoint for tests */
files: [
"index.ts"
],
/* Preprocessors */
preprocessors: {
"index.ts": [
"webpack",
"sourcemap"
]
},
export default (config: KarmaConfig & KarmaConfigOptions) => {
/* Webpack configuration */
webpack: {
const webpack: Partial<WebpackConfig> = {
module: {
rules: [
/* TypeScript */
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /\/node_modules\//
},
/* Instrumentation for code coverge */
{
test: /\.tsx?$/,
use: "istanbul-instrumenter-loader?+esModules",
include: path.resolve(__dirname, "../src"),
enforce: "post"
}
]
},
......@@ -83,7 +58,11 @@ export default (config: Config & ConfigOptions) => {
modules: [
path.resolve(__dirname, "../node_modules")
],
extensions: [".js", ".ts"]
extensions: [".js", ".ts"],
alias: {
"~": path.resolve(__dirname, "../src/assets/javascripts"),
"@mock": path.resolve(__dirname, "mocks")
}
},
plugins: [
......@@ -100,8 +79,44 @@ export default (config: Config & ConfigOptions) => {
}
})
]
}
/* Instrumentation for code coverage */
if (config.singleRun)
(webpack.module as NewModule).rules.push({
test: /\.tsx?$/,
use: "istanbul-instrumenter-loader?+esModules",
include: path.resolve(__dirname, "../src"),
enforce: "post"
})
/* Karma configuration */
config.set({
basePath: __dirname,
/* Frameworks to be used */
frameworks: [
"jasmine",
"jasmine-diff",
"viewport"
],
/* Entrypoint for tests */
files: [
"index.ts"
],
/* Preprocessors */
preprocessors: {
"index.ts": [
"webpack",
"sourcemap"
]
},
/* Webpack configuration */
webpack,
/* Reporters */
reporters: config.singleRun
? ["spec", "coverage-istanbul"]
......@@ -115,7 +130,7 @@ export default (config: Config & ConfigOptions) => {
suppressSkipped: true
},
/* Enable code coverage */
/* Configuration for coverage reporter */
coverageIstanbulReporter: {
reports: [
"html",
......@@ -123,7 +138,7 @@ export default (config: Config & ConfigOptions) => {
]
},
/* Hack: TypeScript is served with "video/mp2t" mime type */
/* Hack: TypeScript files are served with "video/mp2t" mime type */
mime: {
"text/x-typescript": ["ts"]
}
......
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"alwaysStrict": true,
"baseUrl": ".",
"emitDecoratorMetadata": true,
......@@ -18,6 +17,10 @@
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"paths": {
"~/*": ["src/assets/javascripts/*"],
"@mock/*": ["tests/mocks/*"]
},
"preserveConstEnums": true,
"removeComments": true,
"sourceMap": true,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment