jest-serializer-simple 5.0.0-0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # jest-serializer-simple
2
+
3
+ ## 5.0.0-0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#125](https://github.com/benjie/postgraphile-private/pull/125)
8
+ [`91f2256b3`](https://github.com/benjie/postgraphile-private/commit/91f2256b3fd699bec19fc86f1ca79df057e58639)
9
+ Thanks [@benjie](https://github.com/benjie)! - Initial changesets release
package/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # jest-serializer-simple
2
+
3
+ [![GitHub Sponsors](https://img.shields.io/github/sponsors/benjie?color=ff69b4&label=github%20sponsors)](https://github.com/sponsors/benjie)
4
+ [![Patreon sponsor button](https://img.shields.io/badge/sponsor-via%20Patreon-orange.svg)](https://patreon.com/benjie)
5
+ [![Discord chat room](https://img.shields.io/discord/489127045289476126.svg)](http://discord.gg/graphile)
6
+ [![Follow](https://img.shields.io/badge/twitter-@GraphileHQ-blue.svg)](https://twitter.com/GraphileHQ)
7
+
8
+ A Jest serializer to simplify your snapshots.
9
+
10
+ Sometimes you just want to print an object or a string without all the escapes
11
+ and `Object [null prototype] {` annotations. When you want that, this is a
12
+ simple solution for it.
13
+
14
+ <!-- SPONSORS_BEGIN -->
15
+
16
+ ## Crowd-funded open-source software
17
+
18
+ To help us develop this software sustainably under the MIT license, we ask all
19
+ individuals and businesses that use it to help support its ongoing maintenance
20
+ and development via sponsorship.
21
+
22
+ ### [Click here to find out more about sponsors and sponsorship.](https://www.graphile.org/sponsor/)
23
+
24
+ And please give some love to our featured sponsors 🤩:
25
+
26
+ <table><tr>
27
+ <td align="center"><a href="https://surge.io/"><img src="https://graphile.org/images/sponsors/surge.png" width="90" height="90" alt="Surge" /><br />Surge</a> *</td>
28
+ <td align="center"><a href="https://www.netflix.com/"><img src="https://graphile.org/images/sponsors/Netflix.png" width="90" height="90" alt="Netflix" /><br />Netflix</a> *</td>
29
+ <td align="center"><a href="https://qwick.com/"><img src="https://graphile.org/images/sponsors/qwick.png" width="90" height="90" alt="Qwick" /><br />Qwick</a> *</td>
30
+ <td align="center"><a href="https://www.the-guild.dev/"><img src="https://graphile.org/images/sponsors/theguild.png" width="90" height="90" alt="The Guild" /><br />The Guild</a> *</td>
31
+ </tr><tr>
32
+ <td align="center"><a href="http://chads.website"><img src="https://graphile.org/images/sponsors/chadf.png" width="90" height="90" alt="Chad Furman" /><br />Chad Furman</a> *</td>
33
+ <td align="center"><a href="https://www.fanatics.com/"><img src="https://graphile.org/images/sponsors/fanatics.png" width="90" height="90" alt="Fanatics" /><br />Fanatics</a> *</td>
34
+ <td align="center"><a href="https://dovetailapp.com/"><img src="https://graphile.org/images/sponsors/dovetail.png" width="90" height="90" alt="Dovetail" /><br />Dovetail</a> *</td>
35
+ <td align="center"><a href="https://www.enzuzo.com/"><img src="https://graphile.org/images/sponsors/enzuzo.png" width="90" height="90" alt="Enzuzo" /><br />Enzuzo</a> *</td>
36
+ </tr><tr>
37
+ <td align="center"><a href="https://stellate.co/"><img src="https://graphile.org/images/sponsors/Stellate.png" width="90" height="90" alt="Stellate" /><br />Stellate</a> *</td>
38
+ </tr></table>
39
+
40
+ <em>\* Sponsors the entire Graphile suite</em>
41
+
42
+ <!-- SPONSORS_END -->
43
+
44
+ ## Usage:
45
+
46
+ ```
47
+ yarn add jest-serializer-simple
48
+ ```
49
+
50
+ Then add it to your Jest config:
51
+
52
+ ```js
53
+ module.exports = {
54
+ testEnvironment: "node",
55
+ snapshotSerializers: [`jest-serializer-simple`],
56
+ //...
57
+ };
58
+ ```
59
+
60
+ To tell Jest that you want the object to be printed simply, you must wrap it in
61
+ an object with just the `__` key: `{ __: YOUR_VALUE_HERE }`, for example:
62
+
63
+ ```js
64
+ expect({ __: data }).toMatchInlineSnapshot(`
65
+ {
66
+ forums: [
67
+ {
68
+ name: 'Cats',
69
+ },
70
+ {
71
+ name: 'Dogs',
72
+ },
73
+ {
74
+ name: 'Postgres',
75
+ },
76
+ ],
77
+ }
78
+ `);
79
+ ```
@@ -0,0 +1,9 @@
1
+ import type { Plugin } from "pretty-format";
2
+ export interface FormattedObject {
3
+ __: string | JSON | null | undefined;
4
+ }
5
+ declare function printFormattedObject(val: FormattedObject): string;
6
+ export declare const test: Plugin["test"];
7
+ export declare const serialize: typeof printFormattedObject;
8
+ export {};
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAE5C,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,CAAC;CACtC;AAYD,iBAAS,oBAAoB,CAAC,GAAG,EAAE,eAAe,GAAG,MAAM,CAe1D;AAED,eAAO,MAAM,IAAI,EAAE,MAAM,CAAC,MAAM,CAAqB,CAAC;AACtD,eAAO,MAAM,SAAS,6BAAuB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.serialize = exports.test = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const json5_1 = tslib_1.__importDefault(require("json5"));
6
+ function isFormattedObject(val) {
7
+ return ((typeof val === "object" &&
8
+ val &&
9
+ Object.keys(val).length === 1 &&
10
+ "__" in val) ||
11
+ false);
12
+ }
13
+ function printFormattedObject(val) {
14
+ return typeof val.__ === "string"
15
+ ? String(val.__)
16
+ : typeof val.__ === "undefined"
17
+ ? "undefined"
18
+ : json5_1.default.stringify(val.__, {
19
+ space: 2,
20
+ quote: '"',
21
+ }).trim();
22
+ // prettier
23
+ // .format(JSON5.stringify(val.__), {
24
+ // printWidth: 120,
25
+ // parser: "json5",
26
+ // })
27
+ // .trim();
28
+ }
29
+ exports.test = isFormattedObject;
30
+ exports.serialize = printFormattedObject;
31
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,0DAA0B;AAQ1B,SAAS,iBAAiB,CAAC,GAAY;IACrC,OAAO,CACL,CAAC,OAAO,GAAG,KAAK,QAAQ;QACtB,GAAG;QACH,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,KAAK,CAAC;QAC7B,IAAI,IAAI,GAAG,CAAC;QACd,KAAK,CACN,CAAC;AACJ,CAAC;AAED,SAAS,oBAAoB,CAAC,GAAoB;IAChD,OAAO,OAAO,GAAG,CAAC,EAAE,KAAK,QAAQ;QAC/B,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;QAChB,CAAC,CAAC,OAAO,GAAG,CAAC,EAAE,KAAK,WAAW;YAC/B,CAAC,CAAC,WAAW;YACb,CAAC,CAAC,eAAK,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,EAAE;gBACtB,KAAK,EAAE,CAAC;gBACR,KAAK,EAAE,GAAG;aACX,CAAC,CAAC,IAAI,EAAE,CAAC;IACd,WAAW;IACX,yCAAyC;IACzC,yBAAyB;IACzB,yBAAyB;IACzB,SAAS;IACT,eAAe;AACjB,CAAC;AAEY,QAAA,IAAI,GAAmB,iBAAiB,CAAC;AACzC,QAAA,SAAS,GAAG,oBAAoB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "jest-serializer-simple",
3
+ "version": "5.0.0-0.1",
4
+ "description": "Jest serializer that gives really simple formatting",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "prepack": "tsc -b",
9
+ "watch": "tsc -b --watch"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/graphile/heart.git"
14
+ },
15
+ "keywords": [
16
+ "jest",
17
+ "graphql",
18
+ "schema",
19
+ "graphile",
20
+ "graphite"
21
+ ],
22
+ "author": "Benjie Gillam <code@benjiegillam.com>",
23
+ "license": "MIT",
24
+ "bugs": {
25
+ "url": "https://github.com/graphile/heart/issues"
26
+ },
27
+ "homepage": "https://github.com/graphile/heart/tree/main/utils/jest-serializer-simple",
28
+ "dependencies": {
29
+ "@types/json5": "^2.2.0",
30
+ "json5": "^2.2.0",
31
+ "prettier": "^2.5.1"
32
+ },
33
+ "devDependencies": {
34
+ "@types/jest": "^27.5.1",
35
+ "jest": "^28.1.0",
36
+ "pretty-format": "^27.4.2",
37
+ "ts-node": "^10.9.1",
38
+ "tslib": "^2.4.0",
39
+ "typescript": "^4.8.1-rc"
40
+ },
41
+ "files": [
42
+ "dist"
43
+ ]
44
+ }