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
eater
Search
Yosuke Furukawa
PRO
April 26, 2016
Programming
2
1.3k
eater
node 学園付属小学校の2回目で話した eater の話です。
Yosuke Furukawa
PRO
April 26, 2016
Tweet
Share
More Decks by Yosuke Furukawa
See All by Yosuke Furukawa
Welcome JSConf.jp 2024
yosuke_furukawa
PRO
0
28
tc39 x jsconf.jp Panel Discussion 2024
yosuke_furukawa
PRO
0
150
Removing Corepack
yosuke_furukawa
PRO
9
1.3k
JavaScript Runtime とはなにか
yosuke_furukawa
PRO
15
2.5k
Strip Types と Storage
yosuke_furukawa
PRO
4
340
Module Harmony について
yosuke_furukawa
PRO
3
1.5k
LTのやり方
yosuke_furukawa
PRO
16
2.2k
AppRouter Panel Talk
yosuke_furukawa
PRO
3
700
Node.js v22 で変わること
yosuke_furukawa
PRO
13
5.3k
Other Decks in Programming
See All in Programming
Jakarta EE meets AI
ivargrimstad
0
690
Remix on Hono on Cloudflare Workers
yusukebe
1
300
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
7
7.8k
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
광고 소재 심사 과정에 AI를 도입하여 광고 서비스 생산성 향상시키기
kakao
PRO
0
170
よくできたテンプレート言語として TypeScript + JSX を利用する試み / Using TypeScript + JSX outside of Web Frontend #TSKaigiKansai
izumin5210
6
1.7k
Realtime API 入門
riofujimon
0
150
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
120
as(型アサーション)を書く前にできること
marokanatani
10
2.7k
CSC509 Lecture 11
javiergs
PRO
0
180
タクシーアプリ『GO』のリアルタイムデータ分析基盤における機械学習サービスの活用
mot_techtalk
4
1.5k
flutterkaigi_2024.pdf
kyoheig3
0
150
Featured
See All Featured
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
720
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
Designing for humans not robots
tammielis
250
25k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
A Tale of Four Properties
chriscoyier
156
23k
Unsuck your backbone
ammeep
668
57k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
430
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Transcript
Eater @yosuke_furukawa
@yosuke_furukawa
Hello, Noders. This is Full-time Papa committer
None
child_process.spawn()
None
Node Quiz
Quiz: child_process API ͷԼهͷ ҧ͍ԿͰ͠ΐ͏ 1. exec 2. spawn 3.
fork
A: spawn ͕Ұ൪ϩʔϨϕϧ exec/fork spawn ͷ wrapper
A: exec callback Ͱड͚Δɺ fork JavaScript ͷίʔυ Λ
Node.js ͱͯ͠࠶࣮ߦ͢Δ
child_process.spawn const spawn = require('child_process').spawn; const ls = spawn('ls', [‘-al']);
ls.stdout.on('data', (data) => { console.log(data); }); ls.stderr.on('data', (data) => { console.log(data); }); ls.on('exit', (code) => { if (code !== 0) console.error(`Error occurred`); });
child_process.exec const exec = require('child_process').exec; exec(‘ls -al‘, (err, stdout, stderr)
=> { console.log(`${stdout}`); console.error(`${stderr}`); if (error !== null) { console.error(`Error occurred`); } });
child_process.fork const fork = require('child_process').fork; const ls = fork(‘ls.js’); ls.stdout.on('data',
(data) => { console.log(data); }); ls.stderr.on('data', (data) => { console.log(data); }); ls.on('exit', (code) => { if (code !== 0) console.error(`Error occurred`); });
spawn > exec ͜ͷॱͰ simple exec > spawn ͜ͷॱͰ easy
spawn > fork ͜ͷॱͰ simple fork > spawn ͜ͷॱͰ easy
Easy / Simple ͷҧ͍
None
Simple !== Easy
Simple is “୯७” ٬؍తɺҰͭͷࣄ͔͠͠ͳ͍
Easy is “؆୯” ओ؍తɺ”୭͔”ʹͱͬͯ؆୯ “୭ʹͱͬͯ؆୯” ଘࡏ͠ͳ͍
ॳ৺ऀ͕ؕΓ͕ͪͳࣄɿ Easy ͷݴ༿ʹὃ͞Ε͕ͪ ୭ʹͱͬͯEasy ͳΜͯ͋Γ ͑ͳ͍
ॳ৺ऀ͕ؕΓ͕ͪͳࣄɿ Simple ͱ Easy Λࠞಉ͍ͯ͠ Δʹࠔ͞Ε͕ͪ
Eater
Eater is *Ea*sy *t*est runn*er*
Eater has one simple rule If test file outputs `stderr`
message, the test failed.
Easy => ୭ʹͱͬͯʁ `node` ͔͠Βͳ͍Α͏ͳਓ mocha/jestͷࡉ͔͍ߏจΛ֮ ͑ͯͳͯ͘ɺnode ίϚϯυ ͰεΫϦϓτͱ࣮ͯ͠ߦ͢Δ ͚ͩͰΠφϑͳਓ
Eaterͷtest script `node` command Ͱ࣮ߦͰ͖Δ
Easy => ୭ʹͱͬͯʁ mock/spyΛଟ༻͢Δ͚Ͳɺ mock/spyͷ։์࿙ΕΛΕ ͕ͪͳਓʹͱͬͯ
EaterͷtestҰͭҰ͕ͭผϓ ϩηεͰ࣮ߦ͞ΕΔ
mockΛ։์͠ͳͯ͘OK // you don’t need to fix mock/spy console.log =>
(message) { assert(message.match(/Foo Bar/)); }; const mockDate = new Date(2016, 3, 9); Date.now = () => { return mockDate.valueOf(); }; process.exit => (exitcode) { assert(exitcode === 1); };
͔͠ϓϩηείΞͰ ಄ଧͪʹͳΔ eater ——procs 4 ※procs optionͰՄม
Eater DEMO https://github.com/yosuke- furukawa/eater-demo
Happy Eater https://github.com/yosuke- furukawa/eater