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
1
3.2k
tc39 x jsconf.jp Panel Discussion 2024
yosuke_furukawa
PRO
0
170
Removing Corepack
yosuke_furukawa
PRO
9
1.3k
JavaScript Runtime とはなにか
yosuke_furukawa
PRO
15
2.5k
Strip Types と Storage
yosuke_furukawa
PRO
4
350
Module Harmony について
yosuke_furukawa
PRO
3
1.6k
LTのやり方
yosuke_furukawa
PRO
16
2.2k
AppRouter Panel Talk
yosuke_furukawa
PRO
3
720
Node.js v22 で変わること
yosuke_furukawa
PRO
13
5.4k
Other Decks in Programming
See All in Programming
たのしいparse.y
ydah
3
120
ドメインイベント増えすぎ問題
h0r15h0
1
190
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
140
CSC305 Lecture 26
javiergs
PRO
0
140
[JAWS-UG横浜 #76] イケてるアップデートを宇宙いち早く紹介するよ!
maroon1st
0
450
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
1
370
開発者とQAの越境で自動テストが増える開発プロセスを実現する
92thunder
1
180
生成AIでGitHubソースコード取得して仕様書を作成
shukob
0
300
Recoilを剥がしている話
kirik
5
6.6k
LLM Supervised Fine-tuningの理論と実践
datanalyticslabo
3
1.1k
17年周年のWebアプリケーションにTanStack Queryを導入する / Implementing TanStack Query in a 17th Anniversary Web Application
saitolume
0
250
命名をリントする
chiroruxx
1
390
Featured
See All Featured
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.4k
Designing for humans not robots
tammielis
250
25k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
2
170
A designer walks into a library…
pauljervisheath
204
24k
Being A Developer After 40
akosma
87
590k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
Scaling GitHub
holman
458
140k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7k
Bash Introduction
62gerente
608
210k
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