2016-11-21 5 views
5

एक नोड ऐप के अंदर जहां मैं क्लाइंट साइड कोड (testEnvironment: 'jsdom') और सर्वर साइड कोड (testEnvironment: 'node') का परीक्षण करने के लिए जेस्ट का उपयोग कर रहा हूं और क्लाइंट और सर्वर दोनों पक्षों के लिए कोड कवरेज एकत्रित कर रहा हूं।क्या कोई जस्ट कॉन्फ़िगरेशन फ़ाइल बढ़ाने के लिए वैसे भी है?

वर्तमान में मैं इसे पूरा करने के लिए बहुत से अनावश्यक विन्यास के साथ 4 जेस्ट कॉन्फ़िगरेशन फ़ाइलों का उपयोग कर रहा हूं।

ग्राहक

{ 
    "bail": true, 
    "verbose": true, 
    "notify": true, 
    "scriptPreprocessor": "./node_modules/babel-jest", 
    "testPathIgnorePatterns": [ 
    "./node_modules", 
    "./coverage", 
    "./dist", 
    "./build" 
    ], 
    "testRegex": "\\.test\\.js" 
} 

ग्राहक कवरेज

{ 
    "bail": true, 
    "verbose": true, 
    "notify": true, 
    "scriptPreprocessor": "./node_modules/babel-jest", 
    "testPathIgnorePatterns": [ 
    "./node_modules", 
    "./coverage", 
    "./dist", 
    "./build" 
    ], 
    "testRegex": "\\.test\\.js", 
    "collectCoverageFrom": ["**/*.js", "!**/node_modules/**"], 
    "collectCoverage": true, 
    "coverageDirectory": "./coverage", 
    "coveragePathIgnorePatterns": [ 
    "./node_modules", 
    "./coverage", 
    "./dist", 
    "./build", 
    "./test" 
    ], 
    "coverageThreshold": { 
    "global": { 
     "branches": 100, 
     "functions": 100, 
     "lines": 100, 
     "statements": 100 
    } 
    } 
} 

सर्वर

{ 
    "bail": true, 
    "verbose": true, 
    "notify": true, 
    "scriptPreprocessor": "./node_modules/babel-jest", 
    "testPathIgnorePatterns": [ 
    "./node_modules", 
    "./coverage", 
    "./dist", 
    "./build" 
    ], 
    "testRegex": "\\.test\\.js", 
    "testEnvironment": "node" 
} 

सर्वर कवरेज

{ 
    "bail": true, 
    "verbose": true, 
    "notify": true, 
    "scriptPreprocessor": "./node_modules/babel-jest", 
    "testPathIgnorePatterns": [ 
    "./node_modules", 
    "./coverage", 
    "./dist", 
    "./build" 
    ], 
    "testRegex": "\\.test\\.js", 
    "testEnvironment": "node", 
    "collectCoverageFrom": ["**/*.js", "!**/node_modules/**"], 
    "collectCoverage": true, 
    "coverageDirectory": "./coverage", 
    "coveragePathIgnorePatterns": [ 
    "./node_modules", 
    "./coverage", 
    "./dist", 
    "./build", 
    "./test" 
    ], 
    "coverageThreshold": { 
    "global": { 
     "branches": 100, 
     "functions": 100, 
     "lines": 100, 
     "statements": 100 
    } 
    } 
} 

मैं 4 बार अपनी कॉन्फ़िगरेशन दोहराए बिना इसे कैसे प्राप्त कर सकता हूं? मैंने preset कॉन्फ़िगरेशन विकल्प देखा है। इसका उपयोग करके मुझे प्रत्येक कॉन्फ़िगरेशन के लिए एक अलग पैकेज बनाना होगा। क्या यह अनुशंसित तरीका है?

उत्तर

1

हां, चूंकि जेस्ट वी 20 आप कॉन्फ़िगर को जेएस फ़ाइल के रूप में परिभाषित कर सकते हैं और समान कॉन्फ़िगरेशन के सामान्य हिस्सों को साझा करने के लिए इसका उपयोग कर सकते हैं। Docs on configuring Jest

डिफ़ॉल्ट रूप से जेस्ट के लिए लग रहा है:

  • jest.config.js
  • "jest"package.json में प्रवेश

... और एक rootDir के रूप में मूल निर्देशिका व्यवहार करता है।

projects विकल्प को भी देखना सुनिश्चित करें, जो मोनोरोपोज़ के अंदर जेस्ट को चलाने में आसान बनाता है (उदा। क्लाइंट + सर्वर कोड एक कोडबेस में)। संदर्भ के लिए यह उत्तर देखें: Testing two environments with jest

संबंधित मुद्दे