-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: travis, lint, baidu/chrome/qq/uc
- Loading branch information
Showing
7 changed files
with
172 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"env": { | ||
"amd": true | ||
}, | ||
"rules": { | ||
"no-extend-native": "off", | ||
"indent": ["error", 4], | ||
"semi": ["error", "always"] | ||
}, | ||
"extends": "standard" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
language: node_js | ||
sudo: required | ||
dist: trusty | ||
node_js: | ||
- lts/* | ||
env: | ||
- BROWSER=ChromeHeadless | ||
addons: | ||
chrome: stable | ||
cache: | ||
directories: | ||
- "node_modules" | ||
script: | ||
- apm install | ||
- npm run lint | ||
- npm run ci | ||
before_install: | ||
- google-chrome-stable --headless --disable-gpu --remote-debugging-port=9222 http://localhost & |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,75 @@ | ||
// Karma configuration | ||
// Generated on Wed Apr 04 2018 00:03:37 GMT+0800 (CST) | ||
|
||
module.exports = function(config) { | ||
config.set({ | ||
module.exports = function (config) { | ||
config.set({ | ||
|
||
// base path that will be used to resolve all patterns (eg. files, exclude) | ||
basePath: './', | ||
// base path that will be used to resolve all patterns (eg. files, exclude) | ||
basePath: './', | ||
|
||
// frameworks to use | ||
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter | ||
frameworks: ['mocha', 'requirejs', 'chai-as-promised', 'chai-sinon'], | ||
|
||
// frameworks to use | ||
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter | ||
frameworks: ['mocha', 'requirejs', 'chai-as-promised', 'chai-sinon'], | ||
|
||
|
||
// list of files / patterns to load in the browser | ||
files: [ | ||
'test-main.js', | ||
// list of files / patterns to load in the browser | ||
files: [ | ||
'test-main.js', | ||
{pattern: 'src/**/*.js', included: false}, | ||
{pattern: 'amd_modules/**/*.js', included: false}, | ||
{pattern: 'test/**/*.js', included: false} | ||
], | ||
|
||
|
||
// list of files to exclude | ||
exclude: [ | ||
'**/*.swp' | ||
], | ||
|
||
|
||
// preprocess matching files before serving them to the browser | ||
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor | ||
preprocessors: { | ||
// source files, that you wanna generate coverage for | ||
// do not include tests or libraries | ||
// (these files will be instrumented by Istanbul) | ||
'src/**/*.js': ['coverage'] | ||
}, | ||
|
||
|
||
// test results reporter to use | ||
// possible values: 'dots', 'progress' | ||
// available reporters: https://npmjs.org/browse/keyword/karma-reporter | ||
reporters: ['mocha'], | ||
coverageReporter: { | ||
reporters: [ | ||
{ | ||
type: 'text-summary' | ||
}, { | ||
type: 'lcov', | ||
dir: 'coverage/' | ||
} | ||
] | ||
}, | ||
|
||
|
||
// web server port | ||
port: 9876, | ||
|
||
|
||
// enable / disable colors in the output (reporters and logs) | ||
colors: true, | ||
|
||
|
||
// level of logging | ||
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG | ||
logLevel: config.LOG_INFO, | ||
|
||
|
||
// enable / disable watching file and executing tests whenever any file changes | ||
autoWatch: true, | ||
|
||
|
||
// start these browsers | ||
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher | ||
browsers: ['ChromeHeadless'], | ||
|
||
|
||
// Continuous Integration mode | ||
// if true, Karma captures browsers, runs the tests and exits | ||
singleRun: true, | ||
|
||
// Concurrency level | ||
// how many browser should be started simultaneous | ||
concurrency: Infinity | ||
}) | ||
} | ||
], | ||
|
||
// list of files to exclude | ||
exclude: [ | ||
'**/*.swp' | ||
], | ||
|
||
// preprocess matching files before serving them to the browser | ||
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor | ||
preprocessors: { | ||
// source files, that you wanna generate coverage for | ||
// do not include tests or libraries | ||
// (these files will be instrumented by Istanbul) | ||
'src/**/*.js': ['coverage'] | ||
}, | ||
|
||
// test results reporter to use | ||
// possible values: 'dots', 'progress' | ||
// available reporters: https://npmjs.org/browse/keyword/karma-reporter | ||
reporters: ['mocha'], | ||
coverageReporter: { | ||
reporters: [ | ||
{ | ||
type: 'text-summary' | ||
}, { | ||
type: 'lcov', | ||
dir: 'coverage/' | ||
} | ||
] | ||
}, | ||
|
||
// web server port | ||
port: 9876, | ||
|
||
// enable / disable colors in the output (reporters and logs) | ||
colors: true, | ||
|
||
// level of logging | ||
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG | ||
logLevel: config.LOG_INFO, | ||
|
||
// enable / disable watching file and executing tests whenever any file changes | ||
autoWatch: true, | ||
|
||
// start these browsers | ||
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher | ||
browsers: ['ChromeHeadless'], | ||
|
||
// Continuous Integration mode | ||
// if true, Karma captures browsers, runs the tests and exits | ||
singleRun: true, | ||
|
||
// Concurrency level | ||
// how many browser should be started simultaneous | ||
concurrency: Infinity | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,36 @@ | ||
define(function() { | ||
define(function () { | ||
var traits = { | ||
// OS | ||
isAndroid: /android/i, | ||
isIOS: /(iPhone|iPod|iPad)/, | ||
isWinPhone: /Windows Phone ([\d.]+)/, | ||
|
||
function Browser () { | ||
this._name = ''; | ||
// Browser | ||
isBaiduBox: /baiduboxapp/, | ||
isBaiduBoxLite: /lite baiduboxapp/, | ||
isQQ: /QQBrowser/, | ||
isBaiduBrowser: /baidubrowser/, | ||
isSearchCraft: /SearchCraft/i, | ||
isUC: /UCBrowser/, | ||
isChromeDesktop: /Chrome\//, | ||
isChromeMobile: /Chrome\/(\S*) Mobile/, | ||
isSogouMobile: /SogouMobileBrowser/, | ||
isMiuiBrowser: /MiuiBrowser\/(\S*)/ | ||
}; | ||
|
||
Browser.prototype._getBrowserName = function (ua) { | ||
var ua = ua || navigator.userAgent; | ||
if (ua.indexOf('QQBrowser') > -1) { | ||
this._name = 'qq'; | ||
} | ||
} | ||
function factory (userAgentString) { | ||
var ua = { | ||
use: factory | ||
}; | ||
|
||
return Browser; | ||
Object.keys(traits).forEach(function (key) { | ||
var regexp = traits[key]; | ||
ua[key] = function () { | ||
return regexp.test(userAgentString); | ||
}; | ||
}); | ||
return ua; | ||
}; | ||
|
||
}); | ||
return factory(navigator.userAgent); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"rules": { | ||
"no-unused-expressions": "off", | ||
"no-new": "off", | ||
"standard/no-callback-literal": "off" | ||
}, | ||
"globals": { | ||
"expect": true, | ||
"sinon": true | ||
}, | ||
"env": { | ||
"mocha": true | ||
}, | ||
"plugins": [ | ||
"mocha" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
define(['src/index'], function (Browser) { | ||
describe('Browser', function () { | ||
describe('new', function () { | ||
it('should get qq browser name', function () { | ||
var ua = 'Mozilla/5.0 (Linux; U; Android 4.4.4; zh-cn; HUAWEI C8818 Build/HuaweiC8818) AppleWebKit/537.36 (KHTML, like Gecko)Version/4.0 MQQBrowser/5.8 Mobile Safari/537.36'; | ||
var browser = new Browser(); | ||
browser._getBrowserName(ua); | ||
expect(browser._name).to.equal('qq'); | ||
}); | ||
define(['src/index'], function (UA) { | ||
var qqAndroid = 'Mozilla/5.0 (Linux; U; Android 4.4.4; zh-cn; HUAWEI C8818 Build/HuaweiC8818) AppleWebKit/537.36 (KHTML, like Gecko)Version/4.0 MQQBrowser/5.8 Mobile Safari/537.36'; | ||
var qqIOS = 'Mozilla/5.0 (iPhone 84; CPU iPhone OS 10_3_3 like Mac OS X) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.0 MQQBrowser/7.8.0 Mobile/14G60 Safari/8536.25 MttCustomUA/2 QBWebViewType/1 WKType/1'; | ||
var ucAndoird = 'Mozilla/5.0 (Linux; U; Android 7.0; zh-CN; ZUK Z2121 Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/40.0.2214.89 UCBrowser/11.6.8.952 Mobile Safari/537.36'; | ||
|
||
describe('UA', function () { | ||
it('should detect chrome', function () { | ||
expect(UA.isChromeDesktop()).to.equal(true); | ||
expect(UA.isQQ()).to.equal(false); | ||
expect(UA.isUC()).to.equal(false); | ||
}); | ||
it('should detect QQ browser', function () { | ||
expect(UA.use(qqAndroid).isQQ()).to.equal(true); | ||
expect(UA.use(qqIOS).isQQ()).to.equal(true); | ||
}); | ||
it('should detect UC browser', function () { | ||
expect(UA.use(ucAndoird).isUC()).to.equal(true); | ||
}); | ||
}); | ||
}); |