Skip to content

Commit

Permalink
fix(storybook): when migrating to 12.1 do not throw if project has no…
Browse files Browse the repository at this point in the history
… targets

ISSUES CLOSED: nrwl#6128
  • Loading branch information
mandarini committed Jul 23, 2021
1 parent 1655f4b commit 23d267d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 36 deletions.
Expand Up @@ -5,50 +5,79 @@ import updateStorybookTsconfig from './fix-storybook-tsconfig';
describe('Fix Storybook TSConfig to avoid VSCode error', () => {
let tree: Tree;

beforeEach(async () => {
tree = createTreeWithEmptyWorkspace();

writeJson(tree, 'workspace.json', {
projects: {
['home-ui-react']: {
projectType: 'library',
root: 'libs/home/ui-react',
sourceRoot: 'libs/home/ui-react/src',
targets: {
storybook: {
builder: '@nrwl/storybook:storybook',
options: {
uiFramework: '@storybook/react',
port: 4400,
config: {
configFolder: 'libs/home/ui-react/.storybook',
describe('when project has valid configuration and targets', () => {
beforeEach(async () => {
tree = createTreeWithEmptyWorkspace();

writeJson(tree, 'workspace.json', {
projects: {
['home-ui-react']: {
projectType: 'library',
root: 'libs/home/ui-react',
sourceRoot: 'libs/home/ui-react/src',
targets: {
storybook: {
builder: '@nrwl/storybook:storybook',
options: {
uiFramework: '@storybook/react',
port: 4400,
config: {
configFolder: 'libs/home/ui-react/.storybook',
},
},
},
},
},
},
},
});

writeJson(tree, 'libs/home/ui-react/.storybook/tsconfig.json', {
extends: '../tsconfig.json',
compilerOptions: {
emitDecoratorMetadata: true,
},
});
});

writeJson(tree, 'libs/home/ui-react/.storybook/tsconfig.json', {
extends: '../tsconfig.json',
compilerOptions: {
emitDecoratorMetadata: true,
},
it(`should add outDir to the storybook tsconfig to avoid VSCode errors`, async () => {
await updateStorybookTsconfig(tree);

expect(
readJson(tree, 'libs/home/ui-react/.storybook/tsconfig.json')
).toMatchObject({
extends: '../tsconfig.json',
compilerOptions: {
emitDecoratorMetadata: true,
outDir: '',
},
});
});
});

it(`should add outDir to the storybook tsconfig to avoid VSCode errors`, async () => {
await updateStorybookTsconfig(tree);

expect(
readJson(tree, 'libs/home/ui-react/.storybook/tsconfig.json')
).toMatchObject({
extends: '../tsconfig.json',
compilerOptions: {
emitDecoratorMetadata: true,
outDir: '',
},
describe('when project has no targets', () => {
beforeEach(async () => {
tree = createTreeWithEmptyWorkspace();

writeJson(tree, 'workspace.json', {
projects: {
['home-ui-react']: {
projectType: 'library',
root: 'libs/home/ui-react',
sourceRoot: 'libs/home/ui-react/src',
},
},
});

writeJson(tree, 'libs/home/ui-react/.storybook/tsconfig.json', {
extends: '../tsconfig.json',
compilerOptions: {
emitDecoratorMetadata: true,
},
});
});

it(`should not throw errors`, async () => {
await expect(updateStorybookTsconfig(tree)).resolves.not.toThrow();
});
});
});
Expand Up @@ -23,7 +23,7 @@ export default async function updateStorybookTsconfig(tree: Tree) {
),
};

const storybookExecutor = Object.keys(targets).find(
const storybookExecutor = Object.keys(targets || {}).find(
(x) => targets[x].executor === '@nrwl/storybook:storybook'
);

Expand All @@ -38,7 +38,7 @@ export default async function updateStorybookTsconfig(tree: Tree) {
}

const isReactProject = isFramework('react', {
uiFramework: targets[storybookExecutor].options
uiFramework: targets[storybookExecutor]?.options
?.uiFramework as Parameters<typeof isFramework>[1]['uiFramework'],
});

Expand Down

0 comments on commit 23d267d

Please sign in to comment.