jest-jasmine2
Advanced tools
Comparing version 14.0.0 to 14.2.0-alpha.ca8bfb6e
@@ -19,2 +19,3 @@ /** | ||
const not = Object.assign(jasmineMatchers.not, jestMatchers.not); | ||
return Object.assign(jasmineMatchers, jestMatchers, { not });}; | ||
return Object.assign(jasmineMatchers, jestMatchers, { not }); | ||
}; |
@@ -30,4 +30,4 @@ /** | ||
const jasmineScript = new vm.Script(fs.readFileSync(JASMINE_PATH, 'utf8'), { | ||
displayErrors: true, | ||
const jasmineScript = new vm.Script(fs.readFileSync(JASMINE_PATH, 'utf8'), { | ||
displayErrors: true, | ||
filename: JASMINE_PATH }); | ||
@@ -37,27 +37,27 @@ | ||
function isSpyLike(test) { | ||
return test.calls && test.calls.all !== undefined;} | ||
return test.calls && test.calls.all !== undefined; | ||
} | ||
function isMockLike(test) { | ||
return test.mock !== undefined;} | ||
return test.mock !== undefined; | ||
} | ||
function getActualCalls(reporter, calls, limit) { | ||
const count = calls.length - limit; | ||
return ( | ||
`\nActual call${ calls.length === 1 ? '' : 's' }:\n` + | ||
`\nActual call${ calls.length === 1 ? '' : 's' }:\n` + | ||
calls.slice(-limit).map( | ||
call => reporter.getFormatter().prettyPrint(call)). | ||
reverse().join(',\n') + ( | ||
count > 0 ? | ||
`\nand ${ count } other call${ count === 1 ? '' : 's' }.` : ''));} | ||
count > 0 ? | ||
`\nand ${ count } other call${ count === 1 ? '' : 's' }.` : '')); | ||
} | ||
function jasmine2( | ||
config, | ||
environment, | ||
runtime, | ||
testPath) | ||
config, | ||
environment, | ||
runtime, | ||
testPath) | ||
{ | ||
@@ -67,3 +67,3 @@ let env; | ||
const reporter = new JasmineReporter(config, environment); | ||
const reporter = new JasmineReporter(config, environment, testPath); | ||
// Jasmine does stuff with timers that affect running the tests. However, we | ||
@@ -86,20 +86,20 @@ // also mock out all the timer APIs (to make them test-controllable). | ||
if ( | ||
typeof object !== 'object' || | ||
object === null || | ||
environment.global.Node && | ||
object instanceof environment.global.Node && | ||
object.nodeType > 0) | ||
typeof object !== 'object' || | ||
object === null || | ||
environment.global.Node && | ||
object instanceof environment.global.Node && | ||
object.nodeType > 0) | ||
{ | ||
return object;} | ||
return jasmine.util.clone(object);} | ||
return object; | ||
} | ||
return jasmine.util.clone(object); | ||
} | ||
options.expected = shallowCopy(options.expected); | ||
options.actual = shallowCopy(options.actual);} | ||
options.actual = shallowCopy(options.actual); | ||
} | ||
return jasmineBuildExpectationResult.apply(jasmine, arguments); | ||
}; | ||
return jasmineBuildExpectationResult.apply(jasmine, arguments);}; | ||
env = jasmine.getEnv(); | ||
@@ -114,25 +114,25 @@ const jasmineInterface = requireJasmine.interface(jasmine, env); | ||
if (config.setupTestFrameworkScriptFile) { | ||
runtime.requireModule(config.setupTestFrameworkScriptFile);}}); | ||
runtime.requireModule(config.setupTestFrameworkScriptFile); | ||
} | ||
}); | ||
if (!jasmine || !env) { | ||
throw new Error('jasmine2 could not be initialized by Jest');} | ||
throw new Error('jasmine2 could not be initialized by Jest'); | ||
} | ||
const hasIterator = object => !!(object != null && object[Symbol.iterator]); | ||
const iterableEquality = (a, b) => { | ||
if ( | ||
typeof a !== 'object' || | ||
typeof b !== 'object' || | ||
Array.isArray(a) || | ||
Array.isArray(b) || | ||
!hasIterator(a) || | ||
!hasIterator(b)) | ||
typeof a !== 'object' || | ||
typeof b !== 'object' || | ||
Array.isArray(a) || | ||
Array.isArray(b) || | ||
!hasIterator(a) || | ||
!hasIterator(b)) | ||
{ | ||
return undefined;} | ||
return undefined; | ||
} | ||
if (a.constructor !== b.constructor) { | ||
return false;} | ||
return false; | ||
} | ||
const bIterator = b[Symbol.iterator](); | ||
@@ -143,25 +143,25 @@ | ||
if ( | ||
nextB.done || | ||
nextB.done || | ||
!jasmine.matchersUtil.equals( | ||
aValue, | ||
nextB.value, | ||
[iterableEquality])) | ||
aValue, | ||
nextB.value, | ||
[iterableEquality])) | ||
{ | ||
return false;}} | ||
return false; | ||
} | ||
} | ||
if (!bIterator.next().done) { | ||
return false;} | ||
return false; | ||
} | ||
return true; | ||
}; | ||
return true;}; | ||
runtime.setMock( | ||
'', | ||
'jest-check', | ||
'', | ||
'jest-check', | ||
() => { | ||
const jasmineCheck = runtime.requireInternalModule(JASMINE_CHECK_PATH); | ||
return jasmineCheck(environment.global, config.testcheckOptions);}, | ||
return jasmineCheck(environment.global, config.testcheckOptions); | ||
}, | ||
{ virtual: true }); | ||
@@ -172,7 +172,7 @@ | ||
jasmine.addCustomEqualityTester(iterableEquality); | ||
jasmine.addMatchers({ | ||
jasmine.addMatchers({ | ||
toMatchSnapshot: snapshot.matcher( | ||
testPath, | ||
config, | ||
jasmine, | ||
testPath, | ||
config, | ||
jasmine, | ||
snapshotState) }); | ||
@@ -182,35 +182,35 @@ | ||
jasmine.addMatchers({ | ||
toBeCalled: () => ({ | ||
jasmine.addMatchers({ | ||
toBeCalled: () => ({ | ||
compare: (actual, expected) => { | ||
if (expected) { | ||
throw Error( | ||
'toBeCalled() does not accept parameters, use ' + | ||
'toBeCalledWith instead.');} | ||
'toBeCalled() does not accept parameters, use ' + | ||
'toBeCalledWith instead.'); | ||
} | ||
const isSpy = isSpyLike(actual); | ||
if (!isSpy && !isMockLike(actual)) { | ||
throw Error( | ||
'toBeCalled() should be used on a mock function or ' + | ||
'a jasmine spy.');} | ||
'toBeCalled() should be used on a mock function or ' + | ||
'a jasmine spy.'); | ||
const calls = isSpy ? | ||
actual.calls.all().map(x => x.args) : | ||
} | ||
const calls = isSpy ? | ||
actual.calls.all().map(x => x.args) : | ||
actual.mock.calls; | ||
const pass = calls.length !== 0; | ||
const message = | ||
pass ? | ||
'Expected not to be called' : | ||
const message = | ||
pass ? | ||
'Expected not to be called' : | ||
'Expected to be called at least once'; | ||
return { | ||
pass, | ||
message };} }), | ||
return { | ||
pass, | ||
message }; | ||
} }), | ||
lastCalledWith: util => ({ | ||
lastCalledWith: util => ({ | ||
compare(actual) { | ||
@@ -220,8 +220,8 @@ const isSpy = isSpyLike(actual); | ||
throw Error( | ||
'lastCalledWith() should be used on a mock function or ' + | ||
'a jasmine spy.');} | ||
'lastCalledWith() should be used on a mock function or ' + | ||
'a jasmine spy.'); | ||
const calls = isSpy ? | ||
actual.calls.all().map(x => x.args) : | ||
} | ||
const calls = isSpy ? | ||
actual.calls.all().map(x => x.args) : | ||
actual.mock.calls; | ||
@@ -231,30 +231,30 @@ const expected = Array.prototype.slice.call(arguments, 1); | ||
if (!pass) { | ||
return { | ||
pass, | ||
return { | ||
pass, | ||
// $FlowFixMe - get/set properties not yet supported | ||
get message() { | ||
return ( | ||
`Wasn't last called with the expected values.\n` + | ||
'Expected call:\n' + | ||
reporter.getFormatter().prettyPrint(expected) + | ||
getActualCalls(reporter, calls, LAST_CALL_PRINT_LIMIT));} };} | ||
`Wasn't last called with the expected values.\n` + | ||
'Expected call:\n' + | ||
reporter.getFormatter().prettyPrint(expected) + | ||
getActualCalls(reporter, calls, LAST_CALL_PRINT_LIMIT)); | ||
} }; | ||
return { | ||
pass, | ||
} | ||
return { | ||
pass, | ||
// $FlowFixMe - get/set properties not yet supported | ||
get message() { | ||
return ( | ||
`Shouldn't have been last called with\n` + | ||
reporter.getFormatter().prettyPrint(expected));} };} }), | ||
`Shouldn't have been last called with\n` + | ||
reporter.getFormatter().prettyPrint(expected)); | ||
} }; | ||
} }), | ||
toBeCalledWith: util => ({ | ||
toBeCalledWith: util => ({ | ||
compare(actual) { | ||
@@ -264,8 +264,8 @@ const isSpy = isSpyLike(actual); | ||
throw Error( | ||
'toBeCalledWith() should be used on a mock function or ' + | ||
'a jasmine spy.');} | ||
'toBeCalledWith() should be used on a mock function or ' + | ||
'a jasmine spy.'); | ||
const calls = isSpy ? | ||
actual.calls.all().map(x => x.args) : | ||
} | ||
const calls = isSpy ? | ||
actual.calls.all().map(x => x.args) : | ||
actual.mock.calls; | ||
@@ -275,34 +275,34 @@ const expected = Array.prototype.slice.call(arguments, 1); | ||
if (!pass) { | ||
return { | ||
pass, | ||
return { | ||
pass, | ||
// $FlowFixMe - get/set properties not yet supported | ||
get message() { | ||
return ( | ||
'Was not called with the expected values.\n' + | ||
'Expected call:\n' + | ||
reporter.getFormatter().prettyPrint(expected) + | ||
getActualCalls(reporter, calls, CALL_PRINT_LIMIT));} };} | ||
'Was not called with the expected values.\n' + | ||
'Expected call:\n' + | ||
reporter.getFormatter().prettyPrint(expected) + | ||
getActualCalls(reporter, calls, CALL_PRINT_LIMIT)); | ||
} }; | ||
return { | ||
pass, | ||
} | ||
return { | ||
pass, | ||
// $FlowFixMe - get/set properties not yet supported | ||
get message() { | ||
return ( | ||
`Shouldn't have been called with\n` + | ||
reporter.getFormatter().prettyPrint(expected));} };} }) }); | ||
`Shouldn't have been called with\n` + | ||
reporter.getFormatter().prettyPrint(expected)); | ||
} }; | ||
} }) }); | ||
if (!config.persistModuleRegistryBetweenSpecs) { | ||
runtime.resetModuleRegistry();}}); | ||
runtime.resetModuleRegistry(); | ||
} | ||
}); | ||
const snapshotState = snapshot.getSnapshotState(jasmine, testPath); | ||
@@ -326,4 +326,4 @@ | ||
if (updateSnapshot) { | ||
currentSnapshot.removeUncheckedKeys();} | ||
currentSnapshot.removeUncheckedKeys(); | ||
} | ||
const status = currentSnapshot.save(updateSnapshot); | ||
@@ -337,6 +337,6 @@ | ||
results.snapshot.updated = snapshotState.updated; | ||
return results;});} | ||
return results; | ||
}); | ||
} | ||
module.exports = jasmine2; |
@@ -26,9 +26,9 @@ /** | ||
gens = options; | ||
options = {};} | ||
options = {}; | ||
} | ||
const mergedOptions = Object.assign({}, configOptions, options); | ||
return original(specName, mergedOptions, gens, propertyFn);};}; | ||
return original(specName, mergedOptions, gens, propertyFn); | ||
}; | ||
}; | ||
makeMergeOptions(check, 'it'); | ||
@@ -39,2 +39,3 @@ makeMergeOptions(check, 'iit'); | ||
makeMergeOptions(check, 'xit'); | ||
return { check, gen };}; | ||
return { check, gen }; | ||
}; |
@@ -12,5 +12,5 @@ /** | ||
/** | ||
* This module adds ability to test async promise code with jasmine by | ||
* returning a promise from `it\fit` block. | ||
*/ | ||
* This module adds ability to test async promise code with jasmine by | ||
* returning a promise from `it\fit` block. | ||
*/ | ||
@@ -22,5 +22,5 @@ 'use strict'; | ||
function isPromise(obj) { | ||
return obj && typeof obj.then === 'function';} | ||
return obj && typeof obj.then === 'function'; | ||
} | ||
// return a wrapping function: `env.fit = promisifyIt(env.it, env)` | ||
@@ -30,5 +30,5 @@ function promisifyIt(originalFn, env) { | ||
if (!fn) { | ||
return null;} | ||
return null; | ||
} | ||
const isAsync = fn.length; // `done` was passed | ||
@@ -38,4 +38,4 @@ | ||
// jasmine will handle it | ||
return originalFn.call(env, specName, fn, timeout);} else | ||
{ | ||
return originalFn.call(env, specName, fn, timeout); | ||
} else { | ||
// we make *all* tests async and run `done` right away if they | ||
@@ -47,15 +47,15 @@ // didn't return a promise. | ||
if (isPromise(returnValue)) { | ||
returnValue.then(done).catch(done.fail);} else | ||
if (returnValue === undefined) { | ||
done();} else | ||
{ | ||
returnValue.then(done).catch(done.fail); | ||
} else if (returnValue === undefined) { | ||
done(); | ||
} else { | ||
done.fail(new Error( | ||
'Jest: `it` must return either a Promise or undefined.'));}}, | ||
'Jest: `it` must return either a Promise or undefined.')); | ||
} | ||
}, timeout); | ||
} | ||
}; | ||
} | ||
timeout);}};} | ||
function install(global) { | ||
@@ -66,6 +66,6 @@ const jasmine = global.jasmine; | ||
global.pit = env.it = promisifyIt(env.it, env); | ||
env.fit = promisifyIt(env.fit, env);} | ||
env.fit = promisifyIt(env.fit, env); | ||
} | ||
module.exports = { | ||
module.exports = { | ||
install }; |
@@ -23,4 +23,4 @@ /** | ||
const jasmineRequire = require('../vendor/jasmine-2.4.1.js'); | ||
const jasmine = jasmineRequire.core(jasmineRequire); | ||
const JasmineFormatter = require('jest-util').JasmineFormatter; | ||
const jasmine = jasmineRequire.core(jasmineRequire);var _require = | ||
require('jest-util');const formatResultsErrors = _require.formatResultsErrors;const JasmineFormatter = _require.JasmineFormatter; | ||
@@ -49,4 +49,8 @@ | ||
constructor(config, environment) { | ||
constructor(config, environment, testPath) { | ||
this._formatter = new JasmineFormatter(jasmine, environment, config); | ||
this._config = config; | ||
this._testPath = testPath; | ||
this._testResults = []; | ||
@@ -56,23 +60,23 @@ this._currentSuites = []; | ||
this._resultsPromise = new Promise(resolve => this._resolve = resolve); | ||
this._startTimes = new Map();} | ||
this._startTimes = new Map(); | ||
} | ||
specStarted(spec) { | ||
this._startTimes.set(spec.id, Date.now());} | ||
this._startTimes.set(spec.id, Date.now()); | ||
} | ||
specDone(result) { | ||
this._testResults.push( | ||
this._extractSpecResults(result, this._currentSuites.slice(0)));} | ||
this._extractSpecResults(result, this._currentSuites.slice(0))); | ||
} | ||
suiteStarted(suite) { | ||
this._currentSuites.push(suite.description);} | ||
this._currentSuites.push(suite.description); | ||
} | ||
suiteDone() { | ||
this._currentSuites.pop();} | ||
this._currentSuites.pop(); | ||
} | ||
jasmineDone() { | ||
@@ -85,39 +89,49 @@ let numFailingTests = 0; | ||
if (testResult.status === 'failed') { | ||
numFailingTests++;} else | ||
if (testResult.status === 'pending') { | ||
numPendingTests++;} else | ||
{ | ||
numPassingTests++;}}); | ||
numFailingTests++; | ||
} else if (testResult.status === 'pending') { | ||
numPendingTests++; | ||
} else { | ||
numPassingTests++; | ||
} | ||
}); | ||
const testResult = { | ||
failureMessage: null, | ||
numFailingTests, | ||
numPassingTests, | ||
numPendingTests, | ||
testResults, | ||
snapshot: {} }; | ||
this._resolve({ | ||
numFailingTests, | ||
numPassingTests, | ||
numPendingTests, | ||
testResults, | ||
snapshot: {} });} | ||
testResult.failureMessage = formatResultsErrors( | ||
testResult, | ||
this._config, | ||
this._testPath); | ||
this._resolve(testResult); | ||
} | ||
getFormatter() { | ||
return this._formatter;} | ||
return this._formatter; | ||
} | ||
getResults() { | ||
return this._resultsPromise;} | ||
return this._resultsPromise; | ||
} | ||
_extractSpecResults( | ||
specResult, | ||
ancestorTitles) | ||
specResult, | ||
ancestorTitles) | ||
{ | ||
const start = this._startTimes.get(specResult.id); | ||
const duration = start ? Date.now() - start : undefined; | ||
const status = | ||
const status = | ||
specResult.status === 'disabled' ? 'pending' : specResult.status; | ||
const results = { | ||
title: 'it ' + specResult.description, | ||
status, | ||
ancestorTitles, | ||
failureMessages: [], | ||
const results = { | ||
title: specResult.description, | ||
status, | ||
ancestorTitles, | ||
failureMessages: [], | ||
numPassingAsserts: 0, // Jasmine2 only returns an array of failed asserts. | ||
@@ -130,13 +144,13 @@ duration }; | ||
if (!failed.matcherName && failed.stack) { | ||
message = failed.stack;} else | ||
{ | ||
message = this._formatter.formatMatchFailure(failed);} | ||
message = failed.stack; | ||
} else { | ||
message = this._formatter.formatMatchFailure(failed); | ||
} | ||
results.failureMessages.push(message); | ||
}); | ||
results.failureMessages.push(message);}); | ||
return results; | ||
}} | ||
return results;}} | ||
module.exports = Jasmine2Reporter; |
{ | ||
"name": "jest-jasmine2", | ||
"version": "14.0.0", | ||
"version": "14.2.0-alpha.ca8bfb6e", | ||
"repository": { | ||
@@ -13,11 +13,6 @@ "type": "git", | ||
"jasmine-check": "^0.1.4", | ||
"jest-matchers": "^14.0.0", | ||
"jest-snapshot": "^14.0.0", | ||
"jest-util": "^14.0.0" | ||
"jest-matchers": "^14.2.0-alpha.ca8bfb6e", | ||
"jest-snapshot": "^14.2.0-alpha.ca8bfb6e", | ||
"jest-util": "^14.2.0-alpha.ca8bfb6e" | ||
}, | ||
"jest": { | ||
"rootDir": "./src", | ||
"scriptPreprocessor": "../../babel-jest", | ||
"testEnvironment": "node" | ||
}, | ||
"scripts": { | ||
@@ -24,0 +19,0 @@ "test": "../../packages/jest-cli/bin/jest.js" |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
108844
3279
2
+ Addedjest-diff@14.2.0-alpha.ca8bfb6e(transitive)
+ Addedjest-file-exists@14.2.0-alpha.ca8bfb6e(transitive)
+ Addedjest-matcher-utils@14.2.0-alpha.ca8bfb6e(transitive)
+ Addedjest-matchers@14.2.0-alpha.ca8bfb6e(transitive)
+ Addedjest-mock@14.2.0-alpha.ca8bfb6e(transitive)
+ Addedjest-snapshot@14.2.0-alpha.ca8bfb6e(transitive)
+ Addedjest-util@14.2.0-alpha.ca8bfb6e(transitive)
- Removedjest-diff@14.0.0(transitive)
- Removedjest-file-exists@14.0.0(transitive)
- Removedjest-matcher-utils@14.0.0(transitive)
- Removedjest-matchers@14.0.0(transitive)
- Removedjest-mock@14.0.0(transitive)
- Removedjest-snapshot@14.0.0(transitive)
- Removedjest-util@14.0.0(transitive)