Skip to content

Commit

Permalink
添加浏览器端测试 (#55)
Browse files Browse the repository at this point in the history
* 添加浏览器测试

* 添加静态文件引用, 解决测试时404

* 关闭ie8测试

* 恢复代码

* 添加sauce配置

* 删除sauce配置

* 添加系统配置

* 测试链接sauce

* 删除token

* 添加编译状态图标

* 添加 layui.js 测试用例
  • Loading branch information
xuexb committed Sep 1, 2017
1 parent b644b76 commit 6c2c29c
Show file tree
Hide file tree
Showing 7 changed files with 216 additions and 26 deletions.
12 changes: 5 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
language: node_js
dist: trusty
addons:
chrome: stable
node_js:
- node
#addons:
# sauce_connect: true
dist: trusty
addons:
sauce_connect: true
sudo: false
cache:
directories:
- node_modules
script:
- npm run test:cov
#- npm run test:sauce
after_script:
- npm run test:sauce
after_script:
- npm install coveralls && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
经典模块化前端UI框架
</p>

<p align="center">
<a href="https://travis-ci.org/sentsin/layui"><img alt="Build Status" src="https://img.shields.io/travis/sentsin/layui/master.svg"></a>
<a href="https://saucelabs.com/beta/builds/7e6196205e4f492496203388fc003b65"><img src="https://saucelabs.com/buildstatus/layui" alt="Build Status"></a>
<a href="https://coveralls.io/r/sentsin/layui?branch=master"><img alt="Test Coverage" src="https://img.shields.io/coveralls/sentsin/layui/master.svg"></a>
</p>
<p align="center">
<a href="https://saucelabs.com/beta/builds/7e6196205e4f492496203388fc003b65"><img src="https://saucelabs.com/browser-matrix/layui.svg" alt="Browser Matrix"></a>
</p>

---

Layui 是一款采用自身模块规范编写的情怀型前端UI框架,遵循原生HTML/CSS/JS的书写与组织形式,门槛极低,拿来即用。其外在极简,却又不失饱满的内在,体积轻盈,组件丰盈,从核心代码到API的每一处细节都经过精心雕琢,非常适合界面的快速开发。Layui 首个版本发布于2016年金秋,她区别于那些基于MVVM底层的UI框架,却并非逆道而行,而是信奉返璞归真之道。准确地说,她更多是为服务端程序员量身定做,你无需涉足各种前端工具的复杂配置,只需面对浏览器本身,让一切你所需要的元素与交互,从这里信手拈来。
Expand Down
11 changes: 10 additions & 1 deletion karma.conf.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,16 @@ module.exports = function (config) {


// list of files / patterns to load in the browser
files: sourceFileMap.concat('test/**/*.js'),
files: sourceFileMap.concat('test/**/*.js').concat({
pattern: 'src/css/**/*',
included: false
}, {
pattern: 'src/font/**/*',
included: false
}, {
pattern: 'src/images/**/*',
included: false
}),


// list of files to exclude
Expand Down
14 changes: 7 additions & 7 deletions karma.conf.sauce.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ var customLaunchers = {
browserName: 'chrome'
},

sl_ie_8: {
base: 'SauceLabs',
browserName: 'internet explorer',
version: '8'
},
// sl_ie_8: {
// base: 'SauceLabs',
// browserName: 'internet explorer',
// version: '8'
// },
sl_ie_9: {
base: 'SauceLabs',
browserName: 'internet explorer',
Expand Down Expand Up @@ -84,15 +84,15 @@ module.exports = function (config) {
var options = Object.assign(base(config), {
reporters: ['mocha', 'saucelabs'],
sauceLabs: {
'testName': 'layui test case',
'testName': 'layui',
'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(),
'build': 'layui-build-' + process.env.TRAVIS_BUILD_NUMBER,
'tunnelIdentifier': process.env.TRAVIS_JOB_NUMBER
},
customLaunchers: customLaunchers,
Expand Down
17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,28 @@
"author": "贤心",
"homepage": "http://www.layui.com",
"devDependencies": {
"chai": "^4.1.1",
"del": "^2.2.2",
"gulp": "^3.9.1",
"gulp-uglify": "^1.5.4",
"gulp-concat": "^2.6.0 ",
"gulp-header": "^1.8.8",
"gulp-if": "^2.0.1",
"gulp-minify-css": "^1.2.4",
"gulp-rename": "^1.2.2",
"del": "^2.2.2",
"gulp-uglify": "^1.5.4",
"gulp-zip": "^4.0.0",
"minimist": "^1.2.0",
"chai": "^3.5.0",
"karma": "^1.5.0",
"karma-chai": "^0.1.0",
"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",
"karma-sauce-launcher": "^1.1.0",
"minimist": "^1.2.0",
"mocha": "^3.2.0",
"sinon": "^2.0.0",
"sinon-chai": "^2.8.0"
"sinon": "^3.2.1",
"sinon-chai": "^2.13.0"
},
"bugs": {
"url": "https://github.com/sentsin/layui/issues"
Expand All @@ -48,8 +48,7 @@
"doc": "doc",
"test": "test"
},
"dependencies": {
},
"dependencies": {},
"keywords": [
"layui",
"ui"
Expand Down
5 changes: 3 additions & 2 deletions test/laytpl.js → test/lay/modules/laytpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,16 @@ describe('laytpl', function () {
it('error var', function () {
var result = laytpl('{{ data.xxoo }}').render({});

expect(result).to.have.string('Can\'t find variable: data');
expect(result).to.have.string('data');
expect(result).to.have.string('ReferenceError');
expect(result).to.have.string('Laytpl Error');
});

it('error expression', function () {
var result = laytpl('{{# var xxoo = ; }}').render({});

expect(result).to.have.string('Laytpl Error');
expect(result).to.have.string('Unexpected token \';\'');
expect(result).to.have.string('SyntaxError');
});
});
});
174 changes: 174 additions & 0 deletions test/layui.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
/**
* @file layui - 测试
* @author xuexb <fe.xiaowu@gmail.com>
*/

/* global layui */
/* eslint-disable max-nested-callbacks */

var $ = layui.$;

describe('layui', function () {
it('version', function () {
expect(layui.v).to.be.a('string');
expect(layui.v).to.not.be.empty;
});

it('layui.config', function () {
expect(layui.config()).to.deep.equal(layui);
expect(layui.config({
testName: 'layui'
})).to.deep.equal(layui);
expect(layui.cache.testName).to.equal('layui');
});

describe('layui.router', function () {
var defaultData = {
path: [],
search: {},
hash: ''
};

it('default params', function () {
expect(layui.router).to.be.a('function');
expect(layui.router()).to.be.a('object').and.deep.equal(defaultData);
});

it('error router', function () {
[
null,
'',
'#123',
'123',
'##'
].forEach(function (key) {
expect(layui.router(key)).to.deep.equal(defaultData);
});
});

it('router querystring', function () {
expect(layui.router('#/a=1/b=2/c=')).to.deep.equal($.extend({}, defaultData, {
search: {
a: '1',
b: '2',
c: ''
}
}));

expect(layui.router('#/a=测试/b=2').search).to.deep.equal({
a: '测试',
b: '2'
});

// todo
// urlencode
// urldecode
});

it('router hash', function () {
expect(layui.router('#/name#layui')).to.deep.equal($.extend({}, defaultData, {
hash: '#layui',
path: ['name']
}));
expect(layui.router('#/name#layui').hash).to.equal('#layui');
expect(layui.router('#/name#layui=1').hash).to.equal('#layui=1');
expect(layui.router('#/name##layui').hash).to.equal('##layui');
expect(layui.router('#/name=1#layui').hash).to.equal('#layui');
expect(layui.router('#/name=1/b=2#layui').hash).to.equal('#layui');
});

it('router path', function () {
expect(layui.router('#/a/b/c=2#hash')).to.deep.equal({
path: ['a', 'b'],
search: {
c: '2'
},
hash: '#hash'
});
});
});

describe('layui.each', function () {
it('check params', function () {
expect(layui.each).to.be.a('function');
expect(layui.each()).to.deep.equal(layui);
expect(layui.each({})).to.deep.equal(layui);
expect(layui.each([])).to.deep.equal(layui);
expect(layui.each({}, function () {})).to.deep.equal(layui);
expect(layui.each([], function () {})).to.deep.equal(layui);
});

it('null params', function (done) {
var index = 0;
layui.each(null, function (index) {
index += 1;
});
setTimeout(function () {
expect(index).to.equal(0);
done();
});
});

it('object each', function (done) {
layui.each({
name: 'layui'
}, function (key, value) {
expect(this + '').to.deep.equal(value).and.equal('layui');
expect(key).to.equal('name');
done();
});
});

it('array each', function (done) {
layui.each([
'layui'
], function (index, value) {
expect(this + '').to.deep.equal(value).and.equal('layui')
expect(index).to.equal(0);
done();
});
});

it('break array each', function () {
var arr = new Array(100).join(',').split(',');
var flag = -1;
layui.each(arr, function (index) {
flag = index;
if (index > 5) {
return true;
}
});
expect(flag).to.equal(6);

flag = -1;
layui.each(arr, function (index) {
flag = index;
if (index > 5) {
return false;
}
});
expect(flag).to.equal(99);
});

it('break object each', function () {
var obj = {
name: 'layui',
version: '2.x'
};
var flag = null;
layui.each(obj, function (key) {
flag = key;
return true;
});
expect(flag).to.equal('name');

flag = null;
layui.each(obj, function (key) {
flag = key;
return false;
});
expect(flag).to.equal('version');
});
});
});
/* eslint-enable max-nested-callbacks */

0 comments on commit 6c2c29c

Please sign in to comment.