From 81f376310611860c115178654775623e2416cf91 Mon Sep 17 00:00:00 2001 From: Yuta Hiroto Date: Tue, 27 Feb 2018 00:14:19 +0900 Subject: [PATCH] Add test for Option Parsing --- .../__snapshots__/upgradeConfig.test.js.snap | 18 ++++++++++++++++++ __tests__/upgradeConfig.test.js | 5 +++++ fixtures/option-parsing.json | 9 +++++++++ 3 files changed, 32 insertions(+) create mode 100644 fixtures/option-parsing.json diff --git a/__tests__/__snapshots__/upgradeConfig.test.js.snap b/__tests__/__snapshots__/upgradeConfig.test.js.snap index cbb9778..de2121a 100644 --- a/__tests__/__snapshots__/upgradeConfig.test.js.snap +++ b/__tests__/__snapshots__/upgradeConfig.test.js.snap @@ -1,5 +1,23 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`convert comma separated presets/plugins into an array 1`] = ` +Object { + "env": Object { + "development": Object { + "plugins": Array [ + "babel-plugin-istanbul, transform-react-jsx-source, babel-plugin-transform-react-inline-elements", + ], + }, + }, + "plugins": Array [ + "babel-plugin-transform-function-bind, transform-class-properties", + ], + "presets": Array [ + "@babel/preset-env, @babel/preset-react", + ], +} +`; + exports[`package that is removed 1`] = ` Object { "plugins": Array [ diff --git a/__tests__/upgradeConfig.test.js b/__tests__/upgradeConfig.test.js index eeef46e..5213e25 100644 --- a/__tests__/upgradeConfig.test.js +++ b/__tests__/upgradeConfig.test.js @@ -1,6 +1,7 @@ const path = require('path'); const upgradeConfig = require('../src/upgradeConfig'); const babelrcFixture = require('../fixtures/babelrc'); +const optionParsingFixture = require('../fixtures/option-parsing'); const { readBabelRC } = require('../src'); const JSON5_PATH = path.resolve(__dirname, '../fixtures/babelrc.json5'); @@ -38,3 +39,7 @@ test('packages (json5)', async () => { const json5Data = await readBabelRC(JSON5_PATH); expect(upgradeConfig(json5Data)).toMatchSnapshot(); }); + +test('convert comma separated presets/plugins into an array', () => { + expect(upgradeConfig(optionParsingFixture)).toMatchSnapshot(); +}); diff --git a/fixtures/option-parsing.json b/fixtures/option-parsing.json new file mode 100644 index 0000000..b212cda --- /dev/null +++ b/fixtures/option-parsing.json @@ -0,0 +1,9 @@ +{ + "presets": "@babel/preset-env, @babel/preset-react", + "plugins": "babel-plugin-transform-function-bind, transform-class-properties", + "env": { + "development": { + "plugins": "babel-plugin-istanbul, transform-react-jsx-source, babel-plugin-transform-react-inline-elements" + } + } +}