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
Testing modern-day JavaScript Applications
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Remon Oldenbeuving
September 09, 2015
Programming
34
0
Share
Testing modern-day JavaScript Applications
Remon Oldenbeuving
September 09, 2015
More Decks by Remon Oldenbeuving
See All by Remon Oldenbeuving
Groningen.rb RailsConf 2015 recap
rso
0
41
Other Decks in Programming
See All in Programming
Geminiをパートナーに神社DXシステムを個人開発した話(いなめぐDX 開発振り返り)
fujiba
0
130
ローカルで稼働するAI エージェントを超えて / beyond-local-ai-agents
gawa
1
190
Mastering Event Sourcing: Your Parents Holidayed in Yugoslavia
super_marek
0
130
条件判定に名前、つけてますか? #phperkaigi #c
77web
2
880
S3ストレージクラスの「見える」「ある」「使える」は全部違う ─ 体験から見た、仕様の深淵を覗く
ya_ma23
0
1.2k
Ruby and LLM Ecosystem 2nd
koic
1
1.4k
GC言語のWasm化とComponent Modelサポートの実践と課題 - Scalaの場合
tanishiking
0
130
今からFlash開発できるわけないじゃん、ムリムリ! (※ムリじゃなかった!?)
arkw
0
170
AWS×クラウドネイティブソフトウェア設計 / AWS x Cloud-Native Software Design
nrslib
16
3.5k
AI活用のコスパを最大化する方法
ochtum
0
360
脱 雰囲気実装!AgentCoreを良い感じにWEBアプリケーションに組み込むために
takuyay0ne
3
420
それはエンジニアリングの糧である:AI開発のためにAIのOSSを開発する現場より / It serves as fuel for engineering: insights from the field of developing open-source AI for AI development.
nrslib
1
700
Featured
See All Featured
The World Runs on Bad Software
bkeepers
PRO
72
12k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
240
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
170
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.2k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
140
Designing for Performance
lara
611
70k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
230
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
120
Transcript
Build for the web: Karma/Webpack
Build for the web: Karma/Webpack
Testing modern-day JavaScript applications
Who is I? Remon Oldenbeuving https://twitter.com/R51 https://github.com/RSO Software Engineer @
HackerOne
hackerone $ git log —reverse | head -6 commit 450099be9115481241edda6aec3968419ea39e2f
Author: Remon Oldenbeuving <
[email protected]
> Date: Fri Dec 14 03:29:34 2012 -0800 Initial commit
hackerone $ git log —reverse | head -6 commit 450099be9115481241edda6aec3968419ea39e2f
Author: Remon Oldenbeuving <
[email protected]
> Date: Fri Dec 14 03:29:34 2012 -0800 Initial commit
Who is I? Remon Oldenbeuving https://twitter.com/R51 https://github.com/RSO Software Engineer @
HackerOne
Testing modern-day JavaScript applications
“Writing frontend tests should be as obvious as writing backend
tests” Me, just now
hackerone $ bundle exec spec spec/integration ............................................. 5236 examples, 0
failures real 6m34.734s hackerone $ bundle exec teaspoon ............................................. 559 examples, 0 failures real 1m55.100s
None
Why? • Harder to write (good) JavaScript tests • Culture
• All objects defined in global scope • Slow (?)
None
Where we at? • Everything is defined on the window
• Mocha • SinonJS • ChaiJS • Teaspoon
Where do we want to go? • Modules (both internal
and external) • Split frontend from Rails • Sauce Labs
Modules • Browserify • Modular (haha) approach • Lots of
plugins • Webpack • Ability to bundle all assets
Mocking modules • A good way to scope your test
• Could help with keeping the DOM of the testsuite clean • But where to stop?
Mocking modules • Browserify: proxyquireify (WTF) # component.js var link
= require(‘link’); # component.test.js var proxyquire = require(‘proxyquireify’)(require); var stubs = { link: function() {} }; var component = proxyquire(‘component’, stubs);
Mocking modules • Webpack: rewire # component.js var link =
require(‘link’); # component.test.js var rewire = require(‘rewire’); var component = rewire(‘component’); component.__set__(‘link’, function() {});
Test runners • Zuul • Mocha • Karma • Jest
Test runners: Zuul
Test runners: Mocha • Test framework-gone-runner • Command line tool
runs tests in Node, requires JSDOM • No support for Sauce Labs • Too simple for what we need
Test runners: Karma • Created by the Angular team •
Modular • Big community
Test runners: Jest • Created by Facebook, used by React
• Automagic mocking of external dependencies • No choice in framework (Jasmine over Mocha) • Runs tests in parallel • Fake DOM (JSDOM) • No support for Sauce Labs
None
Karma/Webpack • Pro: • Probably the most mainstream approach •
Two powerful communities • Con: • Either run all tests all the times, or create a separate bundle for every test
Demo time?
Questions?