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
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
Intent as Code
shoppingjaws
6
940
GraphRAGのKnowledge Graphを 直接!見る/View-GraphRAG's-KnowledgeGraph-directly!
tyumugi1113
1
290
AI に Inclusive UI を書かせよう — Design Rules Skill で Compose UI を作り直す
theoriatec2024
1
470
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
9
4k
PHPプロジェクトの結合バランスを可視化する #php_night
kajitack
0
240
DroidKaigi 2026 「個人開発という実験場: Android エンジニアが手にする4つの自由」
slashnephy
0
230
ALB ログから Trace を気合で繋げる技術
fohte
7
880
RSSとCodexを使ってX投稿自動化してみた
ochtum
0
110
ゲームコントローラやキーボードのファームウェアをSwiftで書く
kishikawakatsumi
1
220
20260828_品質と開発生産性を両立させる、AI時代のE2Eテストの考え方
magicpod
0
200
Foundry Localでエージェント開発
seosoft
0
180
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
270
Featured
See All Featured
The Spectacular Lies of Maps
axbom
PRO
1
990
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
6.2k
Leo the Paperboy
mayatellez
9
2.3k
Deep Space Network (abreviated)
tonyrice
0
300
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
530
Amusing Abliteration
ianozsvald
1
290
The browser strikes back
jonoalderson
0
1.7k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.7k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
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ʁ