Skip to content

Commit

Permalink
Merge branch 'main' into error-case-show-sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
jughosta authored Dec 7, 2022
2 parents d20f697 + f179279 commit 2405b5f
Show file tree
Hide file tree
Showing 47 changed files with 1,040 additions and 572 deletions.
48 changes: 47 additions & 1 deletion packages/kbn-storybook/src/lib/default_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
*/

import * as path from 'path';
import fs from 'fs';
import type { StorybookConfig } from '@storybook/core-common';
import { Configuration } from 'webpack';
import webpack, { Configuration } from 'webpack';
import webpackMerge from 'webpack-merge';
import { REPO_ROOT } from './constants';
import { default as WebpackConfig } from '../webpack.config';

const MOCKS_DIRECTORY = '__storybook_mocks__';
const EXTENSIONS = ['.ts', '.js'];

export type { StorybookConfig };

const toPath = (_path: string) => path.join(REPO_ROOT, _path);
Expand Down Expand Up @@ -52,6 +56,48 @@ export const defaultConfig: StorybookConfig = {
config.cache = true;
}

// This will go over every component which is imported and check its import statements.
// For every import which starts with ./ it will do a check to see if a file with the same name
// exists in the __storybook_mocks__ folder. If it does, use that import instead.
// This allows you to mock hooks and functions when rendering components in Storybook.
// It is akin to Jest's manual mocks (__mocks__).
config.plugins?.push(
new webpack.NormalModuleReplacementPlugin(/^\.\//, async (resource: any) => {
if (!resource.contextInfo.issuer?.includes('node_modules')) {
const mockedPath = path.resolve(resource.context, MOCKS_DIRECTORY, resource.request);

EXTENSIONS.forEach((ext) => {
const isReplacementPathExists = fs.existsSync(mockedPath + ext);

if (isReplacementPathExists) {
const newImportPath = './' + path.join(MOCKS_DIRECTORY, resource.request);
resource.request = newImportPath;
}
});
}
})
);

// Same, but for imports statements which import modules outside of the directory (../)
config.plugins?.push(
new webpack.NormalModuleReplacementPlugin(/^\.\.\//, async (resource: any) => {
if (!resource.contextInfo.issuer?.includes('node_modules')) {
const prs = path.parse(resource.request);

const mockedPath = path.resolve(resource.context, prs.dir, MOCKS_DIRECTORY, prs.base);

EXTENSIONS.forEach((ext) => {
const isReplacementPathExists = fs.existsSync(mockedPath + ext);

if (isReplacementPathExists) {
const newImportPath = prs.dir + '/' + path.join(MOCKS_DIRECTORY, prs.base);
resource.request = newImportPath;
}
});
}
})
);

config.node = { fs: 'empty' };
config.watch = true;
config.watchOptions = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ beforeEach(() => {

describe('bulkDeleteRulesRoute', () => {
const bulkDeleteRequest = { filter: '' };
const bulkDeleteResult = { errors: [], total: 1, taskIdsFailedToBeDeleted: [] };
const bulkDeleteResult = { rules: [], errors: [], total: 1, taskIdsFailedToBeDeleted: [] };

it('should delete rules with proper parameters', async () => {
const licenseState = licenseStateMock.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
export { mapSortField } from './map_sort_field';
export { validateOperationOnAttributes } from './validate_attributes';
export { retryIfBulkEditConflicts } from './retry_if_bulk_edit_conflicts';
export { retryIfBulkDeleteConflicts } from './retry_if_bulk_delete_conflicts';
export { retryIfBulkDisableConflicts } from './retry_if_bulk_disable_conflicts';
export { retryIfBulkOperationConflicts } from './retry_if_bulk_operation_conflicts';
export { applyBulkEditOperation } from './apply_bulk_edit_operation';
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 2405b5f

Please sign in to comment.