Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix snapshot serializer require, restructure pretty-format. #3399

Merged
merged 2 commits into from
Apr 28, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add a test.
  • Loading branch information
cpojer committed Apr 28, 2017
commit 21622c3aefde448f7ba29530465f02bb9462b349
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ Object {
id=\\"foo\\"
/>
",
"snapshot serializers works with first plugin 1": "foo: 1",
"snapshot serializers works with nested serializable objects 1": "foo: bar: 2",
"snapshot serializers works with first plugin 1": "foo - 1",
"snapshot serializers works with nested serializable objects 1": "foo - bar - 2",
"snapshot serializers works with prepended plugins and default serializers 1": "
<div
aProp={
Object {
\\"a\\": 6,
}
}
bProp={foo: 8}
bProp={foo - 8}
/>
",
"snapshot serializers works with prepended plugins from expect method called once 1": "
Expand All @@ -39,6 +39,6 @@ Object {
bProp={FOO: 8}
/>
",
"snapshot serializers works with second plugin 1": "bar: 2",
"snapshot serializers works with second plugin 1": "bar - 2",
}
`;
2 changes: 1 addition & 1 deletion integration_tests/__tests__/snapshot-serializers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const snapshotsDir = path.resolve(testDir, '__tests__/__snapshots__');
const snapshotPath = path.resolve(snapshotsDir, 'snapshot-test.js.snap');

const runAndAssert = () => {
const result = runJest.json('snapshot-serializers');
const result = runJest.json('snapshot-serializers', ['--no-cache']);
const json = result.json;
expect(json.numTotalTests).toBe(7);
expect(json.numPassedTests).toBe(7);
Expand Down
3 changes: 3 additions & 0 deletions integration_tests/snapshot-serializers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"jest": {
"testEnvironment": "node",
"transform": {
"^.+\\.js$": "<rootDir>/transformer.js"
},
"snapshotSerializers": [
"./plugins/foo",
"<rootDir>/plugins/bar"
Expand Down
5 changes: 4 additions & 1 deletion integration_tests/snapshot-serializers/plugins/bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
*/
'use strict';

/* eslint-disable no-unused-vars */

const createPlugin = require('../utils').createPlugin;
module.exports = createPlugin('bar');

// We inject the call to "createPlugin('bar') through the transformer"
18 changes: 18 additions & 0 deletions integration_tests/snapshot-serializers/transformer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* 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';

module.exports = {
process(src, filename, config, options) {
if (/bar.js$/.test(filename)) {
return `${src};\nmodule.exports = createPlugin('bar');`;
}
return src;
},
};
2 changes: 1 addition & 1 deletion integration_tests/snapshot-serializers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

exports.createPlugin = prop => {
return {
print: (val, serialize) => `${prop}: ${serialize(val[prop])}`,
print: (val, serialize) => `${prop} - ${serialize(val[prop])}`,
test: val => val && val.hasOwnProperty(prop),
};
};