1
+ import fs from 'fs'
1
2
import { executablePath } from 'puppeteer'
3
+
2
4
import config from './config'
3
5
import webpackConfig from './webpack.config.babel'
4
6
5
7
process . env . CHROME_BIN = executablePath ( )
6
8
9
+ const { paths } = config
10
+
7
11
const formatError = ( msg ) => {
8
12
// filter out empty lines and node_modules
9
- if ( ! msg . trim ( ) || / ~ / . test ( msg ) ) return ''
13
+ if ( ! msg . trim ( ) || / ~ / . test ( msg ) || / n o d e _ m o d u l e s \/ / . test ( msg ) ) return ''
10
14
11
15
// indent the error beneath the it() message
12
16
let newLine = ` ${ msg } `
@@ -24,16 +28,20 @@ const formatError = (msg) => {
24
28
25
29
export default ( karmaConfig ) => {
26
30
karmaConfig . set ( {
27
- basePath : process . cwd ( ) ,
31
+ basePath : __dirname ,
28
32
browsers : [ 'puppeteer' ] ,
33
+ browserConsoleLogOptions : {
34
+ level : 'log' ,
35
+ terminal : true ,
36
+ } ,
29
37
client : {
30
38
mocha : {
31
39
reporter : 'html' , // change Karma's debug.html to mocha web reporter
32
40
ui : 'bdd' ,
33
41
} ,
34
42
} ,
35
43
coverageReporter : {
36
- reporters : [ { type : 'lcov' , dir : 'coverage' , subdir : '.' } , { type : 'text-summary' } ] ,
44
+ reporters : [ { type : 'lcov' , dir : 'coverage' , subdir : '.' } ] ,
37
45
includeAllSources : true ,
38
46
} ,
39
47
customLaunchers : {
@@ -47,15 +55,30 @@ export default (karmaConfig) => {
47
55
] ,
48
56
} ,
49
57
} ,
50
- files : [ './test/tests.bundle.js' ] ,
58
+ files : [
59
+ { pattern : 'docs/app/logo.png' , watched : false , included : false , served : true } ,
60
+ { pattern : 'docs/app/assets/**/*.jpg' , watched : false , included : false , served : true } ,
61
+ { pattern : 'docs/app/assets/**/*.png' , watched : false , included : false , served : true } ,
62
+ './test/tests.bundle.js' ,
63
+ ] ,
51
64
formatError,
52
65
frameworks : [ 'mocha' ] ,
66
+ // make karma serve all files that the web server does: /* => /docs/app/*
67
+ proxies : fs . readdirSync ( paths . docsSrc ( ) ) . reduce ( ( acc , file ) => {
68
+ const isDir = fs . statSync ( paths . docsSrc ( file ) ) . isDirectory ( )
69
+ const trailingSlash = isDir ? '/' : ''
70
+
71
+ const original = `/${ file } ${ trailingSlash } `
72
+ acc [ original ] = `/base/docs/app/${ file } ${ trailingSlash } `
73
+ return acc
74
+ } , { } ) ,
53
75
reporters : [ 'mocha' , 'coverage' ] ,
76
+ reportSlowerThan : 100 ,
54
77
singleRun : true ,
55
78
preprocessors : {
56
79
// do not include 'coverage' preprocessor for karma-coverage
57
80
// code is already instrumented by babel-plugin-__coverage__
58
- './ test/tests.bundle.js' : [ 'webpack' ] ,
81
+ 'test/tests.bundle.js' : [ 'webpack' ] ,
59
82
} ,
60
83
webpack : {
61
84
entry : './test/tests.bundle.js' ,
0 commit comments