<commit_before>import webpack from 'webpack';
import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
import * as preset from './framework-preset-react';
import type { StorybookOptions } from './types';

const mockApply = jest.fn();
jest.mock('@pmmmwh/react-refresh-webpack-plugin', () => {
  return jest.fn().mockImplementation(() => {
    return { apply: mockApply };
  });
});

describe('framework-preset-react', () => {
  const reactRefreshPath = require.resolve('react-refresh/babel');
  const webpackConfigMock: webpack.Configuration = {
    plugins: [],
    module: {
      rules: [],
    },
  };
  const babelConfigMock = {};

  const storybookOptions: Partial<StorybookOptions> = {
    configType: 'DEVELOPMENT',
    presets: {
      apply: async () => ({
        fastRefresh: true,
      }),
    },
    presetsList: [],
  };

  const storybookOptionsDisabledRefresh: Partial<StorybookOptions> = {
    configType: 'DEVELOPMENT',
    presets: {
      apply: async () => ({
        fastRefresh: false,
      }),
    },
  };

  describe('babel', () => {
    it('should return a config with fast refresh plugin when fast refresh is enabled', async () => {
      const config = await preset.babel(babelConfigMock, storybookOptions as StorybookOptions);

      expect(config.plugins).toEqual([reactRefreshPath]);
    });

    it('should return unchanged config without fast refresh plugin when fast refresh is disabled', async () => {
      const config = await preset.babel(
        babelConfigMock,
        storybookOptionsDisabledRefresh as StorybookOptions<commit_msg>fix: unit tests for react preset<commit_after>import webpack from 'webpack';
import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
import * as preset from './framework-preset-react';
import type { StorybookOptions } from './types';

const mockApply = jest.fn();
jest.mock('@pmmmwh/react-refresh-webpack-plugin', () => {
  return jest.fn().mockImplementation(() => {
    return { apply: mockApply };
  });
});

describe('framework-preset-react', () => {
  const reactRefreshPath = require.resolve('react-refresh/babel');
  const webpackConfigMock: webpack.Configuration = {
    plugins: [],
    module: {
      rules: [],
    },
  };
  const babelConfigMock = {};

  const storybookOptions: Partial<StorybookOptions> = {
    configType: 'DEVELOPMENT',
    presets: {
      apply: async () => ({
        fastRefresh: true,
      }),
    },
    presetsList: [],
  };

  const storybookOptionsDisabledRefresh: Partial<StorybookOptions> = {
    configType: 'DEVELOPMENT',
    presets: {
      apply: async () => ({
        fastRefresh: false,
      }),
    },
  };

  describe('babel', () => {
    it('should return a config with fast refresh plugin when fast refresh is enabled', async () => {
      const config = await preset.babel(babelConfigMock, storybookOptions as StorybookOptions);

      expect(config.plugins).toEqual([[reactRefreshPath, {}, 'storybook-react-refresh']]);
    });

    it('should return unchanged config without fast refresh plugin when fast refresh is disabled', async () => {
      const config = await preset.babel(
        babelConfigMock,
        storybookOptionsDisabledRefresh as StorybookOptions
{'fraction_non_alphanumeric': 0.1377079482439926, 'fraction_numerical': 0.0, 'mean_word_length': 3.522284122562674, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5445418', 'n_tokens_mistral': 935, 'n_tokens_neox': 900, 'n_words': 215}