From 317dd4f63e220a95a1ede4d961afba33eac957de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=23=E4=BA=91=E6=B7=A1=E7=84=B6?= Date: Sat, 21 May 2016 16:41:06 +0800 Subject: [PATCH] blear.utils.string --- .coveralls.yml | 0 .travis.yml | 7 +- karma.conf-cover.js | 1 - karma.conf.js | 166 +++++++++++++++++++++++++++++++++++++++++++- karma.config-gen.js | 146 -------------------------------------- package.json | 12 ++-- readme.md | 13 +++- 7 files changed, 185 insertions(+), 160 deletions(-) create mode 100644 .coveralls.yml delete mode 100644 karma.conf-cover.js delete mode 100644 karma.config-gen.js diff --git a/.coveralls.yml b/.coveralls.yml new file mode 100644 index 0000000..e69de29 diff --git a/.travis.yml b/.travis.yml index d87b367..cce9300 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,7 @@ language: node_js node_js: - 4.0 -before_script: +before_install: + - export CHROME_BIN=chromium-browser - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start -script: - - npm test \ No newline at end of file + - sh -e /etc/init.d/xvfb start \ No newline at end of file diff --git a/karma.conf-cover.js b/karma.conf-cover.js deleted file mode 100644 index 2de8c08..0000000 --- a/karma.conf-cover.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('./karma.config-gen.js')(true); diff --git a/karma.conf.js b/karma.conf.js index 7870985..8bd3d70 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1 +1,165 @@ -module.exports = require('./karma.config-gen.js')(); +/** + * karma 测试配置文件 + * @author ydr.me + * @create 2016-04-20 21:15 + */ + + +'use strict'; + + +var TRAVIS = process.env.TRAVIS; + +// http 服务器 +var httpServer = function (req, res, next) { + next(); +}; + + +module.exports = function (config) { + var browsers = []; + var reporters = ['progress', 'coverage']; + var coverageReporters = [{ + type: 'text-summary' + }]; + + if (TRAVIS) { + browsers = ['Chrome_travis_ci']; + reporters.push('coveralls'); + coverageReporters.push({ + type: 'lcov', + dir: './coverage/' + }); + } else { + browsers = ['Chrome']; + } + + + config.set({ + + // 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: ['jasmine', 'coolie'], + + + client: {}, + + + // list of files / patterns to load in the browser + files: [ + { + // 加载 src 下的原始文件,但不直接引入,使用模块加载器引入 + pattern: './src/**', + included: false + }, + { + // 加载 node_modules 下的原始文件,但不直接引入,使用模块加载器引入 + pattern: './node_modules/blear.*/package.json', + included: false + }, + { + // 加载 node_modules 下的原始文件,但不直接引入,使用模块加载器引入 + pattern: './node_modules/blear.*/src/**', + included: false + }, + { + // 加载 src 下的原始文件,但不直接引入,使用模块加载器引入 + pattern: './test/test.**', + included: false + }, + { + // 加载 test 下的入口文件,但不直接引入,使用模块加载器引入 + pattern: './test/main.js', + included: true + } + ], + + + // list of files to exclude + include: [], + exclude: [], + + + // preprocess matching files before serving them to the browser + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor + preprocessors: { + // 原始模块,需要测试覆盖率 + './src/index.js': ['coverage'] + }, + + + // optionally, configure the reporter + // 覆盖率报告 + coverageReporter: { + reporters: coverageReporters + }, + + + // test results reporter to use + // possible values: 'dots', 'progress' + // available reporters: https://npmjs.org/browse/keyword/karma-reporter + // 报告类型 + reporters: reporters, + + + // 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: false, + + + // start these browsers + // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher + browsers: browsers, + + + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: false, + + + // Concurrency level + // how many browser should be started simultaneous + concurrency: Infinity, + + + customLaunchers: { + Chrome_travis_ci: { + base: 'Chrome', + flags: ['--no-sandbox'] + } + }, + + + middleware: ['httpServer'], + + + // plugins + plugins: ['karma-*', { + 'middleware:httpServer': [ + 'factory', function () { + return httpServer; + } + ] + }] + }); +}; + + + diff --git a/karma.config-gen.js b/karma.config-gen.js deleted file mode 100644 index 952fc7f..0000000 --- a/karma.config-gen.js +++ /dev/null @@ -1,146 +0,0 @@ -/** - * karma 测试配置文件生成 - * @author ydr.me - * @create 2016-04-20 21:15 - */ - - -'use strict'; - - -var fs = require('fs'); -var path = require('path'); - -// http 服务器 -var httpServer = function (req, res, next) { - next(); -}; - - -module.exports = function (coverage) { - var preprocessors = {}; - var reporters = ['progress']; - - if (coverage) { - preprocessors = { - // 原始模块,需要测试覆盖率 - './src/index.js': ['coverage'] - }; - reporters.push('coverage'); - } - - return function (config) { - config.set({ - - // 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: ['jasmine', 'coolie'], - - - client: {}, - - - // list of files / patterns to load in the browser - files: [ - { - // 加载 src 下的原始文件,但不直接引入,使用模块加载器引入 - pattern: './src/**', - included: false - }, - { - // 加载 node_modules 下的原始文件,但不直接引入,使用模块加载器引入 - pattern: './node_modules/blear.*/package.json', - included: false - }, - { - // 加载 node_modules 下的原始文件,但不直接引入,使用模块加载器引入 - pattern: './node_modules/blear.*/src/**', - included: false - }, - { - // 加载 src 下的原始文件,但不直接引入,使用模块加载器引入 - pattern: './test/test.**', - included: false - }, - { - // 加载 test 下的入口文件,但不直接引入,使用模块加载器引入 - pattern: './test/main.js', - included: true - } - ], - - - // list of files to exclude - include: [], - exclude: [], - - - // preprocess matching files before serving them to the browser - // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor - preprocessors: preprocessors, - - - // optionally, configure the reporter - // 覆盖率报告 - coverageReporter: { - type: 'lcov', - dir: './coverage/' - }, - - - // test results reporter to use - // possible values: 'dots', 'progress' - // available reporters: https://npmjs.org/browse/keyword/karma-reporter - // 报告类型 - reporters: reporters, - - - // 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: false, - - - // start these browsers - // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher - browsers: [], - - - // Continuous Integration mode - // if true, Karma captures browsers, runs the tests and exits - singleRun: true, - - - middleware: ['httpServer'], - - - // plugins - plugins: ['karma-*', { - 'middleware:httpServer': [ - 'factory', function () { - return httpServer; - } - ] - }] - }); - }; -}; - - - diff --git a/package.json b/package.json index dab962c..42e57c3 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,11 @@ { "name": "blear.utils.string", - "version": "1.0.1", + "version": "1.0.2", "description": "string utils", "scripts": { "live": "browser-sync start --config bs-config.js", - "test": "node ./node_modules/.bin/karma start --single-run --browsers PhantomJS --reporters progress" + "test": "node ./node_modules/.bin/karma start karma.conf.js --single-run", + "prepublish": "npm test" }, "preferGlobal": false, "bin": {}, @@ -45,12 +46,11 @@ "devDependencies": { "jasmine-core": "^2.4.1", "karma": "^0.13.22", - "karma-coolie": "^2.0.0", + "karma-chrome-launcher": "^1.0.1", + "karma-coolie": "^2.0.1", "karma-coverage": "^0.5.5", "karma-coveralls": "^1.1.2", - "karma-jasmine": "^0.3.8", - "karma-phantomjs-launcher": "^1.0.0", - "phantomjs-prebuilt": "^2.1.7" + "karma-jasmine": "^0.3.8" }, "license": "MIT" } diff --git a/readme.md b/readme.md index 2756ef1..c09be37 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,15 @@ # blear.utils.string -[![Build Status][travis-img]][travis-url] +[![npm module][npm-img]][npm-url] +[![build status][travis-img]][travis-url] +[![coverage][coveralls-img]][coveralls-url] -[travis-img]: https://travis-ci.org/blearjs/blear.utils.string.svg?branch=master +[travis-img]: https://img.shields.io/travis/blearjs/blear.utils.string/master.svg?maxAge=2592000&style=flat-square [travis-url]: https://travis-ci.org/blearjs/blear.utils.string + +[npm-img]: https://img.shields.io/npm/v/blear.utils.string.svg?maxAge=2592000&style=flat-square +[npm-url]: https://www.npmjs.com/package/blear.utils.string + +[coveralls-img]: https://img.shields.io/coveralls/blearjs/blear.utils.string/master.svg?maxAge=2592000&style=flat-square +[coveralls-url]: https://coveralls.io/github/blearjs/blear.utils.string?branch=master +