Skip to content

Commit ee5e0e8

Browse files
committed
unit1
1 parent 6ff3ea1 commit ee5e0e8

19 files changed

+6801
-16
lines changed

.npmignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
*.yml
44
build
55
coverage
6-
dist/Uploader.js.map
7-
dist/Uploader.min.js.gz
6+
dist/uploader.min.js.map
87
samples
98
explorations
109
perf

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
language: node_js
2+
node_js:
3+
- "0.12"
4+
branches:
5+
only:
6+
- master
7+
before_script:
8+
- npm install -g gulp
9+
script: gulp

bower.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
".*",
99
"samples",
1010
"build",
11-
"perf",
1211
"test",
1312
"gulp",
1413
"gulpfile.js",

dist/uploader.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ utils.extend(Uchunk.prototype, {
4141
_event: function (evt, args) {
4242
args = utils.toArray(arguments)
4343
args.unshift(this)
44-
this.ufile.chunkEvent.apply(this.ufile, args)
44+
this.ufile._chunkEvent.apply(this.ufile, args)
4545
},
4646

4747
getParams: function () {
@@ -321,7 +321,7 @@ var uevent = {
321321
this._eventData[name].splice(i, 1)
322322
return false
323323
}
324-
})
324+
}, this)
325325
} else {
326326
this._eventData[name] = []
327327
}
@@ -1236,7 +1236,7 @@ var utils = {
12361236
noop: function () {},
12371237
bind: function (fn, context) {
12381238
return function () {
1239-
return fn.apply(this, arguments)
1239+
return fn.apply(context, arguments)
12401240
}
12411241
},
12421242
preventEvent: function (evt) {

gulpfile.js

Lines changed: 177 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ var uglify = require('gulp-uglify')
77
var concat = require('gulp-concat')
88
var sourcemaps = require('gulp-sourcemaps')
99

10+
var spawn = require('child_process').spawn
11+
var _ = require('./src/utils')
12+
var karma = require('karma').server
13+
1014
var name = 'uploader'
1115
var NAME = name.charAt(0).toUpperCase() + name.substr(1)
1216
var fname = name + '.js'
@@ -50,7 +54,7 @@ gulp.task('scripts', ['eslint'], function() {
5054
.pipe(gulp.dest(paths.dist))
5155
});
5256

53-
gulp.task('miniScripts', ['scripts'], function () {
57+
gulp.task('build', ['scripts'], function () {
5458
return gulp.src(paths.dist + fname)
5559
.pipe(sourcemaps.init())
5660
.pipe(uglify({
@@ -63,8 +67,176 @@ gulp.task('miniScripts', ['scripts'], function () {
6367
.pipe(gulp.dest(paths.dist))
6468
})
6569

66-
gulp.task('watch', function() {
67-
gulp.watch(allFiles, ['scripts']);
68-
});
70+
var karmaBaseConfig = {
71+
frameworks: ['jasmine', 'commonjs'],
72+
files: [
73+
'node_modules/sinon/pkg/sinon-1.17.1.js',
74+
'test/unit/lib/FakeXMLHttpRequestUpload.js',
75+
'src/**/*.js',
76+
'test/unit/specs/**/*.js'
77+
],
78+
preprocessors: {
79+
'src/**/*.js': ['commonjs'],
80+
'test/unit/specs/**/*.js': ['commonjs']
81+
},
82+
singleRun: true
83+
}
84+
85+
gulp.task('unit', function (done) {
86+
var karmaUnitConfig = _.extend({}, karmaBaseConfig, {
87+
browsers: ['Chrome', 'Firefox', 'Safari'],
88+
reporters: ['progress']
89+
})
90+
karma.start(karmaUnitConfig, done)
91+
})
92+
93+
gulp.task('cover', function (done) {
94+
var karmaCoverageConfig = _.extend({}, karmaBaseConfig, {
95+
browsers: ['PhantomJS'],
96+
reporters: ['progress', 'coverage'],
97+
preprocessors: {
98+
'src/**/*.js': ['commonjs', 'coverage'],
99+
'test/unit/specs/**/*.js': ['commonjs']
100+
},
101+
coverageReporter: {
102+
reporters: [
103+
{
104+
type: 'lcov',
105+
subdir: '.'
106+
},
107+
{
108+
type: 'text-summary',
109+
subdir: '.'
110+
}
111+
]
112+
}
113+
})
114+
karma.start(karmaCoverageConfig, done)
115+
})
116+
117+
gulp.task('karma', function (done) {
118+
karma.start(karmaBaseConfig, done)
119+
})
120+
121+
gulp.task('sauce', function (done) {
122+
var customLaunchers = {
123+
sl_chrome: {
124+
base: 'SauceLabs',
125+
browserName: 'chrome',
126+
platform: 'Windows 7'
127+
},
128+
sl_firefox: {
129+
base: 'SauceLabs',
130+
browserName: 'firefox'
131+
},
132+
sl_mac_safari: {
133+
base: 'SauceLabs',
134+
browserName: 'safari',
135+
platform: 'OS X 10.10'
136+
},
137+
138+
sl_ie_10: {
139+
base: 'SauceLabs',
140+
browserName: 'internet explorer',
141+
platform: 'Windows 8',
142+
version: '10'
143+
},
144+
sl_ie_11: {
145+
base: 'SauceLabs',
146+
browserName: 'internet explorer',
147+
platform: 'Windows 8.1',
148+
version: '11'
149+
},
150+
151+
sl_ios_safari: {
152+
base: 'SauceLabs',
153+
browserName: 'iphone',
154+
platform: 'OS X 10.9',
155+
version: '7.1'
156+
},
157+
sl_android: {
158+
base: 'SauceLabs',
159+
browserName: 'android',
160+
platform: 'Linux',
161+
version: '4.2'
162+
}
163+
}
164+
var sauceConfig = _.extend({}, karmaBaseConfig, {
165+
sauceLabs: {
166+
testName: 'uploader unit tests',
167+
recordScreenshots: false,
168+
tunnelIdentifier: process.env.TRAVIS_JOB_NUMBER,
169+
build: process.env.TRAVIS_JOB_ID || Date.now(),
170+
username: 'dolymood',
171+
accessKey: '297fafe2-fa71-4239-9726-5c46dd8a467b'
172+
},
173+
captureTimeout: 300000,
174+
browserNoActivityTimeout: 300000,
175+
browsers: Object.keys(customLaunchers),
176+
customLaunchers: customLaunchers,
177+
reporters: ['progress', 'saucelabs']
178+
})
179+
karma.start(sauceConfig, done)
180+
})
181+
182+
gulp.task('test', ['unit', 'cover'])
183+
184+
gulp.task('testSpecs', function () {
185+
return gulp.src('test/unit/specs/*.js')
186+
.pipe(browserify({
187+
debug: false
188+
}))
189+
.pipe(concat('specs.js', {newLine: ';'}))
190+
.pipe(gulp.dest('test/unit/'))
191+
})
192+
193+
gulp.task('watch', function () {
194+
gulp.watch(allFiles, ['scripts'])
195+
gulp.watch('test/unit/specs/**/*.js', ['testSpecs'])
196+
})
197+
198+
gulp.task('default', ['build', 'test'])
69199

70-
gulp.task('default', ['miniScripts'])
200+
var argv = require('yargs').argv
201+
var versioning = function () {
202+
if (argv.minor) {
203+
return 'minor'
204+
}
205+
if (argv.major) {
206+
return 'major'
207+
}
208+
return 'patch'
209+
}
210+
var bump = require('gulp-bump')
211+
gulp.task('version', ['cover', 'build', 'sauce'], function () {
212+
return gulp.src('./package.json')
213+
.pipe(bump({type: versioning()}))
214+
.pipe(gulp.dest('./'))
215+
})
216+
217+
var git = require('gulp-git')
218+
var tag_version = require('gulp-tag-version')
219+
gulp.task('git', ['version'], function (done) {
220+
var v = require('./package.json').version
221+
gulp.src('./')
222+
.pipe(git.add({args: '-A'}))
223+
.pipe(git.commit('[release] ' + v))
224+
.pipe(tag_version({version: v}))
225+
.on('end', function () {
226+
git.push('origin', 'master', {args: '--tags'})
227+
done()
228+
})
229+
})
230+
231+
gulp.task('npm-publish', ['git'], function (done) {
232+
spawn('npm', ['publish'], {stdio: 'inherit'}).on('close', done)
233+
})
234+
235+
gulp.task('release', ['npm-publish'])
236+
237+
if (process.env.TRAVIS_PULL_REQUEST) {
238+
// pull request
239+
gulp.task('ci', ['cover', 'build'])
240+
} else {
241+
gulp.task('ci', ['cover', 'build', 'sauce'])
242+
}

package.json

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"bugs": "https://github.com/dolymood/Uploader/issues",
2424
"homepage": "https://github.com/dolymood/Uploader",
2525
"scripts": {
26-
"dev": "gulp watch"
26+
"test": "gulp ci"
2727
},
2828
"devDependencies": {
2929
"eslint": "^1.3.1",
@@ -37,6 +37,22 @@
3737
"gulp-browserify": "^0.5.1",
3838
"browserify-versionify": "^1.0.6",
3939

40-
"shell-task": "^1.0.0"
40+
"gulp-tag-version": "^1.3.0",
41+
"gulp-git": "^1.4.0",
42+
"gulp-bump": "^1.0.0",
43+
"yargs": "^3.26.0",
44+
45+
"karma": "^0.13.10",
46+
"karma-jasmine": "^0.3.6",
47+
"karma-phantomjs-launcher": "^0.2.1",
48+
"karma-coverage": "^0.5.2",
49+
"karma-chrome-launcher": "^0.2.0",
50+
"karma-firefox-launcher": "^0.1.6",
51+
"karma-safari-launcher": "^0.1.1",
52+
"karma-ie-launcher": "^0.2.0",
53+
"karma-sauce-launcher": "^0.2.14",
54+
"karma-commonjs": "^0.0.13",
55+
56+
"sinon": "^1.17.1"
4157
}
4258
}

src/chunk.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ utils.extend(Uchunk.prototype, {
3333
_event: function (evt, args) {
3434
args = utils.toArray(arguments)
3535
args.unshift(this)
36-
this.ufile.chunkEvent.apply(this.ufile, args)
36+
this.ufile._chunkEvent.apply(this.ufile, args)
3737
},
3838

3939
getParams: function () {

src/event.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var uevent = {
2828
this._eventData[name].splice(i, 1)
2929
return false
3030
}
31-
})
31+
}, this)
3232
} else {
3333
this._eventData[name] = []
3434
}

src/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var utils = {
1919
noop: function () {},
2020
bind: function (fn, context) {
2121
return function () {
22-
return fn.apply(this, arguments)
22+
return fn.apply(context, arguments)
2323
}
2424
},
2525
preventEvent: function (evt) {

0 commit comments

Comments
 (0)