From 669a6aeab446aef81d07b95cf9d6716825224833 Mon Sep 17 00:00:00 2001 From: xuexb Date: Wed, 23 Aug 2017 13:37:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0travis=E5=92=8Csaucelabs?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis.yml | 12 ++++ karma.conf.js => karma.conf.base.js | 4 +- karma.conf.sauce.js | 106 ++++++++++++++++++++++++++++ karma.conf.unit.js | 14 ++++ package.json | 4 +- 5 files changed, 137 insertions(+), 3 deletions(-) create mode 100644 .travis.yml rename karma.conf.js => karma.conf.base.js (99%) create mode 100644 karma.conf.sauce.js create mode 100644 karma.conf.unit.js diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..6f3ec51e --- /dev/null +++ b/.travis.yml @@ -0,0 +1,12 @@ +language: node_js +node_js: + - node +sudo: false +cache: + directories: + - node_modules +script: + - npm run test:cov + - npm run test:sauce +after_script: + - npm install coveralls && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage \ No newline at end of file diff --git a/karma.conf.js b/karma.conf.base.js similarity index 99% rename from karma.conf.js rename to karma.conf.base.js index 25709a18..3ae0cf17 100644 --- a/karma.conf.js +++ b/karma.conf.base.js @@ -43,7 +43,7 @@ sourceFileMap.filter(function (uri) { }); module.exports = function(config) { - config.set({ + return { // base path that will be used to resolve all patterns (eg. files, exclude) basePath: '', @@ -122,5 +122,5 @@ module.exports = function(config) { // if true, Karma captures browsers, runs the tests and exits // 脚本调用请设为 true singleRun: true - }); + }; }; \ No newline at end of file diff --git a/karma.conf.sauce.js b/karma.conf.sauce.js new file mode 100644 index 00000000..52507ad6 --- /dev/null +++ b/karma.conf.sauce.js @@ -0,0 +1,106 @@ +/** + * @file karma配置 + * @author fe.xiaowu@gmail.com + */ + +var base = require('./karma.conf.base.js'); + +var customLaunchers = { + // Safari + sl_ios_safari: { + base: 'SauceLabs', + browserName: 'Safari' + }, + + // 安卓浏览器 + sl_android_4_4: { + base: 'SauceLabs', + browserName: 'android', + version: '4.4' + }, + sl_android_5: { + base: 'SauceLabs', + browserName: 'android', + version: '5' + }, + sl_android_6: { + base: 'SauceLabs', + browserName: 'android', + version: '6' + }, + + // chrome + sl_ios_chrome: { + base: 'SauceLabs', + browserName: 'chrome' + }, + + sl_ie_8: { + base: 'SauceLabs', + browserName: 'internet explorer', + platform: 'Windows 7', + version: '8' + }, + sl_ie_9: { + base: 'SauceLabs', + browserName: 'internet explorer', + platform: 'Windows 7', + version: '9' + }, + sl_ie_10: { + base: 'SauceLabs', + browserName: 'internet explorer', + platform: 'Windows 8', + version: '10' + }, + sl_ie_11: { + base: 'SauceLabs', + browserName: 'internet explorer', + platform: 'Windows 8.1', + version: '11' + }, + + sl_firefox: { + base: 'SauceLabs', + browserName: 'firefox', + platform: 'Windows 7' + } +}; + +// 不支持本地运行 +if (!process.env.TRAVIS) { + console.error('不支持本地运行, 请使用 npm run test!'); + process.exit(1); +} + +// 变量检查 +if (!process.env.SAUCE_USERNAME || !process.env.SAUCE_ACCESS_KEY) { + console.error('---------------'); + console.error('Make sure the SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables are set.'); + console.error('---------------'); + process.exit(1); +} + +module.exports = function (config) { + var options = Object.assign(base(config), { + reporters: ['mocha', 'saucelabs'], + sauceLabs: { + 'testName': 'layui test case', + 'recordVideo': false, + 'recordScreenshots': false, + 'startConnect': false, + 'connectOptions': { + 'no-ssl-bump-domains': 'all' + }, + 'public': 'public', + 'build': process.env.CIRCLE_BUILD_NUM || process.env.SAUCE_BUILD_ID || 'build-' + Date.now(), + 'tunnelIdentifier': process.env.TRAVIS_JOB_NUMBER + }, + customLaunchers: customLaunchers, + browsers: Object.keys(customLaunchers), + captureTimeout: 1000 * 60 * 5, + browserNoActivityTimeout: 1000 * 60 * 5 + }); + + config.set(options); +}; diff --git a/karma.conf.unit.js b/karma.conf.unit.js new file mode 100644 index 00000000..7d3fd56c --- /dev/null +++ b/karma.conf.unit.js @@ -0,0 +1,14 @@ +/** + * @file karma配置 + * @author fe.xiaowu@gmail.com + */ + +const base = require('./karma.conf.base.js'); + +module.exports = function(config) { + const options = Object.assign(base(config), { + + }); + + config.set(options); +}; \ No newline at end of file diff --git a/package.json b/package.json index 068b6ade..62fbfffe 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,9 @@ "main": "layui.js", "license": "MIT", "scripts": { - "test": "karma start karma.conf.js", + "test": "karma start karma.conf.unit.js", "test:cov": "npm test -- --reporters mocha,coverage", + "test:sauce": "karma start karma.conf.sauce.js", "test:watch": "npm test -- --auto-watch --no-single-run" }, "repository": { @@ -32,6 +33,7 @@ "karma-chai-sinon": "^0.1.5", "karma-coverage": "^1.1.1", "karma-mocha": "^1.3.0", + "karma-sauce-launcher": "^1.1.0", "karma-mocha-reporter": "^2.2.3", "karma-phantomjs-launcher": "^1.0.4", "mocha": "^3.2.0",