From 0d9f689dd691ed0e18cec6ce1891ce7de0df9915 Mon Sep 17 00:00:00 2001 From: cpojer Date: Fri, 28 Apr 2017 02:10:25 +0100 Subject: [PATCH] Add a test. --- .../snapshot-serializers/package.json | 3 +++ .../snapshot-serializers/plugins/bar.js | 5 ++++- .../snapshot-serializers/transformer.js | 18 ++++++++++++++++++ .../snapshot-serializers/utils.js | 2 +- 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 integration_tests/snapshot-serializers/transformer.js 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..5c8df2e4f935 --- /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 (/plugins\/bar/.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), }; };