Make Flow Parser snapshots more readable

Summary:
The Flow Parser's snapshots, which are serializations of the CodegenSchema object, are extremely difficult to read. In this diff, I explicitly serialized the schema objects using Node's `util.inspect`.

**Benefits:**
- The snapshots are more readable now.
- You can copy-paste the objects from the snapshot files directly into the Chrome console, or into other JavaScript files. This is a very useful feature, when we're testing the generators, or other infra that depends on the codegen.

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D24063112

fbshipit-source-id: 2c6ec3424aac8bab2688dc6ae286b73f90e4bef1
This commit is contained in:
Ramanpreet Nara
2020-10-01 19:30:07 -07:00
committed by Facebook GitHub Bot
parent 5a1ca38305
commit 0a2e0f777b
4 changed files with 8049 additions and 8999 deletions
@@ -14,6 +14,7 @@
const FlowParser = require('../../index.js');
const fixtures = require('../__test_fixtures__/fixtures.js');
const failureFixtures = require('../__test_fixtures__/failures.js');
const util = require('util');
jest.mock('fs', () => ({
readFileSync: filename => fixtures[filename] || failureFixtures[filename],
}));
@@ -23,7 +24,12 @@ describe('RN Codegen Flow Parser', () => {
.sort()
.forEach(fixtureName => {
it(`can generate fixture ${fixtureName}`, () => {
expect(FlowParser.parseFile(fixtureName)).toMatchSnapshot();
const schema = FlowParser.parseFile(fixtureName);
const serializedSchema = util.inspect(schema, {
showHidden: false,
depth: null,
});
expect(serializedSchema).toMatchSnapshot();
});
});
@@ -14,6 +14,7 @@
const FlowParser = require('../../index.js');
const fixtures = require('../__test_fixtures__/fixtures.js');
const failureFixtures = require('../__test_fixtures__/failures.js');
const util = require('util');
jest.mock('fs', () => ({
readFileSync: filename => fixtures[filename] || failureFixtures[filename],
}));
@@ -23,7 +24,13 @@ describe('RN Codegen Flow Parser', () => {
.sort()
.forEach(fixtureName => {
it(`can generate fixture ${fixtureName}`, () => {
expect(FlowParser.parseModuleFixture(fixtureName)).toMatchSnapshot();
const schema = FlowParser.parseModuleFixture(fixtureName);
const serializedSchema = util.inspect(schema, {
showHidden: false,
depth: null,
});
expect(serializedSchema).toMatchSnapshot();
});
});