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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
進化を続けるGo toolsの現在地 / The Current State of Ever-Evolving Go Tools
hond0413
0
230
【QA Test Talk Vol.8】AI-DLC による Whole Team Approach の加速
pkshadeck
PRO
0
190
「人を評価する AI」の設計と実装
ryoyanara
0
210
Go 1.27 における memory allocation の高速化
andpad
0
200
そこに3びきプロダクトがいるじゃろう——生成AI時代における“価値が届かない理由”の構造
kosuket
0
500
源内ハンズオン概要編
hideg
0
190
楽しそうなつよつよエンジニアと目が死んでる僕/A brilliant engineer having a blast, and dead-eyed me.
3l4l5
2
190
20260722_microCMSで考える、AI時代のコンテンツ運用設計
yosh1
0
410
AI時代に設計が 最大の生産性レバーになる 意図駆動開発とデータを消さない設計|Don't Delete Your Data or Your Intent — Design as the Deepest Lever in the AI Era
tomohisa
1
980
AIを紡ぐPMのお話
swdtkuy
0
110
React本体のコードリーディング
high_g_engineer
1
140
変わらないものが、変わるものを決める — 意図駆動開発 × イベントソーシング × イミュータブル | What Doesn't Change Decides What Can — IDD × Event Sourcing × Immutability
tomohisa
0
1.8k
Featured
See All Featured
Being A Developer After 40
akosma
91
590k
Build your cross-platform service in a week with App Engine
jlugia
234
19k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
240
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.2k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
For a Future-Friendly Web
brad_frost
183
10k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3k
Chasing Engaging Ingredients in Design
codingconduct
0
270
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Balancing Empowerment & Direction
lara
6
1.2k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
Art, The Web, and Tiny UX
lynnandtonic
304
22k
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ʁ