Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing/sauce labs integration #1374

Merged
merged 23 commits into from Dec 29, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6c8871c
Add a karma task for Chrome
alexstrat Nov 23, 2013
8b21db0
Add browser tests to test task
alexstrat Nov 23, 2013
205a04f
Add karma tests run on saucelabs
alexstrat Nov 24, 2013
ac9cb4a
Make travis run the tests on saucelabs (TODO: fill secure tokens)
alexstrat Nov 24, 2013
c38e214
`npm test` leads to `grunt test:node`
alexstrat Nov 24, 2013
cc1ba46
Add `test` task to tests tasks
alexstrat Nov 24, 2013
24b141e
grab grunt-karma@0.7.2 from npm
alexstrat Dec 7, 2013
3513b13
Add concat:tests for use in browsers
ichernev Dec 9, 2013
8a57d61
Use accumulated tests from global var in test/browser
ichernev Dec 11, 2013
87238c4
Add environment variables for sauce-labs in Grunt task
ichernev Dec 24, 2013
2f852e2
Add encrypted sauce-labs user/pass in .travis.yml
ichernev Dec 24, 2013
77af2b0
Add Firefox to karma browsers
ichernev Dec 25, 2013
1ad6a9e
Add missing karma launchers to package.json
ichernev Dec 25, 2013
aa8699d
Don't lint auxiliary test fragments
ichernev Dec 25, 2013
980e5d8
.gitignore min/tests.js and sauce_connect.log
ichernev Dec 27, 2013
914ec13
Make firefox a separate karma launcher
ichernev Dec 27, 2013
8bc02f7
Use dots reporter for sauce
ichernev Dec 27, 2013
f44ce42
Workaround for safari bug
ichernev Dec 27, 2013
3359c91
Get rid of console.log in tests
ichernev Dec 27, 2013
b737b15
Add test:server
ichernev Dec 27, 2013
c027289
Fix IE8 bug
ichernev Dec 27, 2013
893ea4f
Make jshint happy
ichernev Dec 28, 2013
af76196
Update sauce access key
ichernev Dec 29, 2013
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -2,3 +2,5 @@ node_modules/
.DS_Store .DS_Store
min/moment+customlangs.js min/moment+customlangs.js
min/moment+customlangs.min.js min/moment+customlangs.min.js
min/tests.js
sauce_connect.log
8 changes: 8 additions & 0 deletions .travis.yml
@@ -1,5 +1,13 @@
language: node_js language: node_js
node_js: node_js:
- 0.8 - 0.8

env:
global:
- secure: "CIzz5komT5c6Y8EoOhYo4CvV8ryQ78gfmZQgSKe2cTeUJU0Hr/kxqqe2W0LYx8bkCqJbuzZQ4Awh6drD+03jCqrHN1r4YHoX61eVnqe2ijAhyRh6i45CzjiUlKROTztFU9mDNAOQpOhItE1Zjj3oL0F/b6AC8UKIRTcHuSOPD34="
- secure: "EhJqzT4RueTZ85zbM3MhY6Ziut2t220UsABIwLSWDTgNyn3Kiqx+Z6Lc0YMm1XDe2Srxj3EY77ujzkMp8oYEc5RGW+ZpbJlCyZjNceb/ntb6RuPqXd7ZnE9Ir1cyudCHus8XIBiXWKKVTnPUw6J+ySXyigoi1rz2G5j4guzXXJ0="

before_script: before_script:
- npm install -g grunt-cli - npm install -g grunt-cli

script: grunt build:travis
109 changes: 104 additions & 5 deletions Gruntfile.js
Expand Up @@ -19,8 +19,87 @@ module.exports = function (grunt) {
langs: { langs: {
src: 'lang/*.js', src: 'lang/*.js',
dest: 'min/langs.js' dest: 'min/langs.js'
},
tests: {
src: [
'test/browser-prefix.js',
'test/moment/*.js',
'test/lang/*.js',
'test/browser-suffix.js'
],
dest: 'min/tests.js'
}
},
env : {
sauceLabs : (grunt.file.exists('.sauce-labs.creds') ?
grunt.file.readJSON('.sauce-labs.creds') : {})
},
karma : {
options: {
frameworks: ['nodeunit'],
files: [
'min/moment-with-langs.js',
'min/tests.js',
'test/browser.js'
],
sauceLabs: {
startConnect: true,
testName: 'MomentJS'
},
customLaunchers: {
sl_chrome_win_xp: {
base: 'SauceLabs',
browserName: 'chrome',
platform: 'Windows XP'
},
sl_ie9_win7: {
base: 'SauceLabs',
browserName: 'internet explorer',
platform: 'Windows 7',
version: '9'
},
sl_ie8_win7: {
base: 'SauceLabs',
browserName: 'internet explorer',
platform: 'Windows 7',
version: '8'
},
sl_ff_linux: {
base: 'SauceLabs',
browserName: 'firefox',
platform: 'Linux'
},
sl_safari_osx: {
base: 'SauceLabs',
browserName: 'safari',
platform: 'OS X 10.8'
}
}
},
server: {
browsers: []
},
chrome: {
singleRun: true,
browsers: ['Chrome']
},
firefox: {
singleRun: true,
browsers: ['Firefox']
},
sauce: {
options: {reporters: ['dots']},
singleRun: true,
browsers: [
'sl_chrome_win_xp',
'sl_ie9_win7',
'sl_ie8_win7',
'sl_ff_linux',
'sl_safari_osx'
]
} }
}, },

uglify : { uglify : {
target: { target: {
files: { files: {
Expand All @@ -43,10 +122,13 @@ module.exports = function (grunt) {
} }
}, },
nodeunit : { nodeunit : {
all : ["test/**/*.js"] all : ["test/moment/**/*.js", "test/lang/**/*.js"]
}, },
jshint: { jshint: {
all: ["Gruntfile.js", "moment.js", "lang/**/*.js", "test/**/*.js"], all: [
"Gruntfile.js", "moment.js", "lang/**/*.js", "test/**/*.js",
"!test/browser*.js"
],
options: { options: {
"node" : true, "node" : true,
"browser" : true, "browser" : true,
Expand All @@ -71,6 +153,7 @@ module.exports = function (grunt) {
"sub" : true, "sub" : true,
"strict" : false, "strict" : false,
"white" : true, "white" : true,
"es3" : true,
"globals": { "globals": {
"define": false "define": false
} }
Expand Down Expand Up @@ -105,12 +188,28 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-concat'); grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-env');
grunt.loadNpmTasks('grunt-karma');


// Default task. // Default task.
grunt.registerTask('default', ['jshint', 'nodeunit']); grunt.registerTask('default', ['jshint', 'nodeunit']);
grunt.registerTask('test', ['nodeunit']);
//test tasks
grunt.registerTask('test', ['test:node', 'test:browser']);
grunt.registerTask('test:node', ['nodeunit']);
grunt.registerTask('test:server', ['concat', 'embed_languages', 'karma:server']);
grunt.registerTask('test:browser', ['concat', 'embed_languages', 'karma:chrome', 'karma:firefox']);
grunt.registerTask('test:sauce-browser', ['concat', 'embed_languages', 'env:sauceLabs', 'karma:sauce']);
grunt.registerTask('test:travis-sauce-browser', ['concat', 'embed_languages', 'karma:sauce']);

// travis build task
grunt.registerTask('build:travis', [
'jshint', 'test:node', 'test:travis-sauce-browser'
]);


// Task to be run when releasing a new version // Task to be run when releasing a new version
grunt.registerTask('release', ['jshint', 'nodeunit', 'concat', grunt.registerTask('release', [
'embed_languages', 'component', 'uglify']); 'jshint', 'nodeunit', 'concat', 'embed_languages',
'component', 'uglify'
]);
}; };
29 changes: 13 additions & 16 deletions min/moment-with-langs.js
Expand Up @@ -62,15 +62,16 @@


// iso 8601 regex // iso 8601 regex
// 0000-00-00 0000-W00 or 0000-W00-0 + T + 00 or 00:00 or 00:00:00 or 00:00:00.000 + +00:00 or +0000 or +00) // 0000-00-00 0000-W00 or 0000-W00-0 + T + 00 or 00:00 or 00:00:00 or 00:00:00.000 + +00:00 or +0000 or +00)
isoRegex = /^\s*\d{4}-(?:(\d\d-\d\d)|(W\d\d$)|(W\d\d-\d)|(\d\d\d))((T| )(\d\d(:\d\d(:\d\d(\.\d+)?)?)?)?([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?$/, isoRegex = /^\s*(?:[+-]\d{6}|\d{4})-(?:(\d\d-\d\d)|(W\d\d$)|(W\d\d-\d)|(\d\d\d))((T| )(\d\d(:\d\d(:\d\d(\.\d+)?)?)?)?([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?$/,


isoFormat = 'YYYY-MM-DDTHH:mm:ssZ', isoFormat = 'YYYY-MM-DDTHH:mm:ssZ',


isoDates = [ isoDates = [
'YYYY-MM-DD', ['YYYYYY-MM-DD', /[+-]\d{6}-\d{2}-\d{2}/],
'GGGG-[W]WW', ['YYYY-MM-DD', /\d{4}-\d{2}-\d{2}/],
'GGGG-[W]WW-E', ['GGGG-[W]WW-E', /\d{4}-W\d{2}-\d/],
'YYYY-DDD' ['GGGG-[W]WW', /\d{4}-W\d{2}/],
['YYYY-DDD', /\d{4}-\d{3}/]
], ],


// iso time formats and regexes // iso time formats and regexes
Expand Down Expand Up @@ -366,7 +367,7 @@
// left zero fill a number // left zero fill a number
// see http://jsperf.com/left-zero-filling for performance comparison // see http://jsperf.com/left-zero-filling for performance comparison
function leftZeroFill(number, targetLength, forceSign) { function leftZeroFill(number, targetLength, forceSign) {
var output = Math.abs(number) + '', var output = '' + Math.abs(number),
sign = number >= 0; sign = number >= 0;


while (output.length < targetLength) { while (output.length < targetLength) {
Expand Down Expand Up @@ -1342,20 +1343,20 @@


// date from iso format // date from iso format
function makeDateFromString(config) { function makeDateFromString(config) {
var i, var i, l,
string = config._i, string = config._i,
match = isoRegex.exec(string); match = isoRegex.exec(string);


if (match) { if (match) {
config._pf.iso = true; config._pf.iso = true;
for (i = 4; i > 0; i--) { for (i = 0, l = isoDates.length; i < l; i++) {
if (match[i]) { if (isoDates[i][1].exec(string)) {
// match[5] should be "T" or undefined // match[5] should be "T" or undefined
config._f = isoDates[i - 1] + (match[6] || " "); config._f = isoDates[i][0] + (match[6] || " ");
break; break;
} }
} }
for (i = 0; i < 4; i++) { for (i = 0, l = isoTimes.length; i < l; i++) {
if (isoTimes[i][1].exec(string)) { if (isoTimes[i][1].exec(string)) {
config._f += isoTimes[i][0]; config._f += isoTimes[i][0];
break; break;
Expand Down Expand Up @@ -1496,11 +1497,7 @@


//http://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday //http://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
function dayOfYearFromWeeks(year, week, weekday, firstDayOfWeekOfYear, firstDayOfWeek) { function dayOfYearFromWeeks(year, week, weekday, firstDayOfWeekOfYear, firstDayOfWeek) {
// The only solid way to create an iso date from year is to use var d = makeUTCDate(year, 0, 1).getUTCDay(), daysToAdd, dayOfYear;
// a string format (Date.UTC handles only years > 1900). Don't ask why
// it doesn't need Z at the end.
var d = new Date(leftZeroFill(year, 6, true) + '-01-01').getUTCDay(),
daysToAdd, dayOfYear;


weekday = weekday != null ? weekday : firstDayOfWeek; weekday = weekday != null ? weekday : firstDayOfWeek;
daysToAdd = firstDayOfWeek - d + (d > firstDayOfWeekOfYear ? 7 : 0); daysToAdd = firstDayOfWeek - d + (d > firstDayOfWeekOfYear ? 7 : 0);
Expand Down
10 changes: 3 additions & 7 deletions moment.js
Expand Up @@ -71,7 +71,7 @@
['YYYY-MM-DD', /\d{4}-\d{2}-\d{2}/], ['YYYY-MM-DD', /\d{4}-\d{2}-\d{2}/],
['GGGG-[W]WW-E', /\d{4}-W\d{2}-\d/], ['GGGG-[W]WW-E', /\d{4}-W\d{2}-\d/],
['GGGG-[W]WW', /\d{4}-W\d{2}/], ['GGGG-[W]WW', /\d{4}-W\d{2}/],
['YYYY-DDD', /\d{4}-\d{3}/], ['YYYY-DDD', /\d{4}-\d{3}/]
], ],


// iso time formats and regexes // iso time formats and regexes
Expand Down Expand Up @@ -367,7 +367,7 @@
// left zero fill a number // left zero fill a number
// see http://jsperf.com/left-zero-filling for performance comparison // see http://jsperf.com/left-zero-filling for performance comparison
function leftZeroFill(number, targetLength, forceSign) { function leftZeroFill(number, targetLength, forceSign) {
var output = Math.abs(number) + '', var output = '' + Math.abs(number),
sign = number >= 0; sign = number >= 0;


while (output.length < targetLength) { while (output.length < targetLength) {
Expand Down Expand Up @@ -1497,11 +1497,7 @@


//http://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday //http://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
function dayOfYearFromWeeks(year, week, weekday, firstDayOfWeekOfYear, firstDayOfWeek) { function dayOfYearFromWeeks(year, week, weekday, firstDayOfWeekOfYear, firstDayOfWeek) {
// The only solid way to create an iso date from year is to use var d = makeUTCDate(year, 0, 1).getUTCDay(), daysToAdd, dayOfYear;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happened here? Seems like a rollback?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ie doesn't parse long years at all. When I wrote the original code the
makeDate functions didn't work with small years (or for some unknown stupid
reason) I wrote the string parsing inside... Stupid idea.
On Dec 27, 2013 9:12 PM, "Isaac Cambron" notifications@github.com wrote:

In moment.js:

@@ -1497,11 +1497,7 @@

 //http://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
 function dayOfYearFromWeeks(year, week, weekday, firstDayOfWeekOfYear, firstDayOfWeek) {
  •    // The only solid way to create an iso date from year is to use
    
  •    // a string format (Date.UTC handles only years > 1900). Don't ask why
    
  •    // it doesn't need Z at the end.
    
  •    var d = new Date(leftZeroFill(year, 6, true) + '-01-01').getUTCDay(),
    
  •        daysToAdd, dayOfYear;
    
  •    var d = makeUTCDate(year, 0, 1).getUTCDay(), daysToAdd, dayOfYear;
    

what happened here?


Reply to this email directly or view it on GitHubhttps://github.com//pull/1374/files#r8575464
.

// a string format (Date.UTC handles only years > 1900). Don't ask why
// it doesn't need Z at the end.
var d = new Date(leftZeroFill(year, 6, true) + '-01-01').getUTCDay(),
daysToAdd, dayOfYear;


weekday = weekday != null ? weekday : firstDayOfWeek; weekday = weekday != null ? weekday : firstDayOfWeek;
daysToAdd = firstDayOfWeek - d + (d > firstDayOfWeekOfYear ? 7 : 0); daysToAdd = firstDayOfWeek - d + (d > firstDayOfWeekOfYear ? 7 : 0);
Expand Down
31 changes: 19 additions & 12 deletions package.json
Expand Up @@ -37,19 +37,26 @@
"type" : "MIT" "type" : "MIT"
} }
], ],
"devDependencies" : { "devDependencies": {
"uglify-js" : "latest", "uglify-js": "latest",
"grunt" : "latest", "grunt": "latest",
"nodeunit" : "latest", "nodeunit": "latest",
"grunt-contrib-jshint" : "latest", "grunt-contrib-jshint": "latest",
"grunt-contrib-nodeunit" : "latest", "grunt-contrib-nodeunit": "latest",
"grunt-contrib-concat" : "latest", "grunt-contrib-concat": "latest",
"grunt-contrib-uglify" : "latest", "grunt-contrib-uglify": "latest",
"grunt-contrib-watch" : "latest", "grunt-contrib-watch": "latest",
"grunt-lib-legacyhelpers" : "latest" "grunt-env": "latest",
}, "grunt-lib-legacyhelpers": "latest",
"grunt-karma": "~0.7.2",
"karma": "~0.11.0",
"karma-chrome-launcher": "latest",
"karma-firefox-launcher": "latest",
"karma-nodeunit": "~0.1.1",
"karma-sauce-launcher": "~0.1"
},
"scripts": { "scripts": {
"test": "grunt" "test": "grunt test:node"
}, },
"ender": "./ender.js", "ender": "./ender.js",
"dojoBuild": "package.js", "dojoBuild": "package.js",
Expand Down
4 changes: 4 additions & 0 deletions test/browser-prefix.js
@@ -0,0 +1,4 @@
(function () {
var global = this,
require = function() { return global.moment; },
exports = global.NPM_TESTS = {};
1 change: 1 addition & 0 deletions test/browser-suffix.js
@@ -0,0 +1 @@
}(this));
3 changes: 3 additions & 0 deletions test/browser.js
@@ -0,0 +1,3 @@
/* global nodeunit */

nodeunit.run(NPM_TESTS);
8 changes: 6 additions & 2 deletions test/moment/create.js
Expand Up @@ -746,8 +746,12 @@ exports.create = {
//can parse other stuff too //can parse other stuff too
test.equal(moment('1999-W37-4 3:30', 'GGGG-[W]WW-E HH:mm').format('YYYY MM DD HH:mm'), '1999 09 16 03:30', "parsing weeks and hours"); test.equal(moment('1999-W37-4 3:30', 'GGGG-[W]WW-E HH:mm').format('YYYY MM DD HH:mm'), '1999 09 16 03:30', "parsing weeks and hours");


// Years less than 100 // In safari, all years before 1300 are shifted back with one day.
ver('0098-06', 'GGGG-WW', "0098 02 03", "small years work", true); // http://stackoverflow.com/questions/20768975/safari-subtracts-1-day-from-dates-before-1300
if (new Date("1300-01-01").getUTCFullYear() === 1300) {
// Years less than 100
ver('0098-06', 'GGGG-WW', "0098 02 03", "small years work", true);
}


test.done(); test.done();
}, },
Expand Down
1 change: 0 additions & 1 deletion test/moment/diff.js
Expand Up @@ -121,7 +121,6 @@ exports.diff = {
"diff across DST" : function (test) { "diff across DST" : function (test) {
var dst = dstForYear(2012), a, b, daysInMonth; var dst = dstForYear(2012), a, b, daysInMonth;
if (!dst) { if (!dst) {
console.log("No DST?");
test.done(); test.done();
return; return;
} }
Expand Down
2 changes: 1 addition & 1 deletion test/moment/is_valid.js
Expand Up @@ -259,5 +259,5 @@ exports.is_valid = {
test.ok(moment("3:25", ["h:mma", "hh:mma", "H:mm", "HH:mm"]).isValid()); test.ok(moment("3:25", ["h:mma", "hh:mma", "H:mm", "HH:mm"]).isValid());


test.done(); test.done();
}, }
}; };