Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Mocha testing in Titanium(ja)
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
170
Titanium もくもく会 #11
k0sukey
0
240
Titanium もくもく会 #10
k0sukey
0
2.4k
Titanium もくもく会 #5
k0sukey
0
2k
Other Decks in Programming
See All in Programming
Findy - エンジニア向け会社紹介/Findy Company Deck
findyinc
6
400k
The Rails Doctrine Decade
koic
2
560
sbt 2.0: takeoff
eed3si9n
0
140
速習iPhone Duo対応
yuukiw00w
2
980
golang-bob.pdf
iwatsukayura
0
130
Agentic Software Factoryに、すごく賢いIF文を。 / super smart IF statement into the Agentic Software Factory.
rkaga
8
2.1k
半永久的に提供し続けられるプライベートクラウドを目指して ― 利用者の認知負荷を抑えるAPI抽象化とハードウェア世代交代の基盤設計
tomokon
0
480
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
200
mrbgem 三角測量 開発
ogom
0
240
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
370
複雑なUIコンポーネントとの ⻑い付き合い⽅:波及するバグからテスト戦略を経て、安全な再設計へ
mixplace
0
380
なぜCTOを降りてFDEを選んだのか?〜なぜプロダクト企業がFDEで顧客の現場に踏み込むのか〜
gonta
1
190
Featured
See All Featured
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
340
SEO for Brand Visibility & Recognition
aleyda
0
4.8k
Heart Work Chapter 1 - Part 1
lfama
PRO
10
37k
sira's awesome portfolio website redesign presentation
elsirapls
0
450
Docker and Python
trallard
47
4.2k
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.2k
Ruling the World: When Life Gets Gamed
codingconduct
0
400
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
5
800
Balancing Empowerment & Direction
lara
6
1.3k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
22k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
Building the Perfect Custom Keyboard
takai
2
900
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ʁ