Skip to content

Commit cbbc1fd

Browse files
committed
Try to enable Jasmine test
1 parent b7352ce commit cbbc1fd

7 files changed

Lines changed: 133 additions & 19 deletions

File tree

.editorconfig

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@ end_of_line = lf
66
charset = utf-8
77
trim_trailing_whitespace = true
88
insert_final_newline = true
9+
tab_width = 2
10+
indent_size = 2
911

1012
[*.js]
1113
indent_style = tab
14+
tab_width = 2
1215

1316
[*.css]
1417
indent_style = space
15-
indent_size = 2
16-
tab_width = 2
1718

1819
[*.coffee]
1920
indent_style = space
20-
indent_size = 2
21-
tab_width = 2
22-

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44

55
# Ignore Node Modules
66
/node_modules/*
7+
/compiled_spec/*
8+
/coverage/*

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
language: node_js
2+
node_js:
3+
- "0.10"
4+
before_install:
5+
- npm install npm@1.4 -g
6+
before_script:
7+
- npm install -g grunt-cli
8+
script:
9+
- grunt test

Gruntfile.coffee

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = (grunt) ->
22
require('load-grunt-tasks') grunt
33
grunt.file.readJSON('package.json')
4-
4+
55
# !! Compile configurations
66
License = '/*!Copyright(c) CommentCoreLibrary (//github.com/jabbany/CommentCoreLibrary) - Licensed under the MIT License */'
77
FilterType = "Simple" # "Comment" || "Simple"
@@ -36,14 +36,14 @@ module.exports = (grunt) ->
3636
'src/parsers/AcfunFormat.js'
3737
'src/parsers/BilibiliFormat.js'
3838
]
39-
39+
4040
# !! Below are compile settings
4141
# Dynamically generate the core ts targets
4242
CMP_CORE_TS = { }
4343
CMP_CORE_NAME = [ ]
4444
for target in SRC_CORE_CMP
4545
CMP_CORE_NAME.push ("typescript:" + target)
46-
CMP_CORE_TS[target] =
46+
CMP_CORE_TS[target] =
4747
options:
4848
target: 'es5'
4949
basePath: 'src/core'
@@ -55,29 +55,31 @@ module.exports = (grunt) ->
5555
CMP_KAGEROU_NAME = [ ]
5656
for target,src of SRC_SCRIPTING_KAGEROU
5757
CMP_KAGEROU_NAME.push ('typescript:kagerou_engine_' + target)
58-
CMP_KAGEROU_TS['kagerou_engine_' + target] =
59-
options:
58+
CMP_KAGEROU_TS['kagerou_engine_' + target] =
59+
options:
6060
target: 'es5'
6161
basePath: src.split('/')[0..-1].join('/')
6262
src: src
6363
dest: 'build/scripting/api/' + src.split('/').pop().split('.')[0] + '.js'
64-
64+
6565
# Append Typescript Tasks
6666
ts_config = {}
6767
for key,value of CMP_CORE_TS
6868
ts_config[key] = value
6969
for key,value of CMP_KAGEROU_TS
7070
ts_config[key] = value
71-
71+
7272
# Core concatenated with libraries
7373
# Actual concat ordering does not/should not matter
7474
SRC_CORELIB = SRC_CORE.concat(SRC_PARSER)
7575

76+
grunt.loadNpmTasks('grunt-contrib-coffee')
77+
grunt.loadNpmTasks('grunt-contrib-jasmine')
7678
grunt.initConfig(
7779
clean:
7880
scripting: ['build/scripting']
7981
build: ['build']
80-
82+
8183
# Concat CSS and JS files
8284
# core_only : builds CCL without parsers
8385
# all : builds CCL with everything
@@ -93,18 +95,18 @@ module.exports = (grunt) ->
9395
files:
9496
'build/style.css': CSS
9597
'build/CommentCoreLibrary.js': SRC_CORELIB
96-
98+
9799
# Compile TypeScript
98100
typescript: ts_config
99-
101+
100102
# Copy
101103
copy:
102104
scripting_sandbox:
103105
files:[
104106
{expand: true, cwd:'src/scripting/api/', src: ['*.js'], dest:'build/scripting/api/'},
105107
{expand: true, cwd:'src/scripting/', src: ['OOAPI.js','Worker.js'], dest:'build/scripting/'}
106108
]
107-
109+
108110
# Auto-prefix CSS properties using Can I Use?
109111
autoprefixer:
110112
options:
@@ -130,19 +132,42 @@ module.exports = (grunt) ->
130132
'build/CommentCoreLibrary.min.js': SRC_CORELIB
131133

132134
# Watch files for changes
135+
#
133136
watch:
134137
all:
135138
files: ['src/**/*', '!node_modules']
136139

137140
# Run concat, autoprefixer, cssmin and uglify
138141
tasks: ['build']
142+
143+
# Jasmine test
144+
145+
jasmine:
146+
coverage:
147+
src: 'src/**/*.js'
148+
#src: 'build/CommentCoreLibrary.js'
149+
options:
150+
specs: 'compiled_spec/*spec.js'
151+
helpers: 'spec/*helper.js'
152+
template: require('grunt-template-jasmine-istanbul')
153+
templateOptions:
154+
report: 'coverage'
155+
coverage: 'coverage/coverage.json'
156+
coffee:
157+
glob_to_multiple:
158+
expand: true,
159+
flatten: true,
160+
src: ['spec/**/*.coffee']
161+
dest: 'compiled_spec/'
162+
ext: '.js'
139163
)
140-
164+
141165
# Register special compiles
142166
grunt.registerTask 'compile-ts-kagerou', CMP_KAGEROU_NAME
143167
grunt.registerTask 'compile-ts-core', CMP_CORE_NAME
144-
168+
145169
# Register our tasks
170+
grunt.registerTask 'test', ['coffee', 'jasmine']
146171
grunt.registerTask 'build-scripting', ['clean:scripting','concat:scripting_host', 'compile-ts-kagerou', 'copy:scripting_sandbox']
147172
grunt.registerTask 'build-core', ['compile-ts-core', 'concat:core_only', 'autoprefixer', 'cssmin', 'uglify:core_only']
148173
grunt.registerTask 'build', ['compile-ts-core', 'concat:all', 'autoprefixer', 'cssmin', 'uglify:all']

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
"grunt-contrib-concat": "~0.5.0",
2424
"grunt-contrib-cssmin": "~0.10.0",
2525
"grunt-contrib-uglify": "~0.6.0",
26+
"grunt-contrib-coffee": "~0.12.0",
27+
"grunt-contrib-jasmine": "~0.8.0",
28+
"grunt-template-jasmine-istanbul": "~0.3.0",
2629
"load-grunt-tasks": "~0.6.0"
2730
}
2831
}
29-

spec/Array_spec.coffee

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
'use strict'
2+
describe 'BinArray', ->
3+
testAray = null
4+
compare = (a, b)-> a - b
5+
6+
describe 'bsearch', ->
7+
describe 'with empty array', ->
8+
beforeEach -> testAray = []
9+
it 'always returns 0', ->
10+
expect(BinArray.bsearch(testAray, 2, compare)).toBe 0
11+
expect(BinArray.bsearch(testAray, 0, compare)).toBe 0
12+
13+
describe 'with [1, 3, 5]', ->
14+
beforeEach -> testAray = [1,3,5]
15+
16+
it 'search for 0', ->
17+
expect(BinArray.bsearch(testAray, 0, compare)).toBe 0
18+
19+
it 'search for 1', ->
20+
expect(BinArray.bsearch(testAray, 1, compare)).toBe 1
21+
22+
it 'search for 2', ->
23+
expect(BinArray.bsearch(testAray, 2, compare)).toBe 1
24+
25+
it 'search for 3', ->
26+
expect(BinArray.bsearch(testAray, 3, compare)).toBe 2
27+
28+
it 'search for 4', ->
29+
expect(BinArray.bsearch(testAray, 4, compare)).toBe 2
30+
31+
it 'search for 5', ->
32+
expect(BinArray.bsearch(testAray, 5, compare)).toBe 3
33+
34+
it 'search for 6', ->
35+
expect(BinArray.bsearch(testAray, 6, compare)).toBe 3
36+
37+
describe 'binsert', ->
38+
describe 'with empty array', ->
39+
beforeEach -> testAray = []
40+
it 'just insert to array', ->
41+
expect(BinArray.binsert(testAray, 0, compare)).toBe 0
42+
expect(testAray).toEqual [0]
43+
44+
describe 'with [1, 3, 5]', ->
45+
beforeEach -> testAray = [1,3,5]
46+
it 'insert 0', ->
47+
expect(BinArray.binsert(testAray, 0, compare)).toBe 0
48+
expect(testAray).toEqual [0,1,3,5]
49+
it 'insert 1', ->
50+
expect(BinArray.binsert(testAray, 1, compare)).toBe 1
51+
expect(testAray).toEqual [1,1,3,5]
52+
it 'insert 2', ->
53+
expect(BinArray.binsert(testAray, 2, compare)).toBe 1
54+
expect(testAray).toEqual [1,2,3,5]
55+
it 'insert 3', ->
56+
expect(BinArray.binsert(testAray, 3, compare)).toBe 2
57+
expect(testAray).toEqual [1,3,3,5]
58+
it 'insert 4', ->
59+
expect(BinArray.binsert(testAray, 4, compare)).toBe 2
60+
expect(testAray).toEqual [1,3,4,5]
61+
it 'insert 5', ->
62+
expect(BinArray.binsert(testAray, 5, compare)).toBe 3
63+
expect(testAray).toEqual [1,3,5,5]
64+
it 'insert 6', ->
65+
expect(BinArray.binsert(testAray, 6, compare)).toBe 3
66+
expect(testAray).toEqual [1,3,5,6]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict'
2+
describe 'CommentManager', ->
3+
manager = null
4+
5+
describe 'instance API', ->
6+
beforeEach ->
7+
manager = new CommentManager(window)
8+
9+
'load start stop insert send clear time'.split(' ').forEach (method)->
10+
it "has method: '#{method}'", ->
11+
expect(typeof manager[method]).toBe 'function'
12+

0 commit comments

Comments
 (0)