Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ before_script:
- bower install
- cd test
- bower install
- npm install
- cd ..
after_script:
- npm run coveralls
6 changes: 5 additions & 1 deletion src/mock/random/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ module.exports = {
format = format || 'yyyy-MM-dd HH:mm:ss'

var date = new Date()
var extraDay = 0

/* jshint -W086 */
// 参考自 http://momentjs.cn/docs/#/manipulating/start-of/
Expand All @@ -121,6 +122,7 @@ module.exports = {
date.setMonth(0)
case 'month':
date.setDate(1)
case 'weekiso':
case 'week':
case 'day':
date.setHours(0)
Expand All @@ -132,8 +134,10 @@ module.exports = {
date.setMilliseconds(0)
}
switch (unit) {
case 'weekiso':
extraDay++
case 'week':
date.setDate(date.getDate() - date.getDay())
date.setDate(date.getDate() - date.getDay() + extraDay)
}

return this._formatDate(date, format)
Expand Down
2 changes: 1 addition & 1 deletion test/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "test",
"dependencies": {
"chai": "^1.10.0"
"mocha": "^4.0.1"
}
}
10 changes: 5 additions & 5 deletions test/test.mock.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>Test: Mock</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="./bower_components/mocha/mocha.css" rel="stylesheet">
<link href="./node_modules/mocha/mocha.css" rel="stylesheet">
<style type="text/css">
li.test h2 {
font-family: monospace;
Expand All @@ -16,13 +16,13 @@
<body>
<div id="mocha"></div>
<!-- Include local Mocha. -->
<script src="./bower_components/mocha/mocha.js"></script>
<script src="./node_modules/mocha/mocha.js"></script>
<script src="./bower_components/chai/chai.js"></script>
<script>mocha.setup('bdd')</script>
<!-- Include RequireJS -->
<script src="./bower_components/requirejs/require.js"></script>
<script type="text/javascript">
require.config({
requirejs.config({
paths: {
'mock': '../dist/mock',
jquery: 'bower_components/jquery/dist/jquery',
Expand All @@ -44,7 +44,7 @@
<script src="./test.mock.request.js"></script>
<script src="./test.mock.schema.js"></script>
<script src="./test.mock.valid.js"></script>

<!-- PhantomJS -->
<script type="text/javascript">
if (window.mochaPhantomJS) {
Expand All @@ -54,4 +54,4 @@
}
</script>
</body>
</html>
</html>
4 changes: 2 additions & 2 deletions test/test.mock.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var Mock, $, _

describe('Mock.mock', function() {
before(function(done) {
require(['mock', 'underscore', 'jquery'], function() {
requirejs(['mock', 'underscore', 'jquery'], function() {
Mock = arguments[0]
_ = arguments[1]
$ = arguments[2]
Expand Down Expand Up @@ -59,4 +59,4 @@ describe('Mock.mock', function() {
})
})
})
})
})
7 changes: 5 additions & 2 deletions test/test.mock.random.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var Mock, Random, $, _, Random
/* jshint -W061 */
describe('Random', function() {
before(function(done) {
require(['mock', 'underscore', 'jquery'], function() {
requirejs(['mock', 'underscore', 'jquery'], function() {
Mock = arguments[0]
window.Random = Random = Mock.Random
_ = arguments[1]
Expand Down Expand Up @@ -212,6 +212,9 @@ describe('Random', function() {
doit('Random.now("week")', function(data) {
expect(data).to.be.ok
})
doit('Random.now("weekiso")', function(data) {
expect(data).to.be.ok
})
doit('Random.now("yyyy-MM-dd HH:mm:ss SS")', function(data) {
expect(data).to.be.ok
})
Expand Down Expand Up @@ -461,4 +464,4 @@ describe('Random', function() {
expect(data).to.be.a('string').with.length(18)
})
})
})
})
4 changes: 2 additions & 2 deletions test/test.mock.request.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var Mock, $, _

describe('Request', function() {
before(function(done) {
require(['mock', 'underscore', 'jquery'], function() {
requirejs(['mock', 'underscore', 'jquery'], function() {
Mock = arguments[0]
_ = arguments[1]
$ = arguments[2]
Expand Down Expand Up @@ -442,4 +442,4 @@ describe('Request', function() {
done()
})
})
})
})
4 changes: 2 additions & 2 deletions test/test.mock.schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var Mock, $, _

describe('Schema', function() {
before(function(done) {
require(['mock', 'underscore', 'jquery'], function() {
requirejs(['mock', 'underscore', 'jquery'], function() {
Mock = arguments[0]
window.XMLHttpRequest = Mock.XHR
_ = arguments[1]
Expand Down Expand Up @@ -202,4 +202,4 @@ describe('Schema', function() {
})
})

})
})
4 changes: 2 additions & 2 deletions test/test.mock.spec.dpd.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var Mock, $, _

describe('DPD', function() {
before(function(done) {
require(['mock', 'underscore', 'jquery'], function() {
requirejs(['mock', 'underscore', 'jquery'], function() {
Mock = arguments[0]
_ = arguments[1]
$ = arguments[2]
Expand Down Expand Up @@ -235,4 +235,4 @@ describe('DPD', function() {
expect(data).to.be.a('object')
})
})
})
})
46 changes: 23 additions & 23 deletions test/test.mock.spec.dtd.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 数据模板定义(Data Temaplte Definition,DTD)
/*
## BDD
1. 结构
1. 结构
describe suite
[ describe ]
before after beforeEach afterEach
Expand All @@ -18,7 +18,7 @@
.to.be.a .to.be.an
.that
.least .most .within
3. 速度
3. 速度
搜索 test.speed
slow > 75
75 / 2 < medium < 75
Expand All @@ -29,7 +29,7 @@ var Mock, $, _

describe('DTD', function() {
before(function(done) {
require(['mock', 'underscore', 'jquery'], function() {
requirejs(['mock', 'underscore', 'jquery'], function() {
Mock = arguments[0]
_ = arguments[1]
$ = arguments[2]
Expand All @@ -48,28 +48,28 @@ describe('DTD', function() {
var data = Mock.mock(this.test.title)
expect(data).to.equal(this.test.title)
})
it(1, function() {
var data = Mock.mock(this.test.title)
expect(data).to.equal(this.test.title)
it('number', function() {
var data = Mock.mock(1)
expect(data).to.equal(1)
})
it(true, function() {
var data = Mock.mock(this.test.title)
expect(data).to.equal(this.test.title)
it('true', function() {
var data = Mock.mock(true)
expect(data).to.equal(true)
})
it(false, function() {
var data = Mock.mock(this.test.title)
expect(data).to.equal(this.test.title)
it('false', function() {
var data = Mock.mock(false)
expect(data).to.equal(false)
})
it({}, function() {
var data = Mock.mock(this.test.title)
expect(data).to.deep.equal(this.test.title)
it('object', function() {
var data = Mock.mock({})
expect(data).to.deep.equal({})
})
it([], function() {
var data = Mock.mock(this.test.title)
expect(data).to.deep.equal(this.test.title)
it('array', function() {
var data = Mock.mock([])
expect(data).to.deep.equal([])
})
it(function() {}, function() {
var data = Mock.mock(this.test.title)
it('function', function() {
var data = Mock.mock(function() {})
expect(data).to.equal(undefined)
})
})
Expand Down Expand Up @@ -205,7 +205,7 @@ describe('DTD', function() {
})
})
describe('Boolean', function() {
// `'name|1': value`
// `'name|1': value`
it('name|1', function() {
var data = Mock.mock({
'name|1': true
Expand Down Expand Up @@ -500,7 +500,7 @@ describe('DTD', function() {
}
}

it(regexp, function() {
it(regexp.toString(), function() {
var data = Mock.mock(regexp)
this.test.title += ' => ' + data
expect(regexp.test(data)).to.be.true
Expand Down Expand Up @@ -674,4 +674,4 @@ describe('DTD', function() {
expect(data).to.be.a('object')
})
})
})
})
4 changes: 2 additions & 2 deletions test/test.mock.valid.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var Mock, Random, $, _

describe('Mock.valid', function() {
before(function(done) {
require(['mock', 'underscore', 'jquery'], function() {
requirejs(['mock', 'underscore', 'jquery'], function() {
Mock = arguments[0]
window.Random = Random = Mock.Random
_ = arguments[1]
Expand Down Expand Up @@ -305,4 +305,4 @@ describe('Mock.valid', function() {
name: 123
}, 0)
})
})
})