Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: create @jest/test-results package #8034

Merged
merged 6 commits into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use in jasmine
  • Loading branch information
SimenB committed Mar 5, 2019
commit 2e0dc992d6e45e97d8b73275f99a26ed6c8f05b8
1 change: 1 addition & 0 deletions packages/jest-jasmine2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"dependencies": {
"@babel/traverse": "^7.1.0",
"@jest/environment": "^24.1.0",
"@jest/test-result": "^24.1.0",
"@jest/types": "^24.1.0",
"chalk": "^2.0.1",
"co": "^4.6.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-jasmine2/src/expectationResultFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import prettyFormat from 'pretty-format';
import {TestResult} from '@jest/types';
import {FailedAssertion} from '@jest/test-result';

function messageFormatter({error, message, passed}: Options) {
if (passed) {
Expand Down Expand Up @@ -68,7 +68,7 @@ export type Options = {
export default function expectationResultFactory(
options: Options,
initError?: Error,
): TestResult.FailedAssertion {
): FailedAssertion {
const message = messageFormatter(options);
const stack = stackFormatter(options, initError, message);

Expand Down
23 changes: 11 additions & 12 deletions packages/jest-jasmine2/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/

import path from 'path';
import {Config, Global, TestResult} from '@jest/types';
import {Config, Global} from '@jest/types';
import {AssertionResult, TestResult} from '@jest/test-result';
import {JestEnvironment} from '@jest/environment';
import {SnapshotStateType} from 'jest-snapshot';
import Runtime from 'jest-runtime';
Expand All @@ -27,7 +28,7 @@ async function jasmine2(
environment: JestEnvironment,
runtime: Runtime,
testPath: string,
): Promise<TestResult.TestResult> {
): Promise<TestResult> {
const reporter = new JasmineReporter(globalConfig, config, testPath);
const jasmineFactory = runtime.requireInternalModule(JASMINE);
const jasmine = jasmineFactory.create({
Expand Down Expand Up @@ -173,18 +174,16 @@ async function jasmine2(
}

const addSnapshotData = (
results: TestResult.TestResult,
results: TestResult,
snapshotState: SnapshotStateType,
) => {
results.testResults.forEach(
({fullName, status}: TestResult.AssertionResult) => {
if (status === 'pending' || status === 'failed') {
// if test is skipped or failed, we don't want to mark
// its snapshots as obsolete.
snapshotState.markSnapshotsAsCheckedForTest(fullName);
}
},
);
results.testResults.forEach(({fullName, status}: AssertionResult) => {
if (status === 'pending' || status === 'failed') {
// if test is skipped or failed, we don't want to mark
// its snapshots as obsolete.
snapshotState.markSnapshotsAsCheckedForTest(fullName);
}
});

const uncheckedCount = snapshotState.getUncheckedCount();
const uncheckedKeys = snapshotState.getUncheckedKeys();
Expand Down
9 changes: 5 additions & 4 deletions packages/jest-jasmine2/src/jasmine/Spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
/* eslint-disable sort-keys */

import {AssertionError} from 'assert';
import {Config, TestResult} from '@jest/types';
import {Config} from '@jest/types';
import {FailedAssertion, Milliseconds, Status} from '@jest/test-result';

import ExpectationFailed from '../ExpectationFailed';
import expectationResultFactory, {
Expand Down Expand Up @@ -62,12 +63,12 @@ export type SpecResult = {
id: string;
description: string;
fullName: string;
duration?: TestResult.Milliseconds;
failedExpectations: Array<TestResult.FailedAssertion>;
duration?: Milliseconds;
failedExpectations: Array<FailedAssertion>;
testPath: Config.Path;
passedExpectations: Array<ReturnType<typeof expectationResultFactory>>;
pendingReason: string;
status: TestResult.Status;
status: Status;
__callsite?: {
getColumnNumber: () => number;
getLineNumber: () => number;
Expand Down
13 changes: 7 additions & 6 deletions packages/jest-jasmine2/src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import {Config, TestResult} from '@jest/types';
import {Config} from '@jest/types';
import {AssertionResult, TestResult} from '@jest/test-result';
import {formatResultsErrors} from 'jest-message-util';
import {SpecResult} from './jasmine/Spec';
import {SuiteResult} from './jasmine/Suite';
Expand All @@ -14,12 +15,12 @@ import {Reporter, RunDetails} from './types';
type Microseconds = number;

export default class Jasmine2Reporter implements Reporter {
private _testResults: Array<TestResult.AssertionResult>;
private _testResults: Array<AssertionResult>;
private _globalConfig: Config.GlobalConfig;
private _config: Config.ProjectConfig;
private _currentSuites: Array<string>;
private _resolve: any;
private _resultsPromise: Promise<TestResult.TestResult>;
private _resultsPromise: Promise<TestResult>;
private _startTimes: Map<string, Microseconds>;
private _testPath: Config.Path;

Expand Down Expand Up @@ -107,7 +108,7 @@ export default class Jasmine2Reporter implements Reporter {
this._resolve(testResult);
}

getResults(): Promise<TestResult.TestResult> {
getResults(): Promise<TestResult> {
return this._resultsPromise;
}

Expand All @@ -129,7 +130,7 @@ export default class Jasmine2Reporter implements Reporter {
private _extractSpecResults(
specResult: SpecResult,
ancestorTitles: Array<string>,
): TestResult.AssertionResult {
): AssertionResult {
const start = this._startTimes.get(specResult.id);
const duration = start ? Date.now() - start : undefined;
const status =
Expand All @@ -140,7 +141,7 @@ export default class Jasmine2Reporter implements Reporter {
line: specResult.__callsite.getLineNumber(),
}
: null;
const results: TestResult.AssertionResult = {
const results: AssertionResult = {
ancestorTitles,
duration,
failureMessages: [],
Expand Down
1 change: 1 addition & 0 deletions packages/jest-jasmine2/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
{"path": "../jest-message-util"},
{"path": "../jest-runtime"},
{"path": "../jest-snapshot"},
{"path": "../jest-test-result"},
{"path": "../jest-types"},
{"path": "../jest-util"},
{"path": "../pretty-format"}
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-test-result/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export {
AggregatedResult,
AssertionLocation,
AssertionResult,
FailedAssertion,
Milliseconds,
SerializableError,
SnapshotSummary,
Status,
Expand Down