Skip to content

Commit bd5a43a

Browse files
musienkoyuriyvalorkin
authored andcommitted
fix(karma): fix unit tests across the all supported browsers (#1322)
1 parent 8daa4be commit bd5a43a

14 files changed

+115
-68
lines changed

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ language: node_js
22
node_js:
33
- "6"
44

5+
env:
6+
global:
7+
- SAUCE_USERNAME=valorkin
8+
- SAUCE_ACCESS_KEY=aeaf806e-ad5c-484b-a8fe-4b4b9f54e99a
9+
510
before_install:
611
- export CHROME_BIN=chromium-browser
712
- export DISPLAY=:99.0
@@ -11,6 +16,7 @@ script:
1116
- npm run pretest
1217
- npm run test-coverage
1318
- ./node_modules/.bin/codecov
19+
- npm run test-cross
1420

1521
after_success:
1622
- ./node_modules/.bin/codecov -f coverage/coverage-final.json

demo/src/index-bs4.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<title>Angular2 Bootstrap</title>
55

66
<meta charset="utf-8">
7-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
7+
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=edge">
88
<meta name="description" content="Angular2 Bootstrap">
99
<meta name="viewport" content="width=device-width, initial-scale=1">
1010
<link rel="icon" href="data:;base64,iVBORw0KGgo=">

demo/src/polyfills.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ import 'core-js/es6/reflect';
1818

1919
import 'core-js/es7/reflect';
2020
import 'zone.js/dist/zone';
21+
import 'classlist-polyfill';

karma.conf.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Karma configuration file, see link for more information
22
// https://karma-runner.github.io/0.13/config/configuration-file.html
33

4+
const customLaunchers = require('./scripts/sauce-browsers').customLaunchers;
5+
46
module.exports = function (config) {
57
const configuration = {
68
basePath: '',
@@ -28,8 +30,8 @@ module.exports = function (config) {
2830
environment: 'dev'
2931
},
3032
reporters: config.angularCli && config.angularCli.codeCoverage
31-
? ['progress', 'karma-remap-istanbul']
32-
: ['progress'],
33+
? ['progress', 'karma-remap-istanbul']
34+
: ['progress'],
3335
port: 9876,
3436
colors: true,
3537
logLevel: config.LOG_DEBUG,
@@ -48,5 +50,32 @@ module.exports = function (config) {
4850
configuration.browsers = ['Chrome_travis_ci'];
4951
}
5052

53+
console.log(process.env.SAUCE)
54+
if (process.env.SAUCE) {
55+
if (!process.env.SAUCE_USERNAME || !process.env.SAUCE_ACCESS_KEY) {
56+
console.log('Make sure the SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables are set.');
57+
process.exit(1);
58+
}
59+
60+
configuration.plugins.push(require('karma-sauce-launcher'));
61+
configuration.reporters.push('saucelabs');
62+
configuration.sauceLabs = {
63+
verbose: true,
64+
testName: 'ng2-bootstrap unit tests',
65+
recordScreenshots: false,
66+
username: process.env.SAUCE_USERNAME,
67+
accessKey: process.env.SAUCE_ACCESS_KEY,
68+
connectOptions: {
69+
port: 5757,
70+
logfile: 'sauce_connect.log'
71+
},
72+
public: 'public'
73+
};
74+
configuration.captureTimeout = 0;
75+
configuration.customLaunchers = customLaunchers();
76+
configuration.browsers = Object.keys(configuration.customLaunchers);
77+
configuration.concurrency = 2;
78+
}
79+
5180
config.set(configuration);
5281
};

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
"generate-bs4": "node scripts/generate-bs4.js",
2020
"pretest": "run-s lint build link",
2121
"test": "ng test -sr",
22+
"test-cross": "SAUCE=true ng test -sr",
2223
"test-coverage": "ng test -sr -cc",
2324
"pree2e": "webdriver-manager update",
2425
"e2e": "protractor",
25-
"e2e.saucelabs": "tsc -p ./demo/e2e/ && webdriver-manager update && protractor protractor.saucelabs.conf.js"
26+
"e2e-cross": "SAUCE=true npm run e2e"
2627
},
2728
"main": "bundles/ng2-bootstrap.umd.js",
2829
"module": "index.js",
@@ -63,6 +64,7 @@
6364
"angular-cli": "1.0.0-beta.20-4",
6465
"bootstrap": "3.3.7",
6566
"chokidar-cli": "1.2.0",
67+
"classlist-polyfill": "1.0.3",
6668
"codecov": "1.0.1",
6769
"codelyzer": "^2.0.0-beta.1",
6870
"conventional-changelog-cli": "1.2.0",
@@ -83,6 +85,7 @@
8385
"karma-cli": "1.0.1",
8486
"karma-jasmine": "1.0.2",
8587
"karma-remap-istanbul": "0.2.1",
88+
"karma-sauce-launcher": "1.1.0",
8689
"lite-server": "2.2.2",
8790
"lodash": "4.17.2",
8891
"markdown-loader": "github:valorkin/markdown-loader",

protractor.conf.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
// https://github.com/angular/protractor/blob/master/docs/referenceConf.js
33

44
/*global jasmine */
5-
var SpecReporter = require('jasmine-spec-reporter');
5+
const SpecReporter = require('jasmine-spec-reporter');
6+
const customLaunchers = require('./scripts/sauce-browsers').customLaunchers;
67

7-
exports.config = {
8+
const config = {
89
allScriptsTimeout: 11000,
910
specs: [
1011
'./demo/e2e/**/*.e2e-spec.ts'
@@ -31,3 +32,16 @@ exports.config = {
3132
jasmine.getEnv().addReporter(new SpecReporter());
3233
}
3334
};
35+
36+
if (process.env.SAUCE) {
37+
if (!process.env.SAUCE_USERNAME || !process.env.SAUCE_ACCESS_KEY) {
38+
console.log('Make sure the SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables are set.');
39+
process.exit(1);
40+
}
41+
42+
delete config.capabilities;
43+
config.multiCapabilities = customLaunchers();
44+
// todo: O`Really?
45+
config.baseUrl = 'http://valor-software.com/ng2-bootstrap/';
46+
}
47+
exports.config = config;

protractor.saucelabs.conf.js

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

scripts/helpers.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
exports.fireEvent = function (target, action) {
2+
var event = document.createEvent('Event');
3+
event.initEvent(action, false, true);
4+
target.dispatchEvent(event);
5+
};

scripts/sauce-browsers.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module.exports.customLaunchers = function customLaunchers() {
2+
return {
3+
sl_chrome: {
4+
base: 'SauceLabs',
5+
browserName: 'chrome',
6+
version: "52.0",
7+
platform: "Windows 7"
8+
},
9+
sl_firefox: {
10+
base: 'SauceLabs',
11+
browserName: 'Firefox',
12+
platform: 'Windows 7',
13+
version: '46.0'
14+
},
15+
sl_ie_9: {
16+
base: 'SauceLabs',
17+
browserName: 'internet explorer',
18+
version: "9.0",
19+
platform: "Windows 7"
20+
},
21+
sl_ie_11: {
22+
base: 'SauceLabs',
23+
browserName: 'internet explorer',
24+
version: "11.0",
25+
platform: "Windows 8.1"
26+
}
27+
};
28+
};
29+

src/spec/collapse.directive.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ describe('Directive: Collapse', () => {
124124
context.isHidden = false;
125125
fixture.detectChanges();
126126
let heightWithDynamic = element.offsetHeight;
127-
expect(heightWithDynamic).toBeGreaterThan(heightWithoutDynamic);
127+
expect(heightWithDynamic).toBeGreaterThanOrEqual(heightWithoutDynamic);
128128
});
129129

130130
it('should shrink accordingly when content size inside collapse decreases', () => {
@@ -135,7 +135,7 @@ describe('Directive: Collapse', () => {
135135
context.isHidden = true;
136136
fixture.detectChanges();
137137
let heightWithoutDynamic = element.offsetHeight;
138-
expect(heightWithoutDynamic).toBeLessThan(heightWithDynamic);
138+
expect(heightWithoutDynamic).toBeLessThanOrEqual(heightWithDynamic);
139139
});
140140
});
141141

0 commit comments

Comments
 (0)