ãã¹ãã®å®è¡æéã2åéããã話
webpack-dev-serverã®ãã¹ããé«éåãã¾ããã
jestã使ã£ã¦ãã¦ã--runInBand
ãä»ã¾ã§ã¯ä½¿ã£ã¦ãã¾ãããããããå¤ãã¾ããã
--runInBand
jestã¯ããã©ã«ãã§ã¯ã¼ã«ã¼ã使ã並åå®è¡ãè¡ãã¾ãã
ãããããã®ãªãã·ã§ã³ãã¤ããã¨ãããç´åå®è¡ã§ãã¾ãã
çç±ã¨ãã¦ã¯ãserverã®listenãããã¹ããå¤ããmochaã§æ¸ããã¦ãããããæ¥ã«jestã«ç§»è¡ãã¦ãã³ã¼ãèªä½ã並åå®è¡ã§ãããã®ã§ã¯ãªãã£ãããã§ãã
PR
ãã®PRã¯ãããã¢ã§æ¸ããã¾ãã:)
ãã pic.twitter.com/B7g2HBl76H
— è丸ãã¡ã³ (@about_hiroppy) 2019å¹´6æ9æ¥
çµæ
ç´åå®è¡
Test Suites: 1 skipped, 49 passed, 49 of 50 total Tests: 9 skipped, 419 passed, 428 total Snapshots: 152 passed, 152 total Time: 113.313s, estimated 173s Ran all test suites.
並åå®è¡
Test Suites: 1 skipped, 49 passed, 49 of 50 total Tests: 9 skipped, 419 passed, 428 total Snapshots: 152 passed, 152 total Time: 60.5s Ran all test suites.
ç´2åãéããªãã¾ããð
æ¦ç¥
å½ããåã§ããããã¼ããå¯è±ªçã«ä½¿ããã¨ã«ããã並åå®è¡ãããã¾ãã
ãã¼ãããã
å½åã¯åæ°ãããªãã¦ããã¼ãçªå·ã«ãã¦ãã®ã§ãããæè»æ§ããªãã£ããããåæ°ã«å¤æ´ãã¾ããã
ã¾ãããã®æ¸ãæ¹ã ã¨ææ¸ãã®ãã¹ã«ããéè¤ã絶対ã«çºçãã¾ããã
const portsList = { cli: 2, // cliã®ãã¹ãã§ã¯ã2åãã¼ãã使ã sockJSClient: 1, // ãã¡ã¤ã«åãå°æåã ã£ãã®ã§ãå¥PRã§ç´ã SockJSServer: 1, Client: 1, ClientOptions: 3, MultiCompiler: 1, ... }; let startPort = 8079; const ports = {}; Object.entries(portsList).forEach(([key, value]) => { // no-plusplusã®å½±é¿ã§ ++ ã¯ãªã ports[key] = value === 1 ? (startPort += 1) : [...new Array(value)].map(() => (startPort += 1)); }); module.exports = ports; // const [port1, port2] = require('./ports-map')['cli'];
èµ·åæ
jestã«ã¯ãååèµ·åæã«ä¸åã ãå®è¡ã§ãããglobalSetup
ã¨ãããã¼ãåå¨ãã¾ãã
ããã¦ãèµ·åæã«ä½¿ç¨ãããã¹ã¦ã®ãã¼ãã空ãã¦ãããã確èªããã¹ã¯ãªãããå®è¡ããã¾ãã
// jest.config.js globalSetup: '<rootDir>/globalSetupTest.js' // globalSetupTest.js // node.jsã®ãã¤ãã£ãã§ãã¼ã確èªããã®ããã©ãããã®ã§ãã®ã¢ã¸ã¥ã¼ã«ã使ã const tcpPortUsed = require('tcp-port-used'); const ports = require('./test/ports-map'); async function validatePorts() { const samples = []; Object.entries(ports).forEach(([key, value]) => { const arr = Array.isArray(value) ? value : [value]; arr.forEach((port) => { const check = tcpPortUsed.check(port, 'localhost').then((inUse) => { if (inUse) throw new Error(`${port} has already used. [${key}]`); }); samples.push(check); }); }); try { await Promise.all(samples); } catch (e) { console.error(e); process.exit(1); } } module.exports = validatePorts;
ããã§ããã¹ãå®è¡åã«ãã¹ãã§ä½¿ç¨ãããã¹ã¦ã®ãã¼ãã使ç¨ããã¦ããªãå ´åã®ã¿ãã¹ããå®è¡ã§ããããã«ãªãã¾ãã
ãã¹ãã³ã¼ã
åãã¹ãã以ä¸ã®ããã«ãã¼ããå¼ç¨ããã°ç«¶åããªãã§ãã
const [port1, port2, port3] = require('../ports-map').ClientOptions;
ãã ããã¼ãè¾¼ã¿ã®snapshotãåã£ã¦ããå ´åãçµæ§æ´æ°ãèµ°ããããã®ã§æ³¨æãã¦ãã ããã
ä¸ã¤çãä¸ã¨ãã§ãã¼ãå¢ããã¨ããè¾¼ã¿ã¾ãã
ãããã«
ã¾ããserverãèµ·åããå¤ãã®ãã¹ãã並åå®è¡ããå ´åã®ãã¼ã管çã®ãã¹ããã©ã¯ãã£ã¹ããã¾ãã¡ããããªãã§ãã
ãµã¼ãã¼èµ·åã°ã£ãããã£ã¦ãåèã«ãªããããã¯ãããã£ããæãã¦ãã ããã
ä¸æ¦ãä»ã®ã¡ã³ããã®æè¦ãå¾
ã¡ã¤ã¤ãã£ã¨ããæ¹æ³ãããã°èãã¾ãã
ãã®æ¦ç¥ã¯ãã¬ãã¥ã¼ã«ãã£ã¦å¤ããå¯è½æ§ãããã¾ãã
ãã©ãä¸çªä½ãè¨ãããã£ããã£ã¦è¨ãã¨ã並åå®è¡ã¯CPUããã£ã¡ã使ããã©ãã£ãéããªããï¼ï¼ï¼ã£ã¦ãã¨ã§ããã(å½ããå)
追è¨
Node6ããµãã¼ã対象å¤ã«ããã®ã§ãasync/awaitã使ããããã«ãªãã¾ããð