fix(storybook): fix broken migration test (#5951)
This commit is contained in:
parent
eff495e606
commit
c64d9dfb2f
@ -1,6 +1,6 @@
|
||||
# storybook-migrate-stories-to-6-2
|
||||
|
||||
Migrate stories to match the new syntax in v6.2 where the component declaration should be in the default export
|
||||
Migrate stories to match the new syntax in v6.2 where the component declaration should be in the default export.
|
||||
|
||||
## Usage
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
# storybook-migrate-stories-to-6-2
|
||||
|
||||
Migrate stories to match the new syntax in v6.2 where the component declaration should be in the default export
|
||||
Migrate stories to match the new syntax in v6.2 where the component declaration should be in the default export.
|
||||
|
||||
## Usage
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
# storybook-migrate-stories-to-6-2
|
||||
|
||||
Migrate stories to match the new syntax in v6.2 where the component declaration should be in the default export
|
||||
Migrate stories to match the new syntax in v6.2 where the component declaration should be in the default export.
|
||||
|
||||
## Usage
|
||||
|
||||
|
||||
@ -69,9 +69,9 @@
|
||||
},
|
||||
|
||||
"storybook-migrate-stories-to-6-2": {
|
||||
"factory": "./src/schematics/storybook-migrate-stories-to-6-2/migrate-stories-to-6-2",
|
||||
"schema": "./src/schematics/storybook-migrate-stories-to-6-2/schema.json",
|
||||
"description": "Migrate stories to match the new syntax in v6.2 where the component declaration should be in the default export",
|
||||
"factory": "./src/generators/storybook-migrate-stories-to-6-2/compat",
|
||||
"schema": "./src/generators/storybook-migrate-stories-to-6-2/schema.json",
|
||||
"description": "Migrate stories to match the new syntax in v6.2 where the component declaration should be in the default export.",
|
||||
"hidden": false
|
||||
},
|
||||
|
||||
@ -161,6 +161,12 @@
|
||||
"schema": "./src/generators/storybook-migrate-defaults-5-to-6/schema.json",
|
||||
"description": "Generate default Storybook configuration files using Storybook version >=6.x specs, for projects that already have Storybook instances and configurations of versions <6.x.",
|
||||
"hidden": false
|
||||
},
|
||||
"storybook-migrate-stories-to-6-2": {
|
||||
"factory": "./src/generators/storybook-migrate-stories-to-6-2/migrate-stories-to-6-2",
|
||||
"schema": "./src/generators/storybook-migrate-stories-to-6-2/schema.json",
|
||||
"description": "Migrate stories to match the new syntax in v6.2 where the component declaration should be in the default export.",
|
||||
"hidden": false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/schema",
|
||||
"$id": "NxStorybookMigrateDefaults5To6Generator",
|
||||
"cli": "nx",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"all": {
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
import { convertNxGenerator } from '@nrwl/devkit';
|
||||
import { angularMigrateStoriesTo62Generator } from './migrate-stories-to-6-2';
|
||||
|
||||
export default convertNxGenerator(angularMigrateStoriesTo62Generator);
|
||||
@ -1,19 +1,21 @@
|
||||
import { Tree, writeJson } from '@nrwl/devkit';
|
||||
import type { Tree } from '@nrwl/devkit';
|
||||
import { joinPathFragments, writeJson } from '@nrwl/devkit';
|
||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
import { wrapAngularDevkitSchematic } from '@nrwl/tao/src/commands/ngcli-adapter';
|
||||
import { SyntaxKind } from 'typescript';
|
||||
import ts = require('typescript');
|
||||
import { nxVersion, storybookVersion } from '../../utils/versions';
|
||||
import migrateStoriesTo62Generator, {
|
||||
getTsSourceFile,
|
||||
} from './migrate-stories-to-6-2';
|
||||
import { Linter } from '@nrwl/linter';
|
||||
import { storybookVersion } from '@nrwl/storybook';
|
||||
import {
|
||||
overrideCollectionResolutionForTesting,
|
||||
wrapAngularDevkitSchematic,
|
||||
} from '@nrwl/tao/src/commands/ngcli-adapter';
|
||||
import { findNodes } from '@nrwl/workspace/src/utils/ast-utils';
|
||||
import * as ts from 'typescript';
|
||||
import { SyntaxKind } from 'typescript';
|
||||
import { getTsSourceFile } from '../../utils/nx-devkit/ast-utils';
|
||||
import { nxVersion } from '../../utils/versions';
|
||||
import { storybookConfigurationGenerator } from '../storybook-configuration/storybook-configuration';
|
||||
import { angularMigrateStoriesTo62Generator } from './migrate-stories-to-6-2';
|
||||
|
||||
const libSchematic = wrapAngularDevkitSchematic('@nrwl/angular', 'lib');
|
||||
const storybookConfigSchematic = wrapAngularDevkitSchematic(
|
||||
'@nrwl/angular',
|
||||
'storybook-configuration'
|
||||
);
|
||||
const componentSchematic = wrapAngularDevkitSchematic(
|
||||
'@schematics/angular',
|
||||
'component'
|
||||
@ -24,6 +26,13 @@ describe('migrate-stories-to-6-2 schematic', () => {
|
||||
|
||||
describe('angular project', () => {
|
||||
beforeEach(async () => {
|
||||
overrideCollectionResolutionForTesting({
|
||||
'@nrwl/storybook': joinPathFragments(
|
||||
__dirname,
|
||||
'../../../../storybook/collection.json'
|
||||
),
|
||||
});
|
||||
|
||||
appTree = createTreeWithEmptyWorkspace();
|
||||
|
||||
await libSchematic(appTree, {
|
||||
@ -43,8 +52,12 @@ describe('migrate-stories-to-6-2 schematic', () => {
|
||||
},
|
||||
});
|
||||
|
||||
await storybookConfigSchematic(appTree, {
|
||||
await storybookConfigurationGenerator(appTree, {
|
||||
name: 'test-ui-lib',
|
||||
configureCypress: true,
|
||||
generateCypressSpecs: true,
|
||||
generateStories: true,
|
||||
linter: Linter.EsLint,
|
||||
});
|
||||
|
||||
appTree.write(
|
||||
@ -82,7 +95,7 @@ describe('migrate-stories-to-6-2 schematic', () => {
|
||||
});
|
||||
|
||||
it('should move the component from the story to parameters.component', async () => {
|
||||
await migrateStoriesTo62Generator(appTree);
|
||||
await angularMigrateStoriesTo62Generator(appTree);
|
||||
const storyFilePath =
|
||||
'libs/test-ui-lib/src/lib/test-button/test-button.component.stories.ts';
|
||||
const file = getTsSourceFile(appTree, storyFilePath);
|
||||
@ -0,0 +1,18 @@
|
||||
import type { Tree } from '@nrwl/devkit';
|
||||
import type { migrateStoriesTo62Generator } from '@nrwl/storybook';
|
||||
|
||||
export async function angularMigrateStoriesTo62Generator(tree: Tree) {
|
||||
let storybookMigrateStoriesTo62Generator: typeof migrateStoriesTo62Generator;
|
||||
try {
|
||||
storybookMigrateStoriesTo62Generator = require('@nrwl/storybook')
|
||||
.migrateStoriesTo62Generator;
|
||||
} catch {
|
||||
throw new Error(
|
||||
`You don't have @nrwl/storybook installed. Please, install it before running this generator.`
|
||||
);
|
||||
}
|
||||
|
||||
await storybookMigrateStoriesTo62Generator(tree);
|
||||
}
|
||||
|
||||
export default angularMigrateStoriesTo62Generator;
|
||||
@ -1,7 +1,9 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/schema",
|
||||
"id": "storybook-migrate-stories-to-6-2",
|
||||
"id": "NxAngularStorybookMigrateStoriesTo62Generator",
|
||||
"type": "object",
|
||||
"cli": "nx",
|
||||
"properties": {},
|
||||
"additionalProperties": false,
|
||||
"required": []
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
import { chain, externalSchematic, Rule } from '@angular-devkit/schematics';
|
||||
import { wrapAngularDevkitSchematic } from '@nrwl/devkit/ngcli-adapter';
|
||||
|
||||
export default function (): Rule {
|
||||
return chain([
|
||||
externalSchematic('@nrwl/storybook', 'migrate-stories-to-6-2', {}),
|
||||
]);
|
||||
}
|
||||
|
||||
export const storybookMigration5to6Generator = wrapAngularDevkitSchematic(
|
||||
'@nrwl/angular',
|
||||
'storybook-migrate-stories-to-6-2'
|
||||
);
|
||||
@ -1,5 +0,0 @@
|
||||
export interface StorybookMigrateDefault5to6Schema {
|
||||
name?: string;
|
||||
all?: boolean;
|
||||
keepOld?: boolean;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user