Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Mocha testing in Titanium(ja)
Search
Kosuke Isobe
August 03, 2015
Programming
200
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Mocha testing in Titanium(ja)
Kosuke Isobe
August 03, 2015
More Decks by Kosuke Isobe
See All by Kosuke Isobe
React Native で LDR の クライアントを作ったというお話
k0sukey
0
110
Mocha testing in Titanium(en)
k0sukey
1
160
Titanium もくもく会 #11
k0sukey
0
230
Titanium もくもく会 #10
k0sukey
0
2.3k
Titanium もくもく会 #5
k0sukey
0
2k
Other Decks in Programming
See All in Programming
이 함수, 실패하면 어떻게 되나요? null부터 Rich Errors까지, Kotlin 에러 처리 15년
haeti2
0
130
XP祭りでしか伝わらないフリップネタ #xpjug
murabayashi
0
110
in-process GraphQL のすすめ #ginzajs
izumin5210
4
1.5k
LoopHub - ローカルで動く GitHub で、AI と共同開発
jugyo
0
400
変化を抱擁するドキュメントの作り方 - ビジネスルール駆動開発がもたらす、コードとの新しい関係
ioki
2
110
Deep dive into the select statement (GopherCon UK)
jespino
0
170
MIZARU@SPAJAM2026 第二回予選
1901drama
0
100
自分的「カンファレンスの楽しみ方」
syumai
0
190
go-spidermonkeyでAIエージェントのCode Modeを実装する
syumai
3
1.5k
MySQLとPostgreSQLって何が違うの?
akagami
PRO
0
160
KotlinConf Extended South Korea 2026 Keynote
l2hyunwoo
0
130
AIの中の人になってみる
htkym
0
160
Featured
See All Featured
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
The Cult of Friendly URLs
andyhume
79
7k
Crafting Experiences
bethany
1
280
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.1k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
The Spectacular Lies of Maps
axbom
PRO
1
970
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
230
BBQ
matthewcrist
89
10k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
430
AI: The stuff that nobody shows you
jnunemaker
PRO
9
970
Everyday Curiosity
cassininazir
0
310
Transcript
.PDIBUFTUJOH JO5JUBOJVN
ү෦྄ʢ͍ͦ͜͏͚͢ʣ 4PDLFUCBTF*ODɹ$50$PGPVOEFS ȍ ɹ LTVLFZ ͜͡͠ΐ͏͔͍
͜͡͠ΐ͏͔͍ w "MMPZϓϩδΣΫτͷ։ൃΛͪΐͬͽΓָʹ ͢Δ LTVLFZBMMPZTNFMUFS w ࡶʹͳΓ͍͢UTTΛ͖Ε͍ྻ͢͠ LTVLFZUTTGPSNBUUFS ͳΜ͔Λ࡞͍ͬͯ·͢
5JUBOJVNɺςετ ͍ͯ͠·͔͢ʁ
Titanium ͷςετͱ͍͑ w ༰қʹςετͰ͖ͳ͍ w γϛϡʢΤϛϡʣϨʔλʗ࣮ػ͡Όͳ͍ͱςετͰ͖ͳ͍ w "QQDFMFSBUPS1MBUGPSNͷςετߴֹɻ͜Εɺ6* "VUPNBUJPOΛϦϞʔτͰಈ͔ͯ͠Α͏ͳͷͩ͠ w
Ϣχοτςετ͕͍ͨ͠ΜͰ͢ w ͭ·Γɺ༰қʹςετͰ͖ͳ͍
͜Ε͘Β͍ͳΒ w KTIJOU w KTCFBVUJpFS w ςετ͡Όͳͯ͘จ ๏νΣοΫͰ͢Ͷ // gulplfile.js
var gulp = require(‘gulp’), plugin = require(‘gulp—load—plugins’)(); gulp.task(‘jshint’, function(){ return gulp.src(‘app/controllers/**/ *.js’) .pipe(plugin.jshint()) .pipe(plugin.jshint.reporter(‘jshint— stylish’)) .pipe(plugin.jshint.reporter(‘fail’)); }); gulp.task(‘jsbeautifier’, function(){ return gulp.src(‘app/controllers/**/ *.js’) .pipe(plugin.jsbeautifier({ logSuccess: false, mode: ‘VERIFY_ONLY’ })); });
΅͘5JUBOJVNίʔυͷ Ϣχοτςετ͕͍ͨ͠ʂ
Titanium ͷςετͱ͍͑ w UJNPDIB w UJUBOJVNKBTNJOF w UJP w %SJMMCJU
γϛϡʢΤϛϡʣϨʔλʗ࣮ػ ͡Όͳ͍ͱςετͰ͖ͳ͍ λʔϛφϧͰ͍݁ͨ͠Ͱ͢ʜ
ͳͥͰ͖ͳ͍ͷ͔ w ͦͦରͷ࣮ߦڥʢ/PEFKTʣʹ5JUBOJVN"1*͕ ͳ͍Ͱ͢͠ w ਓͷख͕հࡏͯ͠ྑ͍ͷ͔ɻશࣗಈԽ͍ͨ͠ w .BD͡Όͳ͍ͱJ04ͷςετ͕ʜ w 5JUBOJVN4%,("͔Β8JOEPXT1IPOF͖
·ͨ͠Ͷɻ8JOEPXT͍࣋ͬͯͳ͍Ͱ͢
5SBWJT$*ͱ͔$JSDMF$*Ͱ ࠓ෩ʹ$*͍ͨ͠ΜͰ͢ ָ͍ͨ͠
࡞Γ·ͨ͠
ΞʔΩςΫνϟ w /PEFKTͷ7.Ϟδϡʔϧ w 5JUBOJVN"1*Λಈ͔͢ʢೝࣝͤ͞Δʣ w ΈΜͳେ͖.PDIB
7.Ϟδϡʔϧͱ
VM Ϟδϡʔϧ w ؆୯ʹݴ͏ͱɺ҆શͳFWBM w αϯυϘοΫεͳίϯςΩετΛ࡞Γɺͦͷ தͰ+BWB4DSJQUΛ࣮ߦͰ͖Δ w ͦͦFYQPSUTͱ͔SFRVJSF͑͞ແ͍
VM Ϟδϡʔϧ w ͜Μͳײ͡Ͱ࣮ߦڥ Λ࡞ͬͯ͋͛·͢ w WNSVO*O$POUFYUͷ ฦ٫࣮ߦ݁Ռͷί ϯςΩετ˺Ξαʔ γϣϯͰ͖Δ͡Όͳ͍
var vm = require(‘vm’), context = vm.createContext({ require: require, module: module, exports: exports, console: console, setTimeout: setTimeout, setInterval: setInterval, clearTimeout: clearTimeout, clearInterval: clearInterval, JSON: JSON, alert: function(e) { console.log(e); } }), result = vm.runInContext(‘console.log(\’ Hello, world.\’);’, context);
VM Ϟδϡʔϧ w WNDSFBUF$POUFYUʹ 5JUBOJVN"1*Λͯ͠ ͋͛Ε࣮ߦͰ͖Δʁ w Ͳ͏ߟ͑ͯಈ͖·͢ ΑͶɺ͜ΕɻΑ͠ɺ5Jʙ ͳ"1*શ෦ॻ͔͘ʜ
var vm = require(‘vm’), context = vm.createContext({ Ti: { UI: { createWindow: function(){} } } }), result = vm.runInContext(‘var win = Ti.UI.createWindow();’, context);
શ5JUBOJVN"1*Λ Ͳ͏ʹ͔͢Δ
Titanium API w ͦͦɺ͍ͭ͋͘Δͷ͔ղΒͳ͍Ϩϕϧ w ΓΦϒδΣΫτͰ͝·͔ͤͳ͍ w શ෦खॻ͖ࢮϑϥά w ϦϑΝϨϯεΛεΫϨΠϐϯά͢Δ͔ʁ
Titanium API w ެࣜϦϑΝϨϯε͋ Γ·͢ΑͶ w Αʔʔʔ͘ݟͯΒ ͍͍ͨɻ͜ͷล
ϦϑΝϨϯε͕+40/Ͱ ఏڙ͞Ε͍ͯΔʂʂʂ̍
Titanium API w ϦϑΝϨϯε+40/Λͬͯ/PEFKTͷ࣮ ߦڥͰಈ͘5JUBOJVNGBLFS"1*Λࣗಈੜ ͠·͢ w ͍ͭ͜Λ7.ϞδϡʔϧͷίϯςΩετʹ ͯ͠͠·͑ʜ
/PEFKT্Ͱ5JUBOJVNͷ ίʔυ͕࣮ߦͰ͖·ͨ͠❤
ti-slag w 5JUBOJVNGBLFS"1* w 5JUBOJVN4%,͕ଘࡏ͠ͳͯ͘/PEFKT্Ͱ 5JUBOJVN"1*ͷৼΔ͍ΛγϛϡϨʔτ͠·͢ w %FQSFDBUFEͳϓϩύςΟʗϝιουΛ͓৮Γ͢Δͱɺ ྫ֎͕͛ΒΕ·͢ w
ͪΖΜը໘ભҠ͠·ͤΜΑɻը໘ͳ͍Ͱ͢͠
slagʁ w ߭ᕥʢ͜͏͍͞ʣɻ߭ੴ͔Βਫ਼࿉͢Δࡍʹɺ ରͷۚଐ͔Βͨ߭͠ͳͲɻଏʹ ۚሬʢΟΩϖσΟΞௐʣ w ͭ·ΓɺΓΧε
LTVLFZUJTMBH
Mocha testing in ti-slag w ඞཁͳOQNύοέʔ δΛΠϯετʔϧ w QBDLBHFKTPOς ετͷ࣮ߦεΫϦϓ
τΛՃ $ cd path/to/yourapp $ npm init $ npm install mocha ti—slag lodash ——save—dev package.json { … “scripts”: { “test”: “mocha test.js” }, … }
Mocha testing in ti-slag w ·ͣ"MMPZίϯύΠ ϧ͠·͢ɻUJCVJMEʗ BQQDSVOͱ͔Ͱ0,ɻ ͱʹ͔͘3FTPVSDF ԼʹίʔυΛు͔ͤ·͢
w ͦͯ͠OQNUFTU $ alloy compile ——config platform=ios $ npm test >
[email protected]
test /Users/ Kosuke/src/sandbox > mocha test.js iOS index.js ✓ should does not throw exception in the Controller 1 passing (10ms)
Mocha testing in ti-slag w "MMPZϓϩδΣΫτίϯύΠϧ͞ΕΔͱɺ3FTPVSDFTԼ ʹΫϥγοΫͳίʔυΛు͖ग़͠·͢ w ͜ͷίʔυΛUJTMBHʹ͢ͱ7.ڥͰ࣮ߦ͞Εɺ݁ՌΛ ίϯςΩετͱͯ͠ฦ٫͠·͢
w ίϯύΠϧ͞Εͨ"MMPZίϯτϩʔϥNPEVMFFYQPSUTͰ $POUSPMMFSͱͯ͠ެ։͞Ε͍ͯΔͷͰɺ͍ͭ͜Λ࣮ߦ͠·͢
// Resources/…/index.js function Controller() { function doClick() { var next
= Alloy.createController(‘next’ ), view = next.getView(); view.open(); } $.index.open(); } module.exports = Controller; // app/controllers/index.js function doClick() { var next = Alloy.createController(‘next’) , view = next.getView(); view.open(); } $.index.open(); Mocha testing in ti-slag
Mocha testing in ti-slag // test.js var _ = require(‘lodash’),
assert = require(‘assert’), path = require(‘path’), slag = require(‘ti—slag); describe(‘iOS index.js’, function(){ var context = slag(‘./Resources/iphone/alloy/controllers/index.js’, { titanium: ‘4.0.0.GA’, platfrom: ‘ios’, module: { alloy: alloy, ‘alloy/controllers/BaseController’: BaseController } }); it(‘should does not throw exception in the Controller’, function(){ assert.doesNotThrow(function(){ context.Controller(); }); }); });
5JUBOJVN"1*ྑ͍͚Ͳɺ ϞδϡʔϧͲ͏͢ΔͷΑ
Mocha testing in ti-slag w ୈೋҾʹ͋ΔNPEVMF Ͱϐϯͱ͖͔ͨ͠Ε· ͤΜͶ w SFRVJSF͢ΔϞδϡʔϧ
ͷ໊শΛͤͦͷ·· ಡΈࠐ·ΕΔͷͰɺ͓ ͖ʹͲ͏ͧ var context = slag(‘./ Resources/iphone/alloy/ controllers/index.js’, { titanium: ‘4.0.0.GA’, platfrom: ‘ios’, module: { ‘ti.map’: { // ࣗͰ͕ΜΕ } } });
ͦͦ"MMPZͷ࣮ߦڥ Ͳ͏ͳ͍ͬͯΔͷ
Mocha testing in ti-slag w "MMPZͬͯ5JUBOJVN4%,ڥԼͰಈ͍͍ͯ·͢ΑͶ w ͪΖΜUJTMBHڥԼͰಉ͡Α͏ʹ࣮ߦͰ͖·͢ w UJTMBHͷϞδϡʔϧʹ"MMPZίϯςΩετΛͯ͋͛͠
Ε0,Ͱ͢ʢਖ਼͘͠#BTF$POUSPMMFSඞཁͰ͢ʣ w ৄ͘͠ɺ LTVLFZUJTMBHUFTUKTΛࢀর
είʔϓతʹߟ͑ͯ EP$MJDL͕࣮ߦͰ͖ͳ͍
Mocha testing in ti-slag w UJTMBHʹ"MMPZίϯςΩ ετ͕ల։͞Ε͍ͯΔͷͰɺ "MMPZίϯτϩʔϥͷϝιο υͦͷ··͑Δ w
"MMPZ!͔ΒՃ͞Ε ͨΠϕϯτՃʗऔಘʗআ ϝιουͰΠϕϯτϦεφΛ औಘ͢Ε0, assert.doesNotThrow(function(){ context.Controller(); var listeners = context.getListener(); });
Mocha testing in ti-slag describe(‘iOS index.js’, function(){ var context =
slag(‘./Resources/iphone/alloy/controllers/index.js’, { titanium: ‘4.0.0.GA’, platfrom: ‘ios’, module: { alloy: alloy, ‘alloy/controllers/BaseController’: BaseController } }), listeners; it(‘should does not throw exception in the Controller’, function(){ assert.doesNotThrow(function(){ context.Controller(); listeners = context.getListener(); }); }); it(‘should does not throw exception in the event listeners’, function(){ assert.doesNotThrow(function(){ _.each(listeners, function(listener){ listener.handler(); }); }); }); });
$JSDMF$*ͷ࣮ߦڥΛ ఆٛ͠·͢
circle.yml w UFTUQSFͰHVMQ KTIJOUKTCFBVUJpFS ͔ͯ͠Β"MMPZίϯ ύΠϧ w ͦͷίϯύΠϧ݁ՌΛ ࣋ͬͯςετΛ࣮ߦ machine:
node: version: 0.10.34 dependencies: pre: — npm install —g alloy — npm install test: pre: — gulp jshint — gulp jsbeautifier — alloy compile ——config platform=ios — alloy compile ——config platform=android
(JU)VCʹϓογϡ $JSDMF$*Ͱ࣮ߦ ݁ՌΛ4MBDLʹ ͛Δ ɹɹɹɹɹɹɹɹɹɹ΅͘͝ຬӻ CI
5IBOLZPV❤
2VFTUJPOʁ