Skip to content

Commit

Permalink
chore: extract jest snapshot serializers (#5034)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikatyang committed Sep 1, 2018
1 parent 2e8366a commit 55e620b
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 50 deletions.
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const isOldNode = semver.parse(process.version).major <= 4;
module.exports = {
setupFiles: ["<rootDir>/tests_config/run_spec.js"],
snapshotSerializers: [
"<rootDir>/tests_config/raw-serializer.js",
"<rootDir>/tests_config/ansi-serializer.js"
"jest-snapshot-serializer-raw",
"jest-snapshot-serializer-ansi"
],
testRegex: "jsfmt\\.spec\\.js$|__tests__/.*\\.js$",
testPathIgnorePatterns: ["tests/new_react", "tests/more_react"].concat(
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@
"eslint-plugin-prettier": "2.6.0",
"eslint-plugin-react": "7.7.0",
"execa": "0.10.0",
"has-ansi": "3.0.0",
"jest": "23.3.0",
"jest-junit": "5.0.0",
"jest-snapshot-serializer-ansi": "1.0.0",
"jest-snapshot-serializer-raw": "1.1.0",
"jest-watch-typeahead": "0.1.0",
"mkdirp": "0.5.1",
"prettier": "1.14.2",
Expand Down
13 changes: 0 additions & 13 deletions tests_config/ansi-serializer.js

This file was deleted.

16 changes: 0 additions & 16 deletions tests_config/raw-serializer.js

This file was deleted.

13 changes: 1 addition & 12 deletions tests_config/run_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const fs = require("fs");
const extname = require("path").extname;
const raw = require("jest-snapshot-serializer-raw").wrap;

const AST_COMPARE = process.env["AST_COMPARE"];
const TEST_STANDALONE = process.env["TEST_STANDALONE"];
Expand Down Expand Up @@ -130,18 +131,6 @@ function skipStandalone(parser) {
return new Set(["parse5"]).has(parser);
}

/**
* Wraps a string in a marker object that is used by `./raw-serializer.js` to
* directly print that string in a snapshot without escaping all double quotes.
* Backticks will still be escaped.
*/
function raw(string) {
if (typeof string !== "string") {
throw new Error("Raw snapshots have to be strings.");
}
return { [Symbol.for("raw")]: string };
}

function mergeDefaultOptions(parserConfig) {
return Object.assign(
{
Expand Down
23 changes: 17 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2603,18 +2603,18 @@ har-validator@~5.0.3:
ajv "^5.1.0"
har-schema "^2.0.0"

has-ansi@3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/has-ansi/-/has-ansi-3.0.0.tgz#36077ef1d15f333484aa7fa77a28606f1c655b37"
dependencies:
ansi-regex "^3.0.0"

has-ansi@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/has-ansi/-/has-ansi-2.0.0.tgz#34f5049ce1ecdf2b0649af3ef24e45ed35416d91"
dependencies:
ansi-regex "^2.0.0"

has-ansi@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/has-ansi/-/has-ansi-3.0.0.tgz#36077ef1d15f333484aa7fa77a28606f1c655b37"
dependencies:
ansi-regex "^3.0.0"

has-flag@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-1.0.0.tgz#9d9e793165ce017a00f00418c43f942a7b1d11fa"
Expand Down Expand Up @@ -3471,6 +3471,17 @@ jest-serializer@^23.0.1:
version "23.0.1"
resolved "https://registry.yarnpkg.com/jest-serializer/-/jest-serializer-23.0.1.tgz#a3776aeb311e90fe83fab9e533e85102bd164165"

jest-snapshot-serializer-ansi@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/jest-snapshot-serializer-ansi/-/jest-snapshot-serializer-ansi-1.0.0.tgz#7daeefe7bfa81aed44e153fd3451320b61dc2a67"
dependencies:
has-ansi "^3.0.0"
strip-ansi "^4.0.0"

jest-snapshot-serializer-raw@1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/jest-snapshot-serializer-raw/-/jest-snapshot-serializer-raw-1.1.0.tgz#1d7f09c02f3dbbc3ae70b5b7598fb2f45e37d6c8"

jest-snapshot@^23.0.1:
version "23.3.0"
resolved "https://registry.yarnpkg.com/jest-snapshot/-/jest-snapshot-23.3.0.tgz#fc4e9f81e45432d10507e27f50bce60f44d81424"
Expand Down

0 comments on commit 55e620b

Please sign in to comment.