mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-06 07:21:16 +08:00
CLEANUP && FIX unit test
This commit is contained in:
parent
8727989141
commit
6695d953a6
3
app/angular/src/client/manager/index.js
vendored
3
app/angular/src/client/manager/index.js
vendored
@ -1,5 +1,4 @@
|
||||
/* global document */
|
||||
|
||||
import { document } from 'global';
|
||||
import renderStorybookUI from '@storybook/ui';
|
||||
import Provider from './provider';
|
||||
|
||||
|
3
app/angular/src/client/manager/provider.js
vendored
3
app/angular/src/client/manager/provider.js
vendored
@ -1,5 +1,4 @@
|
||||
/* global location */
|
||||
|
||||
import { location } from 'global';
|
||||
import qs from 'qs';
|
||||
import React from 'react';
|
||||
import { Provider } from '@storybook/ui';
|
||||
|
3
app/angular/src/client/preview/client_api.js
vendored
3
app/angular/src/client/preview/client_api.js
vendored
@ -1,5 +1,4 @@
|
||||
/* eslint no-underscore-dangle: 0 */
|
||||
// import Vue from 'vue';
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
|
||||
export default class ClientApi {
|
||||
constructor({ channel, storyStore }) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* eslint no-underscore-dangle: 0 */
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
|
||||
import ClientAPI from './client_api';
|
||||
|
||||
@ -75,7 +75,10 @@ describe('preview.client_api', () => {
|
||||
},
|
||||
});
|
||||
|
||||
api.storiesOf('none').aa().bb();
|
||||
api
|
||||
.storiesOf('none')
|
||||
.aa()
|
||||
.bb();
|
||||
expect(data).toEqual(['foo', 'bar']);
|
||||
});
|
||||
|
||||
|
2
app/angular/src/client/preview/config_api.js
vendored
2
app/angular/src/client/preview/config_api.js
vendored
@ -1,4 +1,4 @@
|
||||
/* eslint no-underscore-dangle: 0 */
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
|
||||
import { location } from 'global';
|
||||
import { setInitialStory, setError, clearError } from './actions';
|
||||
|
3
app/angular/src/client/preview/index.js
vendored
3
app/angular/src/client/preview/index.js
vendored
@ -1,5 +1,4 @@
|
||||
/* global window */
|
||||
|
||||
import { window } from 'global';
|
||||
import { createStore } from 'redux';
|
||||
import addons from '@storybook/addons';
|
||||
import createChannel from '@storybook/channel-postmessage';
|
||||
|
8
app/angular/src/client/preview/render.js
vendored
8
app/angular/src/client/preview/render.js
vendored
@ -1,13 +1,5 @@
|
||||
// import { environment } from './environments/environment';
|
||||
|
||||
// import { ErrorComponent } from './error.component.ts';
|
||||
// import { document } from 'global';
|
||||
|
||||
import { renderNgApp, renderNgError, renderNoPreview } from './angular/helpers.ts';
|
||||
|
||||
// // check whether we're running on node/browser
|
||||
// const isBrowser = typeof window !== 'undefined';
|
||||
|
||||
const logger = console;
|
||||
let previousKind = '';
|
||||
let previousStory = '';
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* eslint no-underscore-dangle: 0 */
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
|
||||
let count = 0;
|
||||
|
||||
|
2
app/angular/src/server/addons.js
vendored
2
app/angular/src/server/addons.js
vendored
@ -1,2 +0,0 @@
|
||||
// import '@storybook/addon-actions/register';
|
||||
// import '@storybook/addon-links/register';
|
10
app/angular/src/server/babel_config.js
vendored
10
app/angular/src/server/babel_config.js
vendored
@ -68,17 +68,9 @@ export default function(configDir) {
|
||||
const finalConfig = babelConfig || defaultConfig;
|
||||
// Ensure plugins are defined or fallback to an array to avoid empty values.
|
||||
const babelConfigPlugins = finalConfig.plugins || [];
|
||||
const extraPlugins = [
|
||||
[
|
||||
require.resolve('babel-plugin-react-docgen'),
|
||||
{
|
||||
DOC_GEN_COLLECTION_NAME: 'STORYBOOK_REACT_CLASSES',
|
||||
},
|
||||
],
|
||||
];
|
||||
// If `babelConfigPlugins` is not an `Array`, calling `concat` will inject it
|
||||
// as a single value, if it is an `Array` it will be spreaded.
|
||||
finalConfig.plugins = [].concat(babelConfigPlugins, extraPlugins);
|
||||
finalConfig.plugins = [].concat(babelConfigPlugins);
|
||||
|
||||
return finalConfig;
|
||||
}
|
||||
|
@ -1,90 +1,89 @@
|
||||
import mock from 'mock-fs';
|
||||
import loadBabelConfig from './babel_config';
|
||||
|
||||
// eslint-disable-next-line global-require
|
||||
jest.mock('fs', () => require('../../../../__mocks__/fs'));
|
||||
jest.mock('path', () => ({
|
||||
resolve: () => '.babelrc',
|
||||
parse: require.requireActual('path').parse,
|
||||
join: require.requireActual('path').join,
|
||||
dirname: require.requireActual('path').dirname,
|
||||
}));
|
||||
|
||||
const setup = ({ files }) => {
|
||||
// eslint-disable-next-line no-underscore-dangle, global-require
|
||||
require('fs').__setMockFiles(files);
|
||||
};
|
||||
|
||||
describe('babel_config', () => {
|
||||
// As the 'fs' is going to be mocked, let's call require.resolve
|
||||
// so the require.cache has the correct route to the file.
|
||||
// In fact let's use it in the tests :)
|
||||
const babelPluginReactDocgenPath = require.resolve('babel-plugin-react-docgen');
|
||||
|
||||
it('should return the config with the extra plugins when `plugins` is an array.', () => {
|
||||
// Mock a simple `.babelrc` config file.
|
||||
mock({
|
||||
'.babelrc': `{
|
||||
setup({
|
||||
files: {
|
||||
'.babelrc': `{
|
||||
"presets": [
|
||||
"es2015",
|
||||
"env",
|
||||
"foo-preset"
|
||||
],
|
||||
"plugins": [
|
||||
"foo-plugin"
|
||||
]
|
||||
}`,
|
||||
},
|
||||
});
|
||||
|
||||
const config = loadBabelConfig('.foo');
|
||||
|
||||
expect(config.plugins).toEqual([
|
||||
'foo-plugin',
|
||||
[
|
||||
babelPluginReactDocgenPath,
|
||||
{
|
||||
DOC_GEN_COLLECTION_NAME: 'STORYBOOK_REACT_CLASSES',
|
||||
},
|
||||
],
|
||||
]);
|
||||
|
||||
mock.restore();
|
||||
expect(config).toEqual({
|
||||
babelrc: false,
|
||||
plugins: ['foo-plugin'],
|
||||
presets: ['env', 'foo-preset'],
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the config with the extra plugins when `plugins` is not an array.', () => {
|
||||
// Mock a `.babelrc` config file with plugins key not being an array.
|
||||
mock({
|
||||
'.babelrc': `{
|
||||
"presets": [
|
||||
"es2015",
|
||||
"foo-preset"
|
||||
],
|
||||
"plugins": "bar-plugin"
|
||||
}`,
|
||||
setup({
|
||||
files: {
|
||||
'.babelrc': `{
|
||||
"presets": [
|
||||
"env",
|
||||
"foo-preset"
|
||||
],
|
||||
"plugins": "bar-plugin"
|
||||
}`,
|
||||
},
|
||||
});
|
||||
|
||||
const config = loadBabelConfig('.bar');
|
||||
|
||||
expect(config.plugins).toEqual([
|
||||
'bar-plugin',
|
||||
[
|
||||
babelPluginReactDocgenPath,
|
||||
{
|
||||
DOC_GEN_COLLECTION_NAME: 'STORYBOOK_REACT_CLASSES',
|
||||
},
|
||||
],
|
||||
]);
|
||||
|
||||
mock.restore();
|
||||
expect(config).toEqual({
|
||||
babelrc: false,
|
||||
plugins: ['bar-plugin'],
|
||||
presets: ['env', 'foo-preset'],
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the config only with the extra plugins when `plugins` is not present.', () => {
|
||||
// Mock a `.babelrc` config file with no plugins key.
|
||||
mock({
|
||||
'.babelrc': `{
|
||||
"presets": [
|
||||
"es2015",
|
||||
"foo-preset"
|
||||
]
|
||||
}`,
|
||||
setup({
|
||||
files: {
|
||||
'.babelrc': `{
|
||||
"presets": [
|
||||
"env",
|
||||
"foo-preset"
|
||||
]
|
||||
}`,
|
||||
},
|
||||
});
|
||||
|
||||
const config = loadBabelConfig('.biz');
|
||||
|
||||
expect(config.plugins).toEqual([
|
||||
[
|
||||
babelPluginReactDocgenPath,
|
||||
{
|
||||
DOC_GEN_COLLECTION_NAME: 'STORYBOOK_REACT_CLASSES',
|
||||
},
|
||||
],
|
||||
]);
|
||||
|
||||
mock.restore();
|
||||
expect(config).toEqual({
|
||||
babelrc: false,
|
||||
plugins: [],
|
||||
presets: ['env', 'foo-preset'],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user