chore: extract jest snapshot serializers (#5034)

master
Ika 2018-09-01 12:11:19 +08:00 committed by GitHub
parent 2e8366a84e
commit 55e620bdc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 50 deletions

View File

@ -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(

View File

@ -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",

View File

@ -1,13 +0,0 @@
"use strict";
const hasAnsi = require("has-ansi");
const stripAnsi = require("strip-ansi");
module.exports = {
print(value, serialize) {
return serialize(stripAnsi(value));
},
test(value) {
return typeof value === "string" && hasAnsi(value);
}
};

View File

@ -1,16 +0,0 @@
"use strict";
const RAW = Symbol.for("raw");
module.exports = {
print(val) {
return val[RAW];
},
test(val) {
return (
val &&
Object.prototype.hasOwnProperty.call(val, RAW) &&
typeof val[RAW] === "string"
);
}
};

View File

@ -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"];
@ -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(
{

View File

@ -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"
@ -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"