Skip to content

Commit b05c2d0

Browse files
deigakamilogorek
authored andcommitted
build/ci: Use Karma for running tests, add Headless Firefox, Android 6/7 and latest Edge
1 parent 785a95e commit b05c2d0

14 files changed

+258
-230
lines changed

.travis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ cache:
1010
directories:
1111
- node_modules
1212
addons:
13-
chrome: stable
13+
chrome: latest
14+
firefox: latest
1415
sauce_connect: true
1516
script:
1617
- npm run test && npm run test:ci

Gruntfile.js

+1-76
Original file line numberDiff line numberDiff line change
@@ -196,69 +196,6 @@ module.exports = function(grunt) {
196196
}
197197
},
198198

199-
'saucelabs-mocha': {
200-
all: {
201-
options: {
202-
urls: [
203-
'http://127.0.0.1:9999/test/index.html',
204-
'http://127.0.0.1:9999/test/integration/index.html'
205-
],
206-
sauceConfig: {
207-
'record-video': false,
208-
'record-screenshots': false
209-
},
210-
build: process.env.TRAVIS_BUILD_NUMBER,
211-
// On average, our integration tests take 60s to run
212-
// and unit tests about 30s, which gives us 90s in total
213-
// And even though we are running 2 tests in parallel, it's safer to assume
214-
// 90s * 7 browsers = ~10 minutes (plus some additional time, just in case)
215-
// Therefore 200 * 3000ms = 10min
216-
statusCheckAttempts: 200,
217-
pollInterval: 3000,
218-
testname:
219-
'Raven.js' +
220-
(process.env.TRAVIS_JOB_NUMBER ? ' #' + process.env.TRAVIS_JOB_NUMBER : ''),
221-
browsers: [
222-
// Latest version of Edge (v15) can't reach the server, so we use v14 for now instead
223-
// Already notified SauceLabs support about this issue
224-
['Windows 10', 'microsoftedge', 'latest-1'],
225-
226-
// We can skip IE11 on Win7, as there are no differences that'd change anything for us
227-
// https://msdn.microsoft.com/library/dn394063(v=vs.85).aspx#unsupported_features
228-
['Windows 10', 'internet explorer', '11'],
229-
['Windows 7', 'internet explorer', '10'],
230-
['Windows 10', 'chrome', 'latest'],
231-
['Windows 10', 'firefox', 'latest'],
232-
['macOS 10.12', 'safari', '10.0'],
233-
['macOS 10.12', 'iphone', '10.0'],
234-
['Linux', 'android', '4.4'],
235-
['Linux', 'android', '5.1']
236-
237-
// grunt-saucelabs (or SauceLabs REST API?) doesn't allow for passing device attribute at the moment
238-
// and it's required for Android 6.0/7.1 - https://wiki.saucelabs.com/display/DOCS/2017/03/31/Android+6.0+and+7.0+Support+Released
239-
// Notified SauceLabs support as well, so hopefully it'll be resolved soon
240-
// {
241-
// browserName: 'Chrome',
242-
// platform: 'Android',
243-
// version: '6.0',
244-
// device: 'Android Emulator'
245-
// }, {
246-
// browserName: 'Chrome',
247-
// platform: 'Android',
248-
// version: '7.1',
249-
// device: 'Android GoogleAPI Emulator'
250-
// }
251-
],
252-
public: 'public',
253-
tunnelArgs: ['--verbose'],
254-
onTestComplete: function(result, callback) {
255-
console.log(result);
256-
callback(null);
257-
}
258-
}
259-
}
260-
},
261-
262199
release: {
263200
options: {
264201
npm: false,
@@ -291,12 +228,6 @@ module.exports = function(grunt) {
291228
},
292229

293230
connect: {
294-
ci: {
295-
options: {
296-
port: 9999
297-
}
298-
},
299-
300231
test: {
301232
options: {
302233
port: 8000,
@@ -389,7 +320,6 @@ module.exports = function(grunt) {
389320
grunt.loadNpmTasks('grunt-s3');
390321
grunt.loadNpmTasks('grunt-gitinfo');
391322
grunt.loadNpmTasks('grunt-sri');
392-
grunt.loadNpmTasks('grunt-saucelabs');
393323

394324
// Build tasks
395325
grunt.registerTask('_prep', ['clean', 'gitinfo', 'version']);
@@ -412,12 +342,7 @@ module.exports = function(grunt) {
412342
grunt.registerTask('build', ['build.plugins-combined']);
413343
grunt.registerTask('dist', ['build.core', 'copy:dist']);
414344

415-
grunt.registerTask('test:ci', [
416-
'config:ci',
417-
'build.test',
418-
'connect:ci',
419-
'saucelabs-mocha'
420-
]);
345+
grunt.registerTask('test:ci', ['config:ci', 'build.test']);
421346

422347
// Webserver tasks
423348
grunt.registerTask('run:test', ['build.test', 'connect:test']);

karma.config.js

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Karma configuration
2+
// Generated on Tue Oct 10 2017 16:05:16 GMT+0300 (EEST)
3+
4+
module.exports = {
5+
// base path that will be used to resolve all patterns (eg. files, exclude)
6+
basePath: '',
7+
8+
// frameworks to use
9+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
10+
frameworks: ['mocha', 'chai', 'sinon'],
11+
12+
// list of files / patterns to load in the browser
13+
files: [],
14+
15+
// list of files to exclude
16+
exclude: [],
17+
18+
// preprocess matching files before serving them to the browser
19+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
20+
preprocessors: {},
21+
22+
plugins: [
23+
'karma-mocha',
24+
'karma-mocha-reporter',
25+
'karma-chai',
26+
'karma-sinon',
27+
'karma-chrome-launcher',
28+
'karma-firefox-launcher',
29+
'karma-failed-reporter'
30+
],
31+
32+
// test results reporter to use
33+
// possible values: 'dots', 'progress'
34+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
35+
reporters: ['mocha'],
36+
37+
// web server port
38+
port: 9876,
39+
40+
// enable / disable colors in the output (reporters and logs)
41+
colors: true,
42+
43+
// enable / disable watching file and executing tests whenever any file changes
44+
autoWatch: true,
45+
46+
// start these browsers
47+
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
48+
browsers: ['ChromeHeadless', 'FirefoxHeadless'],
49+
50+
customLaunchers: {
51+
FirefoxHeadless: {
52+
base: 'Firefox',
53+
flags: ['-headless']
54+
}
55+
},
56+
57+
// Continuous Integration mode
58+
// if true, Karma captures browsers, runs the tests and exits
59+
singleRun: false,
60+
61+
// Concurrency level
62+
// how many browser should be started simultaneous
63+
concurrency: Infinity,
64+
65+
client: {
66+
mocha: {
67+
reporter: 'html',
68+
ui: 'bdd'
69+
}
70+
}
71+
};

karma.integration.config.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var commonConfig = require('./karma.config');
2+
3+
var testFiles = [
4+
{pattern: 'node_modules/es6-promise/dist/es6-promise.auto.js', included: false},
5+
{pattern: 'node_modules/whatwg-fetch/fetch.js', included: false},
6+
{pattern: 'test/integration/123', included: false},
7+
{pattern: 'test/integration/throw-string.js', included: false},
8+
{pattern: 'test/integration/throw-error.js', included: false},
9+
{pattern: 'test/integration/throw-object.js', included: false},
10+
{pattern: 'test/integration/example.json', included: false},
11+
{pattern: 'test/integration/frame.html', included: false},
12+
'test/integration/test.js',
13+
'test/globals.js',
14+
'build/raven.js',
15+
];
16+
17+
module.exports = function(config) {
18+
var testConfig = Object.assign({}, commonConfig, {files: testFiles});
19+
config.set(testConfig);
20+
};

karma.sauce.config.js

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
var commonConfig = require('./karma.config');
2+
3+
var customLaunchers = {
4+
sl_chrome: {
5+
base: 'SauceLabs',
6+
browserName: 'chrome',
7+
platform: 'Windows 10',
8+
version: 'latest'
9+
},
10+
sl_firefox: {
11+
base: 'SauceLabs',
12+
browserName: 'firefox',
13+
platform: 'Windows 10',
14+
version: 'latest'
15+
},
16+
sl_edge: {
17+
base: 'SauceLabs',
18+
browserName: 'microsoftedge',
19+
version: 'latest',
20+
platform: 'Windows 10'
21+
},
22+
sl_ie_11: {
23+
base: 'SauceLabs',
24+
browserName: 'internet explorer',
25+
platform: 'Windows 7',
26+
version: '11'
27+
},
28+
sl_ie_10: {
29+
base: 'SauceLabs',
30+
browserName: 'internet explorer',
31+
platform: 'Windows 7',
32+
version: '10'
33+
},
34+
sl_safari: {
35+
base: 'SauceLabs',
36+
browserName: 'safari',
37+
platform: 'OS X 10.12',
38+
version: '10.0'
39+
},
40+
sl_ios: {
41+
base: 'SauceLabs',
42+
browserName: 'iphone',
43+
platform: 'OS X 10.12',
44+
version: '10.0'
45+
},
46+
sl_android_7: {
47+
base: 'SauceLabs',
48+
browserName: 'Chrome',
49+
platform: 'Android',
50+
version: '7.1',
51+
device: 'Android GoogleAPI Emulator'
52+
},
53+
sl_android_6: {
54+
base: 'SauceLabs',
55+
browserName: 'Chrome',
56+
platform: 'Android',
57+
version: '6.0',
58+
device: 'Android Emulator'
59+
},
60+
sl_android_5: {
61+
base: 'SauceLabs',
62+
browserName: 'android',
63+
platform: 'Linux',
64+
version: '5.1'
65+
},
66+
sl_android_4: {
67+
base: 'SauceLabs',
68+
browserName: 'android',
69+
platform: 'Linux',
70+
version: '4.4'
71+
}
72+
};
73+
74+
var testFiles = [
75+
{pattern: 'node_modules/es6-promise/dist/es6-promise.auto.js', included: false},
76+
{pattern: 'node_modules/whatwg-fetch/fetch.js', included: false},
77+
{pattern: 'test/integration/123', included: false},
78+
{pattern: 'test/integration/throw-string.js', included: false},
79+
{pattern: 'test/integration/throw-error.js', included: false},
80+
{pattern: 'test/integration/throw-object.js', included: false},
81+
{pattern: 'test/integration/example.json', included: false},
82+
{pattern: 'test/integration/frame.html', included: false},
83+
'test/integration/test.js',
84+
'test/globals.js',
85+
'build/raven.js',
86+
'build/raven.test.js'
87+
];
88+
89+
module.exports = function(config) {
90+
var testConfig = Object.assign({}, commonConfig, {
91+
files: testFiles,
92+
logLevel: config.LOG_INFO,
93+
customLaunchers: customLaunchers,
94+
browsers: Object.keys(customLaunchers),
95+
reporters: ['failed', 'saucelabs'],
96+
singleRun: true,
97+
plugins: commonConfig.plugins.concat(['karma-sauce-launcher']),
98+
build: process.env.TRAVIS_BUILD_NUMBER,
99+
// SauceLabs allows for 2 tunnels only, therefore some browsers will have to wait
100+
// rather long time. Plus mobile emulators tend to require a lot of time to start up.
101+
// 10 minutes should be more than enough to run all of them.
102+
browserNoActivityTimeout: 600000,
103+
captureTimeout: 600000,
104+
sauceLabs: {
105+
recordScreenshots: false,
106+
recordVideo: false,
107+
testName:
108+
'Raven.js' +
109+
(process.env.TRAVIS_JOB_NUMBER ? ' #' + process.env.TRAVIS_JOB_NUMBER : ''),
110+
public: 'public'
111+
}
112+
});
113+
config.set(testConfig);
114+
};

karma.unit.config.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var commonConfig = require('./karma.config');
2+
3+
var testFiles = ['test/globals.js', 'build/raven.test.js'];
4+
5+
module.exports = function(config) {
6+
var testConfig = Object.assign(
7+
{},
8+
commonConfig,
9+
{files: testFiles},
10+
{logLevel: config.LOG_INFO}
11+
);
12+
config.set(testConfig);
13+
};

package.json

+15-5
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@
1919
"precommit": "lint-staged",
2020
"publish": "npm run test && grunt publish",
2121
"test": "npm run lint && npm run test:size && grunt build.test && npm run test:unit && npm run test:integration && npm run test:typescript",
22-
"test:unit": "mocha-chrome test/index.html",
23-
"test:integration": "mocha-chrome test/integration/index.html --chrome-flags '[\"--disable-web-security\"]' --ignore-resource-errors --ignore-exceptions",
22+
"test:karma:unit": "karma start karma.unit.config.js",
23+
"test:karma:integration": "karma start karma.integration.config.js ",
24+
"test:karma:sauce": "karma start karma.sauce.config.js ",
25+
"test:unit": "npm run test:karma:unit -- --single-run",
26+
"test:integration": "npm run test:karma:integration -- --single-run",
2427
"test:typescript": "tsc --noEmit --noImplicitAny typescript/raven-tests.ts",
25-
"test:ci": "npm run lint && grunt test:ci",
28+
"test:ci": "npm run lint && grunt test:ci && npm run test:karma:sauce",
2629
"test:size": "grunt dist && bundlesize"
2730
},
2831
"devDependencies": {
@@ -45,12 +48,19 @@
4548
"grunt-gitinfo": "^0.1.7",
4649
"grunt-release": "^0.13.0",
4750
"grunt-s3": "0.2.0-alpha.3",
48-
"grunt-saucelabs": "^9.0.0",
4951
"grunt-sri": "mattrobenolt/grunt-sri#pretty",
5052
"husky": "^0.14.3",
53+
"karma": "^1.7.1",
54+
"karma-chai": "^0.1.0",
55+
"karma-chrome-launcher": "^2.2.0",
56+
"karma-failed-reporter": "0.0.3",
57+
"karma-firefox-launcher": "^1.0.1",
58+
"karma-mocha": "^1.3.0",
59+
"karma-mocha-reporter": "^2.2.4",
60+
"karma-sauce-launcher": "^1.2.0",
61+
"karma-sinon": "^1.0.5",
5162
"lint-staged": "^4.0.4",
5263
"mocha": "^3.5.0",
53-
"mocha-chrome": "^0.2.1",
5464
"prettier": "^1.6.1",
5565
"proxyquireify": "^3.0.2",
5666
"sinon": "^3.2.1",

test/globals.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
window.__DEV__ = true;
2+
__DEV__ = true;

0 commit comments

Comments
 (0)