jest-runtime
Advanced tools
Comparing version 13.2.3 to 13.3.0-alpha.4eb0c908
@@ -14,2 +14,3 @@ /** | ||
const args = require('./args'); | ||
const chalk = require('chalk'); | ||
const os = require('os'); | ||
@@ -79,3 +80,3 @@ const path = require('path'); | ||
catch(e => { | ||
console.error(e); | ||
console.error(chalk.red(e)); | ||
process.on('exit', () => process.exit(1));});});} | ||
@@ -82,0 +83,0 @@ |
@@ -18,2 +18,3 @@ /** | ||
const createHasteMap = require('jest-haste-map').create; | ||
@@ -24,3 +25,3 @@ const createResolver = require('jest-resolve').create; | ||
const path = require('path'); | ||
const transform = require('./lib/transform'); | ||
const transform = require('./transform'); | ||
const utils = require('jest-util'); | ||
@@ -332,5 +333,18 @@ | ||
_shouldCollectCoverage(filename) { | ||
const collectOnlyFrom = this._config.collectCoverageOnlyFrom; | ||
const shouldCollectCoverage = | ||
this._config.collectCoverage && !collectOnlyFrom || | ||
collectOnlyFrom && collectOnlyFrom[filename]; | ||
return ( | ||
shouldCollectCoverage && | ||
!this._coverageRegex.test(filename) && | ||
!(this._mocksPattern && this._mocksPattern.test(filename)) && | ||
!this._testRegex.test(filename));} | ||
_execModule(localModule) { | ||
// If the environment was disposed, prevent this module from | ||
// being executed. | ||
// If the environment was disposed, prevent this module from being executed. | ||
if (!this._environment.global) { | ||
@@ -341,27 +355,10 @@ return;} | ||
const filename = localModule.filename; | ||
const shouldCollectCoverage = this._shouldCollectCoverage(filename); | ||
const collectors = this._coverageCollectors; | ||
const collectOnlyFrom = this._config.collectCoverageOnlyFrom; | ||
const shouldCollectCoverage = | ||
this._config.collectCoverage && !collectOnlyFrom || | ||
collectOnlyFrom && collectOnlyFrom[filename]; | ||
if (shouldCollectCoverage && !collectors[filename]) { | ||
collectors[filename] = new this._CoverageCollector();} | ||
let moduleContent = transform(filename, this._config); | ||
let collectorStore; | ||
if ( | ||
shouldCollectCoverage && | ||
!this._coverageRegex.test(filename) && | ||
!(this._mocksPattern && this._mocksPattern.test(filename)) && | ||
!this._testRegex.test(filename)) | ||
{ | ||
if (!collectors[filename]) { | ||
collectors[filename] = new this._CoverageCollector( | ||
moduleContent, | ||
filename);} | ||
const collectorStore = | ||
shouldCollectCoverage && collectors[filename].getCoverageDataStore(); | ||
const collector = collectors[filename]; | ||
collectorStore = collector.getCoverageDataStore(); | ||
moduleContent = collector.getInstrumentedSource('$JEST_COVERAGE_DATA');} | ||
const lastExecutingModulePath = this._currentlyExecutingModulePath; | ||
@@ -378,4 +375,13 @@ this._currentlyExecutingModulePath = filename; | ||
const wrapperFunc = this._runSourceText(moduleContent, filename); | ||
wrapperFunc.call( | ||
const script = transform(filename, this._config, { | ||
instrument: shouldCollectCoverage && ( | ||
source => collectors[filename].getInstrumentedSource( | ||
source, | ||
filename, | ||
'$JEST')) }); | ||
const wrapper = this._runScript(script, filename); | ||
wrapper.call( | ||
localModule.exports, // module context | ||
@@ -389,3 +395,3 @@ localModule, // module object | ||
this._createRuntimeFor(filename), // jest object | ||
collectorStore); | ||
collectorStore); // the coverage object | ||
@@ -397,12 +403,10 @@ | ||
_runSourceText(moduleContent, filename) { | ||
/* eslint-disable max-len */ | ||
const config = this._config; | ||
const relative = filePath => path.relative(config.rootDir, filePath); | ||
const env = this._environment; | ||
const evalResultVariable = 'Object.<anonymous>'; | ||
const wrapper = '({ "' + evalResultVariable + '": function(module, exports, require, __dirname, __filename, global, jest, $JEST_COVERAGE_DATA) {' + moduleContent + '\n}});'; | ||
_runScript(script, filename) { | ||
try { | ||
return env.runSourceText(wrapper, filename)[evalResultVariable];} | ||
return this._environment.runScript(script)[ | ||
transform.EVAL_RESULT_VARIABLE];} | ||
catch (e) { | ||
const config = this._config; | ||
const relative = filePath => path.relative(config.rootDir, filePath); | ||
if (e.constructor.name === 'SyntaxError') { | ||
@@ -417,2 +421,3 @@ const hasPreprocessor = config.scriptPreprocessor; | ||
''; | ||
/* eslint-disable max-len */ | ||
throw new SyntaxError( | ||
@@ -423,9 +428,8 @@ `${ e.message } in file '${ relative(filename) }'.\n\n` + | ||
'If you are currently setting up Jest or modifying your preprocessor, try `jest --no-cache`.\n' + | ||
`Preprocessor: ${ preprocessorInfo }.\n${ babelInfo }` + | ||
`Jest tried to the execute the following ${ hasPreprocessor ? 'preprocessed ' : '' }code:\n${ moduleContent }\n`);} | ||
`Preprocessor: ${ preprocessorInfo }.\n${ babelInfo }`); | ||
/* eslint-enable max-len */} | ||
throw e;} | ||
throw e;}} | ||
/* eslint-enable max-len */} | ||
@@ -672,3 +676,2 @@ | ||
clearAllTimers: () => this._environment.fakeTimers.clearAllTimers(), | ||
currentTestPath: () => this._environment.testFilePath, | ||
@@ -675,0 +678,0 @@ dontMock: unmock, |
{ | ||
"name": "jest-runtime", | ||
"version": "13.2.3", | ||
"version": "13.3.0-alpha.4eb0c908", | ||
"repository": { | ||
@@ -11,10 +11,10 @@ "type": "git", | ||
"dependencies": { | ||
"chalk": "^1.1.3", | ||
"graceful-fs": "^4.1.3", | ||
"jest-config": "^13.2.3", | ||
"jest-environment-jsdom": "^13.2.2", | ||
"jest-haste-map": "^13.2.2", | ||
"jest-mock": "^13.2.2", | ||
"jest-resolve": "^13.2.2", | ||
"jest-snapshot": "^13.2.3", | ||
"jest-util": "^13.2.2", | ||
"jest-config": "^13.3.0-alpha.4eb0c908", | ||
"jest-haste-map": "^13.3.0-alpha.4eb0c908", | ||
"jest-mock": "^13.3.0-alpha.4eb0c908", | ||
"jest-resolve": "^13.3.0-alpha.4eb0c908", | ||
"jest-snapshot": "^13.3.0-alpha.4eb0c908", | ||
"jest-util": "^13.3.0-alpha.4eb0c908", | ||
"json-stable-stringify": "^1.0.0", | ||
@@ -27,8 +27,11 @@ "yargs": "^4.7.1" | ||
"devDependencies": { | ||
"jest-config": "^13.2.3" | ||
"jest-config": "^13.3.0-alpha.4eb0c908", | ||
"jest-environment-node": "^13.3.0-alpha.4eb0c908" | ||
}, | ||
"jest": { | ||
"automock": false, | ||
"rootDir": "./build", | ||
"testEnvironment": "jest-environment-node", | ||
"rootDir": "./src", | ||
"scriptPreprocessor": "../../babel-jest", | ||
"setupTestFrameworkScriptFile": "<rootDir>/__mocks__/env.js", | ||
"testEnvironment": "node", | ||
"testPathIgnorePatterns": [ | ||
@@ -35,0 +38,0 @@ "/__tests__/[^/]*/.+" |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
8
30722
2
7
723
2
+ Addedchalk@^1.1.3
+ Addedjest-config@13.3.0-alpha.g8b48d59(transitive)
+ Addedjest-diff@13.3.0-alpha.g8b48d59(transitive)
+ Addedjest-environment-jsdom@13.3.0-alpha.g8b48d59(transitive)
+ Addedjest-environment-node@13.3.0-alpha.g8b48d59(transitive)
+ Addedjest-haste-map@13.3.0-alpha.g8b48d59(transitive)
+ Addedjest-jasmine1@13.3.0-alpha.g8b48d59(transitive)
+ Addedjest-jasmine2@13.3.0-alpha.g8b48d59(transitive)
+ Addedjest-matcher-utils@13.3.0-alpha.g8b48d59(transitive)
+ Addedjest-matchers@13.3.0-alpha.g8b48d59(transitive)
+ Addedjest-mock@13.3.0-alpha.g8b48d59(transitive)
+ Addedjest-resolve@13.3.0-alpha.g8b48d59(transitive)
+ Addedjest-snapshot@13.3.0-alpha.g8b48d59(transitive)
+ Addedjest-util@13.3.0-alpha.g8b48d59(transitive)
- Removedjest-environment-jsdom@^13.2.2
- Removedjest-config@13.2.3(transitive)
- Removedjest-environment-jsdom@13.2.2(transitive)
- Removedjest-environment-node@13.2.2(transitive)
- Removedjest-haste-map@13.2.2(transitive)
- Removedjest-jasmine1@13.2.2(transitive)
- Removedjest-jasmine2@13.2.3(transitive)
- Removedjest-mock@13.2.2(transitive)
- Removedjest-resolve@13.2.2(transitive)
- Removedjest-snapshot@13.2.3(transitive)
- Removedjest-util@13.2.2(transitive)