Skip to content

Commit

Permalink
fix(storybook): fix 6.1.0 migration to prevent wiping out root eslintrc
Browse files Browse the repository at this point in the history
closed #17748
  • Loading branch information
rathpc committed Jun 23, 2023
1 parent e9dc24c commit 916fb69
Showing 1 changed file with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,37 @@ describe('Ignore @nx/react/plugins/storybook in Storybook eslint plugin', () =>
);

if (!tree.exists('.eslintrc.json')) {
tree.write('.eslintrc.json', '{}');
tree.write('.eslintrc.json', `{}`);
}
updateJson(tree, '.eslintrc.json', (json) => {
json.extends ??= [];
json.extends.push('plugin:storybook/recommended');
return json;
});
});

it('should not ignore the plugin if it is not used', async () => {
await eslintIgnoreReactPlugin(tree);
const eslintConfig = readJson(tree, '.eslintrc.json');
expect(eslintConfig).toEqual({});
expect(eslintConfig.rules).toBeUndefined();
});

it('should not ignore the plugin if "plugin:storybook/recommended" is not included', async () => {
tree.write('apps/main-webpack/tsconfig.json', `{}`);
tree.write(
`apps/main-webpack/.storybook/main.js`,
`
module.exports = {
stories: ['../src/lib/**/*.stories.@(mdx|js|jsx|ts|tsx)'],
addons: ['@storybook/addon-essentials', '@nx/react/plugins/storybook'],
framework: {
name: '@storybook/react-webpack5',
options: {},
},
};
`
);

await eslintIgnoreReactPlugin(tree);

const eslintConfig = readJson(tree, '.eslintrc.json');
expect(eslintConfig).toEqual({});
expect(eslintConfig.rules).toBeUndefined();
});

Expand All @@ -71,6 +90,12 @@ describe('Ignore @nx/react/plugins/storybook in Storybook eslint plugin', () =>
`
);

updateJson(tree, '.eslintrc.json', (json) => {
json.extends ??= [];
json.extends.push('plugin:storybook/recommended');
return json;
});

await eslintIgnoreReactPlugin(tree);

const eslintConfig = readJson(tree, '.eslintrc.json');
Expand Down

0 comments on commit 916fb69

Please sign in to comment.