Skip to content
This repository was archived by the owner on Jun 27, 2020. It is now read-only.

Commit 454f208

Browse files
authored
Merge pull request #9 from markandey/saucelabs
Add saucelab tests.
2 parents 0b90ba3 + a99ca6f commit 454f208

File tree

7 files changed

+337
-34
lines changed

7 files changed

+337
-34
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
language: node_js
22
node_js:
33
- "6"
4+
45
addons:
56
firefox: "49.0"
7+
sauce_connect:
8+
username: "date-time-format-timezone"
9+
access_key: "***********************"
610
install:
711
- npm install
812
before_script:

Gruntfile.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ module.exports = function(grunt) {
8181
],
8282
dest: 'build/browserified/test/test-complete.js'
8383
},
84+
sauceLabTest: {
85+
src: [
86+
'build/test/test-saucelabs.js'
87+
],
88+
dest: 'build/browserified/test/test-saucelabs.js'
89+
},
8490
specificTimezone: {
8591
src: [
8692
'build/test/test-specific-zone-only.js'
@@ -158,6 +164,14 @@ module.exports = function(grunt) {
158164
}, {
159165
src: 'build/browserified/test/test-specific-zone-specific-locale.js'
160166
}]
167+
},
168+
saucelabsTest: {
169+
configFile: 'karma.conf.saucelabs.js',
170+
files: [{
171+
src: 'node_modules/intl/dist/Intl.complete.js'
172+
}, {
173+
src: 'build/browserified/test/test-saucelabs.js'
174+
}]
161175
}
162176
},
163177
mochaTest: {
@@ -207,9 +221,17 @@ module.exports = function(grunt) {
207221
pkg: grunt.file.readJSON('package.json')
208222
});
209223

224+
function allBut(task, subtask) {
225+
return Object.keys(grunt.config.get(task)).
226+
filter(sub => subtask !== sub).
227+
map(sub => [task, sub].join(':'));
228+
}
229+
210230
grunt.loadTasks('tasks');
211231
grunt.registerTask('build', ['clean:build', 'eslint', 'babel', 'copy', 'gen-package', 'browserify', 'uglify']);
212-
grunt.registerTask('test', ['mochaTest', 'karma']);
232+
233+
grunt.registerTask('test', process.env.TRAVIS ? ['mochaTest', 'karma'] : ['mochaTest'].concat(allBut('karma', 'saucelabsTest')));
234+
213235
grunt.registerTask('default', ['build', 'test']);
214236
grunt.loadNpmTasks('grunt-contrib-copy');
215237
grunt.loadNpmTasks('grunt-contrib-clean');

karma.conf.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
11
// Karma configuration
22

33
module.exports = function(config) {
4-
const customLaunchers = {
5-
sl_ie_9: {
6-
base: 'SauceLabs',
7-
browserName: 'internet explorer',
8-
version: '9'
9-
},
10-
sl_safari: {
11-
base: 'SauceLabs',
12-
browserName: 'safari',
13-
version: '9'
14-
}
15-
};
16-
174
config.set({
185
basePath: '',
196
plugins: ['karma-chrome-launcher',
@@ -29,8 +16,7 @@ module.exports = function(config) {
2916
testName: 'DateTimeFormatTimeZone tests'
3017
},
3118
frameworks: ['mocha'],
32-
customLaunchers: customLaunchers,
33-
reporters: [process.env.TRAVIS ? 'dots' : 'progress', 'saucelabs'],
19+
reporters: [process.env.TRAVIS ? 'dots' : 'progress'],
3420
logLevel: 'ERROR',
3521
colors: true,
3622
browserNoActivityTimeout: 100000,

karma.conf.saucelabs.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Karma configuration
2+
3+
module.exports = function(config) {
4+
const customLaunchers = {
5+
sl_ie_11: {
6+
base: 'SauceLabs',
7+
browserName: 'internet explorer',
8+
version: '11'
9+
},
10+
sl_safari: {
11+
base: 'SauceLabs',
12+
browserName: 'safari',
13+
version: '10'
14+
},
15+
sl_edge: {
16+
base: 'SauceLabs',
17+
browserName: 'microsoftedge'
18+
}
19+
};
20+
21+
config.set({
22+
basePath: '',
23+
plugins: ['karma-chrome-launcher',
24+
'karma-firefox-launcher',
25+
'karma-phantomjs-launcher',
26+
'karma-sauce-launcher',
27+
'karma-mocha'
28+
],
29+
mochaReporter: {
30+
output: 'noFailures'
31+
},
32+
sauceLabs: {
33+
testName: 'DateTimeFormatTimeZone tests'
34+
},
35+
frameworks: ['mocha'],
36+
customLaunchers: customLaunchers,
37+
reporters: [process.env.TRAVIS ? 'dots' : 'progress', 'saucelabs'],
38+
logLevel: 'ERROR',
39+
colors: true,
40+
browserNoActivityTimeout: 100000,
41+
port: 9999,
42+
singleRun: true,
43+
browsers: ['sl_edge', 'sl_ie_11', 'sl_safari']
44+
});
45+
};

src/code/polyfill.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,24 @@ export default function polyfill(globalSpace) {
3939
const timeZone = (options && options.timeZone) || 'UTC';
4040

4141
if (options === undefined) {
42-
// options is provided. this means
43-
// we dont need to format a arbitraray timezone
42+
// options is not provided. this means
43+
// we don't need to format arbitrary timezone
4444
super(locale, options);
4545

4646
return;
4747
}
4848

4949
if (checkTimeZoneSupport(timeZone)) {
50-
// native method has support for timezone. no pollifyll logic needed.
50+
// native method has support for timezone. no polyfill logic needed.
5151
super(locale, options);
5252

5353
return;
5454
}
5555

5656
const timeZoneData = gIntl._timeZoneData.get(timeZone);
5757

58+
// check if we have timezone data for this timezone
5859
if (!timeZoneData) {
59-
// check if we have timezone data for this timezone
6060
throw new RangeError(`invalid time zone in DateTimeFormat(): ${timeZone}`);
6161
}
6262

@@ -70,14 +70,14 @@ export default function polyfill(globalSpace) {
7070
if (options.timeZoneName !== undefined) {
7171
// We need to include timeZoneName in date format.
7272
// Check if we have locale data to able to do that.
73-
if (!(gIntl._localeData.get(resolvedLocale) && // availlabillity of localedata
74-
Intl._metaZoneData.get(timeZone))) { // availlabillity of metaZone for this timeZone
73+
if (!(gIntl._localeData.get(resolvedLocale) && // availability of localedata
74+
Intl._metaZoneData.get(timeZone))) { // availability of metaZone for this timeZone
7575
throw new RangeError(`unsupported value "${options.timeZoneName}" for timeZone ${timeZone}. requires locale data for ${resolvedLocale}`);
7676
}
7777
}
7878

79-
// to minimize pollution. everything we need to perform polyfill is wraped under one object.
80-
this._dateTimeFromatPolyfill = {
79+
// to minimize pollution everything we need to perform polyfill is wrapped under one object.
80+
this._dateTimeFormatPolyfill = {
8181
optionTimeZone: timeZone,
8282
optionTimeZoneName: options.timeZoneName,
8383
timeZoneData: timeZoneData
@@ -92,7 +92,7 @@ export default function polyfill(globalSpace) {
9292
}
9393

9494
format(date) {
95-
if (!this._dateTimeFromatPolyfill) {
95+
if (!this._dateTimeFormatPolyfill) {
9696
return super.format(date);
9797
}
9898

@@ -104,7 +104,7 @@ export default function polyfill(globalSpace) {
104104
date = new Date(date);
105105
}
106106

107-
const polyfill = this._dateTimeFromatPolyfill;
107+
const polyfill = this._dateTimeFormatPolyfill;
108108
const timeZoneOffsetInfo = getTimeZoneOffsetInfo(polyfill.timeZoneData, date);
109109
const timeZoneOffset = timeZoneOffsetInfo.offset * 60000;
110110
const shiftedDate = new Date(date.getTime() + timeZoneOffset); // We need to format time by offseting it
@@ -114,7 +114,7 @@ export default function polyfill(globalSpace) {
114114

115115
if (doNeedToReplaceTimeZoneName) {
116116
/*
117-
Since our timeshifted native format will only return UTC timeZone Name e.g. "1/31/2017, 6:39:55 PM GMT"
117+
Since our timeshifted native format will only return UTC timeZone Name e.g. "1/31/2017, 6:39:55 PM GMT"
118118
We have to replace GMT that with actual timezone name. like "Pacific Standard Time"
119119
This is achived by replacing timeZoneNameUTC with timeZoneName
120120
*/
@@ -147,11 +147,11 @@ export default function polyfill(globalSpace) {
147147
}
148148

149149
resolvedOptions() {
150-
if (this._dateTimeFromatPolyfill) {
150+
if (this._dateTimeFormatPolyfill) {
151151
// since we have altered timezone option for super.
152152
// we need to correct that before returing.
153153
const options = jsonClone(super.resolvedOptions());
154-
options.timeZone = this._dateTimeFromatPolyfill.optionTimeZone;
154+
options.timeZone = this._dateTimeFormatPolyfill.optionTimeZone;
155155

156156
return options;
157157
}
@@ -214,7 +214,7 @@ export default function polyfill(globalSpace) {
214214
if (options.day === undefined &&
215215
options.month === undefined &&
216216
options.year === undefined) {
217-
// LocaleDateString must contain one or more from day month & year
217+
// LocaleDateString must contain one or more from day, month & year
218218
// if none is specified we should fallback to to choose day, month and year
219219
options = jsonClone(options);
220220
options.day = defaultDateOption.day;

test/test-complete.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import polyfill from '../src/code/polyfill.js';
77
import dataLoader from '../src/code/data-loader.js';
88
import tzdataMoonLanding from './test-data/tzdata-moon-nearside.js';
99
import tzdata from '../src/data/tzdata.js';
10-
import locale from '../src/data/locale.js';
10+
import localeData from '../src/data/locale.js';
1111
import metazone from '../src/data/metazone.js';
1212

1313
const isNode = (typeof global !== "undefined" && {}.toString.call(global) === '[object global]');
@@ -18,21 +18,21 @@ dataLoader(myGlobal); // Functions facilitates data loading
1818
polyfill(myGlobal); // Applies polyfill in place
1919
metazone(myGlobal); // Data which maps zoneName to cldr metaNames
2020
tzdata(myGlobal); // Loads timezone iana data in memory
21-
locale(myGlobal); // Loads timezone CLDR data in memory
21+
localeData(myGlobal); // Loads timezone CLDR data in memory
2222
tzdataMoonLanding(myGlobal);
2323

2424
describe('Polyfill with complete package', () => {
2525
describe('DateTimeFormat', () => {
2626
describe('Instanceof integrity', () => {
2727
it('nativedDateTimeFormat instanceof Intl.DateTimeFormat', () => {
28-
const nativedDateTimeFormat = new Intl.DateTimeFormat(locale, {
28+
const nativedDateTimeFormat = new Intl.DateTimeFormat('en', {
2929
timeZone: 'America/Los_Angeles'
3030
});
3131
assert.equal(nativedDateTimeFormat instanceof Intl.DateTimeFormat, true);
3232
});
3333

3434
it('polyfilledDateTimeFormat instanceof Intl.DateTimeFormat', () => {
35-
const polyfilledDateTimeFormat = new Intl.DateTimeFormat(locale, {
35+
const polyfilledDateTimeFormat = new Intl.DateTimeFormat('en', {
3636
timeZone: 'Moon/Nearside'
3737
});
3838
assert.equal(polyfilledDateTimeFormat instanceof Intl.DateTimeFormat, true);

0 commit comments

Comments
 (0)