aboutsummaryrefslogtreecommitdiff
path: root/node_modules/jest-snapshot
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/jest-snapshot')
-rw-r--r--node_modules/jest-snapshot/.npmignore3
-rw-r--r--node_modules/jest-snapshot/build/State.js176
-rw-r--r--node_modules/jest-snapshot/build/index.js161
-rw-r--r--node_modules/jest-snapshot/build/plugins.js22
-rw-r--r--node_modules/jest-snapshot/build/utils.js188
-rw-r--r--node_modules/jest-snapshot/package.json19
6 files changed, 0 insertions, 569 deletions
diff --git a/node_modules/jest-snapshot/.npmignore b/node_modules/jest-snapshot/.npmignore
deleted file mode 100644
index 85e48fe7b..000000000
--- a/node_modules/jest-snapshot/.npmignore
+++ /dev/null
@@ -1,3 +0,0 @@
-**/__mocks__/**
-**/__tests__/**
-src
diff --git a/node_modules/jest-snapshot/build/State.js b/node_modules/jest-snapshot/build/State.js
deleted file mode 100644
index 156bb283d..000000000
--- a/node_modules/jest-snapshot/build/State.js
+++ /dev/null
@@ -1,176 +0,0 @@
-/**
- * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- *
- */
-
-'use strict';var _require =
-
-
-
-
-
-
-
-
-
-
-
-require('./utils');const saveSnapshotFile = _require.saveSnapshotFile,getSnapshotData = _require.getSnapshotData,getSnapshotPath = _require.getSnapshotPath,keyToTestName = _require.keyToTestName,serialize = _require.serialize,testNameToKey = _require.testNameToKey,unescape = _require.unescape;
-const fileExists = require('jest-file-exists');
-const fs = require('fs');
-
-class SnapshotState {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- constructor(
- testPath,
- update,
- snapshotPath,
- expand)
- {
- this._snapshotPath = snapshotPath || getSnapshotPath(testPath);var _getSnapshotData =
- getSnapshotData(this._snapshotPath, update);const data = _getSnapshotData.data,dirty = _getSnapshotData.dirty;
- this._snapshotData = data;
- this._dirty = dirty;
- this._uncheckedKeys = new Set(Object.keys(this._snapshotData));
- this._counters = new Map();
- this._index = 0;
- this.expand = expand || false;
- this.added = 0;
- this.matched = 0;
- this.unmatched = 0;
- this.update = update;
- this.updated = 0;
- this.skippedTests = new Set();
- this.failedTests = new Set();
- }
-
- markSnapshotsAsCheckedForTest(testName) {
- this._uncheckedKeys.forEach(uncheckedKey => {
- if (keyToTestName(uncheckedKey) === testName) {
- this._uncheckedKeys.delete(uncheckedKey);
- }
- });
- }
-
- _addSnapshot(key, receivedSerialized) {
- this._dirty = true;
- this._snapshotData[key] = receivedSerialized;
- }
-
- save(update) {
- const status = {
- deleted: false,
- saved: false };
-
-
- const isEmpty = Object.keys(this._snapshotData).length === 0;
-
- if ((this._dirty || this._uncheckedKeys.size) && !isEmpty) {
- saveSnapshotFile(this._snapshotData, this._snapshotPath);
- status.saved = true;
- } else if (isEmpty && fileExists(this._snapshotPath)) {
- if (update) {
- fs.unlinkSync(this._snapshotPath);
- }
- status.deleted = true;
- }
-
- return status;
- }
-
- getUncheckedCount() {
- return this._uncheckedKeys.size || 0;
- }
-
- removeUncheckedKeys() {
- if (this._uncheckedKeys.size) {
- this._dirty = true;
- this._uncheckedKeys.forEach(key => delete this._snapshotData[key]);
- this._uncheckedKeys.clear();
- }
- }
-
- match(testName, received, key) {
- this._counters.set(testName, (this._counters.get(testName) || 0) + 1);
- const count = Number(this._counters.get(testName));
-
- if (!key) {
- key = testNameToKey(testName, count);
- }
-
- this._uncheckedKeys.delete(key);
-
- const receivedSerialized = serialize(received);
- const expected = this._snapshotData[key];
- const pass = expected === receivedSerialized;
- const hasSnapshot = this._snapshotData[key] !== undefined;
-
- if (pass) {
- // Executing a snapshot file as JavaScript and writing the strings back
- // when other snapshots have changed loses the proper escaping for some
- // characters. Since we check every snapshot in every test, use the newly
- // generated formatted string.
- // Note that this is only relevant when a snapshot is added and the dirty
- // flag is set.
- this._snapshotData[key] = receivedSerialized;
- }
-
- if (
- !fileExists(this._snapshotPath) || // there's no snapshot file
- hasSnapshot && this.update || // there is a file, but we're updating
- !hasSnapshot // there is a file, but it doesn't have this snaphsot
- ) {
- if (this.update) {
- if (!pass) {
- if (hasSnapshot) {
- this.updated++;
- } else {
- this.added++;
- }
- this._addSnapshot(key, receivedSerialized);
- } else {
- this.matched++;
- }
- } else {
- this._addSnapshot(key, receivedSerialized);
- this.added++;
- }
-
- return { pass: true };
- } else {
- if (!pass) {
- this.unmatched++;
- return {
- actual: unescape(receivedSerialized),
- count,
- expected: unescape(expected),
- pass: false };
-
- } else {
- this.matched++;
- return { pass: true };
- }
- }
- }}
-
-
-module.exports = SnapshotState; \ No newline at end of file
diff --git a/node_modules/jest-snapshot/build/index.js b/node_modules/jest-snapshot/build/index.js
deleted file mode 100644
index 866f8b698..000000000
--- a/node_modules/jest-snapshot/build/index.js
+++ /dev/null
@@ -1,161 +0,0 @@
-/**
- * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- *
- */
-'use strict';
-
-
-
-
-const diff = require('jest-diff');
-const fileExists = require('jest-file-exists');
-const fs = require('fs');
-const path = require('path');
-const SnapshotState = require('./State');var _require =
-require('./plugins');const addSerializer = _require.addSerializer,getSerializers = _require.getSerializers;var _require2 =
-
-
-
-
-
-
-require('jest-matcher-utils');const EXPECTED_COLOR = _require2.EXPECTED_COLOR,ensureNoExpected = _require2.ensureNoExpected,matcherHint = _require2.matcherHint,RECEIVED_COLOR = _require2.RECEIVED_COLOR;var _require3 =
-require('./utils');const SNAPSHOT_EXTENSION = _require3.SNAPSHOT_EXTENSION;
-
-const cleanup = (hasteFS, update) => {
- const pattern = '\\.' + SNAPSHOT_EXTENSION + '$';
- const files = hasteFS.matchFiles(pattern);
- const filesRemoved = files.
- filter(snapshotFile => !fileExists(
- path.resolve(
- path.dirname(snapshotFile),
- '..',
- path.basename(snapshotFile, '.' + SNAPSHOT_EXTENSION)),
-
- hasteFS)).
-
- map(snapshotFile => {
- if (update) {
- fs.unlinkSync(snapshotFile);
- }
- }).
- length;
-
- return {
- filesRemoved };
-
-};
-
-const initializeSnapshotState = (
-testFile,
-update,
-testPath,
-expand) =>
-new SnapshotState(testFile, update, testPath, expand);
-
-const toMatchSnapshot = function (received, testName) {
- this.dontThrow && this.dontThrow();const
-
- currentTestName = this.currentTestName,isNot = this.isNot,snapshotState = this.snapshotState;
-
- if (isNot) {
- throw new Error(
- 'Jest: `.not` cannot be used with `.toMatchSnapshot()`.');
-
- }
-
- if (!snapshotState) {
- throw new Error('Jest: snapshot state must be initialized.');
- }
-
- const result = snapshotState.match(testName || currentTestName, received);const
- pass = result.pass;
-
- if (pass) {
- return { message: '', pass: true };
- } else {const
- count = result.count,expected = result.expected,actual = result.actual;
-
- const expectedString = expected.trim();
- const actualString = actual.trim();
- const diffMessage = diff(
- expectedString,
- actualString,
- {
- aAnnotation: 'Snapshot',
- bAnnotation: 'Received',
- expand: snapshotState.expand });
-
-
-
- const report =
- () => `${RECEIVED_COLOR('Received value')} does not match ` +
- `${EXPECTED_COLOR('stored snapshot ' + count)}.\n\n` + (
- diffMessage ||
- RECEIVED_COLOR('- ' + expectedString) + '\n' +
- EXPECTED_COLOR('+ ' + actualString));
-
-
- const message =
- () => matcherHint('.toMatchSnapshot', 'value', '') + '\n\n' +
- report();
-
- // Passing the the actual and expected objects so that a custom reporter
- // could access them, for example in order to display a custom visual diff,
- // or create a different error message
- return {
- actual: actualString,
- expected: expectedString,
- message,
- name: 'toMatchSnapshot',
- pass: false,
- report };
-
- }
-};
-
-const toThrowErrorMatchingSnapshot = function (received, expected) {
- this.dontThrow && this.dontThrow();const
- isNot = this.isNot;
-
- if (isNot) {
- throw new Error(
- 'Jest: `.not` cannot be used with `.toThrowErrorMatchingSnapshot()`.');
-
- }
-
- ensureNoExpected(expected, '.toThrowErrorMatchingSnapshot');
-
- let error;
-
- try {
- received();
- } catch (e) {
- error = e;
- }
-
- if (error === undefined) {
- throw new Error(
- matcherHint('.toThrowErrorMatchingSnapshot', '() => {}', '') + '\n\n' +
- `Expected the function to throw an error.\n` +
- `But it didn't throw anything.`);
-
- }
-
- return toMatchSnapshot.call(this, error.message);
-};
-
-module.exports = {
- EXTENSION: SNAPSHOT_EXTENSION,
- SnapshotState,
- addSerializer,
- cleanup,
- getSerializers,
- initializeSnapshotState,
- toMatchSnapshot,
- toThrowErrorMatchingSnapshot }; \ No newline at end of file
diff --git a/node_modules/jest-snapshot/build/plugins.js b/node_modules/jest-snapshot/build/plugins.js
deleted file mode 100644
index 620ee099a..000000000
--- a/node_modules/jest-snapshot/build/plugins.js
+++ /dev/null
@@ -1,22 +0,0 @@
-/**
- * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- *
- */
-'use strict';
-
-const ReactElementPlugin = require('pretty-format/build/plugins/ReactElement');
-const ReactTestComponentPlugin = require('pretty-format/build/plugins/ReactTestComponent');
-
-let PLUGINS = [ReactElementPlugin, ReactTestComponentPlugin];
-
-// Prepend to list so the last added is the first tested.
-exports.addSerializer = plugin => {
- PLUGINS = [plugin].concat(PLUGINS);
-};
-
-exports.getSerializers = () => PLUGINS; \ No newline at end of file
diff --git a/node_modules/jest-snapshot/build/utils.js b/node_modules/jest-snapshot/build/utils.js
deleted file mode 100644
index 9c86e4fb4..000000000
--- a/node_modules/jest-snapshot/build/utils.js
+++ /dev/null
@@ -1,188 +0,0 @@
-/**
- * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- *
- */
-
-'use strict';
-
-
-
-const chalk = require('chalk');
-const createDirectory = require('jest-util').createDirectory;
-const fileExists = require('jest-file-exists');
-const path = require('path');
-const prettyFormat = require('pretty-format');
-const fs = require('fs');
-const naturalCompare = require('natural-compare');
-const getSerializers = require('./plugins').getSerializers;
-
-const SNAPSHOT_EXTENSION = 'snap';
-const SNAPSHOT_VERSION = '1';
-const SNAPSHOT_VERSION_REGEXP = /^\/\/ Jest Snapshot v(.+),/;
-const SNAPSHOT_GUIDE_LINK = 'https://goo.gl/fbAQLP';
-const SNAPSHOT_VERSION_WARNING = chalk.yellow(
-`${chalk.bold('Warning')}: Before you upgrade snapshots, ` +
-`we recommend that you revert any local changes to tests or other code, ` +
-`to ensure that you do not store invalid state.`);
-
-
-const writeSnapshotVersion = () =>
-`// Jest Snapshot v${SNAPSHOT_VERSION}, ${SNAPSHOT_GUIDE_LINK}`;
-
-const validateSnapshotVersion = snapshotContents => {
- const versionTest = SNAPSHOT_VERSION_REGEXP.exec(snapshotContents);
- const version = versionTest && versionTest[1];
-
- if (!version) {
- return new Error(
- chalk.red(
- `${chalk.bold('Outdated snapshot')}: No snapshot header found. ` +
- `Jest 19 introduced versioned snapshots to ensure all developers on ` +
- `a project are using the same version of Jest. ` +
- `Please update all snapshots during this upgrade of Jest.\n\n`) +
-
- SNAPSHOT_VERSION_WARNING);
-
- }
-
- if (version < SNAPSHOT_VERSION) {
- return new Error(
- chalk.red(
- `${chalk.red.bold('Outdated snapshot')}: The version of the snapshot ` +
- `file associated with this test is outdated. The snapshot file ` +
- `version ensures that all developers on a project are using ` +
- `the same version of Jest. ` +
- `Please update all snapshots during this upgrade of Jest.\n\n`) +
-
- `Expected: v${SNAPSHOT_VERSION}\n` +
- `Received: v${version}\n\n` +
- SNAPSHOT_VERSION_WARNING);
-
- }
-
- if (version > SNAPSHOT_VERSION) {
- return new Error(
- chalk.red(
- `${chalk.red.bold('Outdated Jest version')}: The version of this ` +
- `snapshot file indicates that this project is meant to be used ` +
- `with a newer version of Jest. ` +
- `The snapshot file version ensures that all developers on a project ` +
- `are using the same version of Jest. ` +
- `Please update your version of Jest and re-run the tests.\n\n`) +
-
- `Expected: v${SNAPSHOT_VERSION}\n` +
- `Received: v${version}`);
-
- }
-
- return null;
-};
-
-const testNameToKey = (testName, count) =>
-testName + ' ' + count;
-
-const keyToTestName = key => {
- if (!/ \d+$/.test(key)) {
- throw new Error('Snapshot keys must end with a number.');
- }
-
- return key.replace(/ \d+$/, '');
-};
-
-const getSnapshotPath = testPath => path.join(
-path.join(path.dirname(testPath), '__snapshots__'),
-path.basename(testPath) + '.' + SNAPSHOT_EXTENSION);
-
-
-const getSnapshotData = (snapshotPath, update) => {
- const data = Object.create(null);
- let snapshotContents = '';
- let dirty = false;
-
- if (fileExists(snapshotPath)) {
- try {
- snapshotContents = fs.readFileSync(snapshotPath, 'utf8');
- // eslint-disable-next-line no-new-func
- const populate = new Function('exports', snapshotContents);
- populate(data);
- } catch (e) {}
- }
-
- const validationResult = validateSnapshotVersion(snapshotContents);
- const isInvalid = snapshotContents && validationResult;
-
- if (!update && isInvalid) {
- throw validationResult;
- }
-
- if (update && isInvalid) {
- dirty = true;
- }
-
- return { data, dirty };
-};
-
-// Extra line breaks at the beginning and at the end of the snapshot are useful
-// to make the content of the snapshot easier to read
-const addExtraLineBreaks =
-string => string.includes('\n') ? `\n${string}\n` : string;
-
-const serialize = data => {
- return addExtraLineBreaks(prettyFormat(data, {
- escapeRegex: true,
- plugins: getSerializers(),
- printFunctionName: false }));
-
-};
-
-const unescape = data =>
-data.replace(/\\(")/g, '$1'); // unescape double quotes
-
-const printBacktickString = str => {
- return '`' + str.replace(/`|\\|\${/g, '\\$&') + '`';
-};
-
-const ensureDirectoryExists = filePath => {
- try {
- createDirectory(path.join(path.dirname(filePath)));
- } catch (e) {}
-};
-
-const normalizeNewlines =
-string => string.replace(/\r\n|\r/g, '\n');
-
-const saveSnapshotFile = (
-snapshotData,
-snapshotPath) =>
-{
- const snapshots = Object.keys(snapshotData).sort(naturalCompare).
- map(key =>
- 'exports[' + printBacktickString(key) + '] = ' +
- printBacktickString(normalizeNewlines(snapshotData[key])) + ';');
-
-
- ensureDirectoryExists(snapshotPath);
- fs.writeFileSync(
- snapshotPath,
- writeSnapshotVersion() + '\n\n' + snapshots.join('\n\n') + '\n');
-
-};
-
-module.exports = {
- SNAPSHOT_EXTENSION,
- SNAPSHOT_GUIDE_LINK,
- SNAPSHOT_VERSION,
- SNAPSHOT_VERSION_WARNING,
- ensureDirectoryExists,
- getSnapshotData,
- getSnapshotPath,
- keyToTestName,
- saveSnapshotFile,
- serialize,
- testNameToKey,
- unescape }; \ No newline at end of file
diff --git a/node_modules/jest-snapshot/package.json b/node_modules/jest-snapshot/package.json
deleted file mode 100644
index 0c271a1d1..000000000
--- a/node_modules/jest-snapshot/package.json
+++ /dev/null
@@ -1,19 +0,0 @@
-{
- "name": "jest-snapshot",
- "version": "19.0.2",
- "repository": {
- "type": "git",
- "url": "https://github.com/facebook/jest.git"
- },
- "license": "BSD-3-Clause",
- "main": "build/index.js",
- "dependencies": {
- "chalk": "^1.1.3",
- "jest-diff": "^19.0.0",
- "jest-file-exists": "^19.0.0",
- "jest-matcher-utils": "^19.0.0",
- "jest-util": "^19.0.2",
- "natural-compare": "^1.4.0",
- "pretty-format": "^19.0.0"
- }
-}