Skip to content

Commit e0bbd20

Browse files
author
Matty Goo
authored
test: added karma local and ci (material-components#7)
1 parent a1616de commit e0bbd20

File tree

7 files changed

+192
-121
lines changed

7 files changed

+192
-121
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ coverage
22
.idea
33
node_modules
44
.DS_Store
5+
*.iml

karma.ci.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const karmaConfig = require('./scripts/karma/config');
2+
3+
// enable ChromeHeadless Browser
4+
process.env.CHROME_BIN = require('puppeteer').executablePath();
5+
6+
module.exports = function(config) {
7+
karmaConfig.browsers = ['ChromeHeadless'];
8+
config.set(karmaConfig);
9+
};

karma.conf.js

Lines changed: 0 additions & 110 deletions
This file was deleted.

karma.local.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const karmaConfig = require('./scripts/karma/config');
2+
3+
module.exports = function(config) {
4+
karmaConfig.browsers = ['Chrome'];
5+
config.set(karmaConfig);
6+
};

package-lock.json

Lines changed: 72 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
"pretest": "npm run lint && npm stop && ./test/screenshot/start.sh",
1313
"test": "npm run test:unit && npm run test:image-diff",
1414
"posttest": "npm stop && istanbul report --root coverage text-summary && istanbul check-coverage --lines 95 --statements 95 --branches 95 --functions 95",
15-
"test:watch": "karma start --auto-watch",
16-
"test:unit": "karma start --single-run",
15+
"test:watch": "karma start karma.local.js --auto-watch",
16+
"test:unit": "karma start karma.local.js --single-run",
17+
"test:ci": "karma start karma.ci.js --single-run",
1718
"test:image-diff": "./node_modules/.bin/mocha --compilers js:babel-core/register --ui tdd --timeout 15000 test/screenshot/diff-suite.js"
1819
},
1920
"config": {
@@ -51,6 +52,7 @@
5152
"node-resemble-js": "^0.2.0",
5253
"node-sass": "^4.7.2",
5354
"optimize-css-assets-webpack-plugin": "^3.2.0",
55+
"puppeteer": "^1.1.1",
5456
"react": "^16.2.0",
5557
"react-dom": "^16.2.0",
5658
"sass-loader": "^6.0.7",

scripts/karma/config.js

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Karma configuration
2+
// Generated on Tue Mar 06 2018 14:20:28 GMT-0800 (PST)
3+
const path = require('path');
4+
5+
module.exports = {
6+
// base path that will be used to resolve all patterns (eg. files, exclude)
7+
basePath: '',
8+
9+
10+
// frameworks to use
11+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
12+
frameworks: ['mocha'],
13+
14+
15+
// list of files / patterns to load in the browser
16+
files: [
17+
'test/unit/index.js'
18+
],
19+
20+
21+
// list of files / patterns to exclude
22+
exclude: [
23+
],
24+
25+
26+
// preprocess matching files before serving them to the browser
27+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
28+
preprocessors: {
29+
'test/unit/index.js': ['webpack']
30+
},
31+
32+
webpack: {
33+
devtool: 'inline-source-map',
34+
module: {
35+
loaders: [
36+
{ test: /\.js?$/, loader: 'babel-loader' }
37+
],
38+
rules: [
39+
// instrument only testing sources with Istanbul
40+
{
41+
test: /\.js$/,
42+
use: {
43+
loader: 'istanbul-instrumenter-loader',
44+
options: {esModules: true}
45+
},
46+
include: path.resolve('packages/'),
47+
exclude: [
48+
/node_modules/
49+
],
50+
enforce: 'post'
51+
}
52+
]
53+
}
54+
},
55+
56+
client: {
57+
mocha: {
58+
reporter: 'html',
59+
ui: 'qunit',
60+
},
61+
},
62+
63+
// test results reporter to use
64+
// possible values: 'dots', 'progress'
65+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
66+
reporters: ['progress', 'coverage'],
67+
68+
coverageReporter: {
69+
dir: 'coverage',
70+
reporters: [
71+
{type: 'lcovonly', subdir: '.'},
72+
{type: 'json', subdir: '.', file: 'coverage.json'},
73+
{type: 'html'},
74+
],
75+
},
76+
77+
// web server port
78+
port: 9876,
79+
80+
81+
// enable / disable colors in the output (reporters and logs)
82+
colors: true,
83+
84+
85+
// level of logging
86+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
87+
// logLevel: config.LOG_INFO,
88+
89+
90+
// enable / disable watching file and executing tests whenever any file changes
91+
autoWatch: false,
92+
93+
// Continuous Integration mode
94+
// if true, Karma captures browsers, runs the tests and exits
95+
singleRun: false,
96+
97+
// Concurrency level
98+
// how many browser should be started simultaneous
99+
concurrency: Infinity,
100+
};

0 commit comments

Comments
 (0)