Skip to content

Commit

Permalink
Remove jest-snapshot from jest-jasmine2 and jest-runtime
Browse files Browse the repository at this point in the history
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
  • Loading branch information
andersk committed Feb 11, 2020
1 parent 5dcc480 commit 861ec97
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 84 deletions.
1 change: 0 additions & 1 deletion packages/jest-jasmine2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"jest-matcher-utils": "^25.1.0",
"jest-message-util": "^25.1.0",
"jest-runtime": "^25.1.0",
"jest-snapshot": "^25.1.0",
"jest-util": "^25.1.0",
"pretty-format": "^25.1.0",
"throat": "^5.0.0"
Expand Down
39 changes: 3 additions & 36 deletions packages/jest-jasmine2/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@

import * as path from 'path';
import {Config, Global} from '@jest/types';
import {AssertionResult, TestResult} from '@jest/test-result';
import {TestResult} from '@jest/test-result';
import {JestEnvironment} from '@jest/environment';
import {SnapshotStateType} from 'jest-snapshot';
import Runtime = require('jest-runtime');

import {getCallsite} from '@jest/source-map';
Expand Down Expand Up @@ -140,7 +139,7 @@ async function jasmine2(
});
}

const snapshotState: SnapshotStateType = runtime
runtime
.requireInternalModule(path.resolve(__dirname, './setup_jest_globals.js'))
.default({
config,
Expand Down Expand Up @@ -170,40 +169,8 @@ async function jasmine2(

const results = await reporter.getResults();

return addSnapshotData(results, snapshotState);
}

const addSnapshotData = (
results: TestResult,
snapshotState: SnapshotStateType,
) => {
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();

if (uncheckedCount) {
snapshotState.removeUncheckedKeys();
}

const status = snapshotState.save();
results.snapshot.fileDeleted = status.deleted;
results.snapshot.added = snapshotState.added;
results.snapshot.matched = snapshotState.matched;
results.snapshot.unmatched = snapshotState.unmatched;
results.snapshot.updated = snapshotState.updated;
results.snapshot.unchecked = !status.deleted ? uncheckedCount : 0;
// Copy the array to prevent memory leaks
results.snapshot.uncheckedKeys = Array.from(uncheckedKeys);

return results;
};
}

// eslint-disable-next-line no-redeclare
namespace jasmine2 {
Expand Down
14 changes: 0 additions & 14 deletions packages/jest-jasmine2/src/jestExpect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@

import expect = require('expect');
import {Global} from '@jest/types';
import {
addSerializer,
toMatchInlineSnapshot,
toMatchSnapshot,
toThrowErrorMatchingInlineSnapshot,
toThrowErrorMatchingSnapshot,
} from 'jest-snapshot';
import {Jasmine, RawMatcherFn} from './types';

declare const global: Global.Global;
Expand All @@ -29,13 +22,6 @@ type JasmineMatchersObject = {[id: string]: JasmineMatcher};
export default (config: {expand: boolean}) => {
global.expect = expect;
expect.setState({expand: config.expand});
expect.extend({
toMatchInlineSnapshot,
toMatchSnapshot,
toThrowErrorMatchingInlineSnapshot,
toThrowErrorMatchingSnapshot,
});
expect.addSnapshotSerializer = addSerializer;

const jasmine = global.jasmine as Jasmine;
jasmine.anything = expect.anything;
Expand Down
31 changes: 1 addition & 30 deletions packages/jest-jasmine2/src/setup_jest_globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
import {Config, Global} from '@jest/types';
import {Plugin} from 'pretty-format';
import {extractExpectedAssertionsErrors, getState, setState} from 'expect';
import {
SnapshotState,
addSerializer,
buildSnapshotResolver,
} from 'jest-snapshot';
import JasmineSpec, {Attributes, SpecResult} from './jasmine/Spec';
import {Jasmine} from './types';

Expand Down Expand Up @@ -85,32 +80,8 @@ const patchJasmine = () => {
};

export default ({
config,
globalConfig,
localRequire,
testPath,
}: SetupOptions) => {
// Jest tests snapshotSerializers in order preceding built-in serializers.
// Therefore, add in reverse because the last added is the first tested.
config.snapshotSerializers
.concat()
.reverse()
.forEach(path => {
addSerializer(localRequire(path));
});

patchJasmine();
const {expand, updateSnapshot} = globalConfig;
const snapshotResolver = buildSnapshotResolver(config);
const snapshotPath = snapshotResolver.resolveSnapshotPath(testPath);
const snapshotState = new SnapshotState(snapshotPath, {
expand,
getBabelTraverse: () => require('@babel/traverse').default,
getPrettier: () =>
config.prettierPath ? require(config.prettierPath) : null,
updateSnapshot,
});
setState({snapshotState, testPath});
// Return it back to the outer scope (test runner outside the VM).
return snapshotState;
setState({testPath});
};
1 change: 0 additions & 1 deletion packages/jest-jasmine2/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
{"path": "../jest-matcher-utils"},
{"path": "../jest-message-util"},
{"path": "../jest-runtime"},
{"path": "../jest-snapshot"},
{"path": "../jest-source-map"},
{"path": "../jest-test-result"},
{"path": "../jest-types"},
Expand Down
3 changes: 1 addition & 2 deletions packages/jest-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {formatStackTrace, separateMessageFromStack} from 'jest-message-util';
import Resolver = require('jest-resolve');
import {createDirectory, deepCyclicCopy} from 'jest-util';
import {escapePathForRegex} from 'jest-regex-util';
import Snapshot = require('jest-snapshot');
import {
ScriptTransformer,
ShouldInstrumentOptions,
Expand Down Expand Up @@ -244,7 +243,7 @@ class Runtime {
computeSha1: config.haste.computeSha1,
console: options && options.console,
dependencyExtractor: config.dependencyExtractor,
extensions: [Snapshot.EXTENSION].concat(config.moduleFileExtensions),
extensions: config.moduleFileExtensions,
hasteImplModulePath: config.haste.hasteImplModulePath,
ignorePattern,
maxWorkers: (options && options.maxWorkers) || 1,
Expand Down

0 comments on commit 861ec97

Please sign in to comment.