diff --git a/integration_tests/__tests__/__snapshots__/snapshot-serializers-test.js.snap b/integration_tests/__tests__/__snapshots__/snapshot-serializers-test.js.snap index 2a87b6477f19..4acc30034214 100644 --- a/integration_tests/__tests__/__snapshots__/snapshot-serializers-test.js.snap +++ b/integration_tests/__tests__/__snapshots__/snapshot-serializers-test.js.snap @@ -7,8 +7,8 @@ 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": "
", "snapshot serializers works with prepended plugins from expect method called once 1": " @@ -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", } `; diff --git a/integration_tests/__tests__/snapshot-serializers-test.js b/integration_tests/__tests__/snapshot-serializers-test.js index 69db584d7f1c..eea69cd2e89d 100644 --- a/integration_tests/__tests__/snapshot-serializers-test.js +++ b/integration_tests/__tests__/snapshot-serializers-test.js @@ -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); diff --git a/integration_tests/snapshot-serializers/package.json b/integration_tests/snapshot-serializers/package.json index 9f215865987a..658160fc0f8e 100644 --- a/integration_tests/snapshot-serializers/package.json +++ b/integration_tests/snapshot-serializers/package.json @@ -1,6 +1,9 @@ { "jest": { "testEnvironment": "node", + "transform": { + "^.+\\.js$": "/transformer.js" + }, "snapshotSerializers": [ "./plugins/foo", "/plugins/bar" diff --git a/integration_tests/snapshot-serializers/plugins/bar.js b/integration_tests/snapshot-serializers/plugins/bar.js index 0720054dbe67..67775fff8347 100644 --- a/integration_tests/snapshot-serializers/plugins/bar.js +++ b/integration_tests/snapshot-serializers/plugins/bar.js @@ -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" diff --git a/integration_tests/snapshot-serializers/transformer.js b/integration_tests/snapshot-serializers/transformer.js new file mode 100644 index 000000000000..e6b4b83653dc --- /dev/null +++ b/integration_tests/snapshot-serializers/transformer.js @@ -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};\module.exports = createPlugin('bar');`; + } + return src; + }, +}; diff --git a/integration_tests/snapshot-serializers/utils.js b/integration_tests/snapshot-serializers/utils.js index 704fa21925f0..4b86c01f3e43 100644 --- a/integration_tests/snapshot-serializers/utils.js +++ b/integration_tests/snapshot-serializers/utils.js @@ -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), }; };