-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21409 from storybookjs/valentin/angular-codemod
Add Angular Builder Codemods
- Loading branch information
Showing
12 changed files
with
637 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
code/lib/cli/src/automigrate/fixes/__snapshots__/angular-builders.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`is not Nx project angular builders Angular < 14.0.0 should throw an Error 1`] = ` | ||
"❌ Your project uses Angular < 14.0.0. Storybook 7.0 for Angular requires Angular 14.0.0 or higher. | ||
Please upgrade your Angular version to at least version 14.0.0 to use Storybook 7.0 in your project." | ||
`; |
132 changes: 132 additions & 0 deletions
132
code/lib/cli/src/automigrate/fixes/angular-builders-multiproject.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import type { StorybookConfig } from '@storybook/types'; | ||
import type { PackageJson } from '../../js-package-manager'; | ||
import { makePackageManager, mockStorybookData } from '../helpers/testing-helpers'; | ||
import { angularBuildersMultiproject } from './angular-builders-multiproject'; | ||
import * as helpers from '../../helpers'; | ||
import * as angularHelpers from '../../generators/ANGULAR/helpers'; | ||
|
||
const checkAngularBuilders = async ({ | ||
packageJson, | ||
main: mainConfig = {}, | ||
storybookVersion = '7.0.0', | ||
}: { | ||
packageJson: PackageJson; | ||
main?: Partial<StorybookConfig> & Record<string, unknown>; | ||
storybookVersion?: string; | ||
}) => { | ||
mockStorybookData({ mainConfig, storybookVersion }); | ||
|
||
// mock file system (look at eslint plugin test) | ||
|
||
return angularBuildersMultiproject.check({ | ||
packageManager: makePackageManager(packageJson), | ||
}); | ||
}; | ||
|
||
jest.mock('../../helpers', () => ({ | ||
...jest.requireActual('../../helpers'), | ||
isNxProject: jest.fn(), | ||
})); | ||
|
||
jest.mock('../../generators/ANGULAR/helpers', () => ({ | ||
...jest.requireActual('../../generators/ANGULAR/helpers'), | ||
AngularJSON: jest.fn(), | ||
})); | ||
|
||
describe('is Nx project', () => { | ||
beforeEach(() => { | ||
(helpers.isNxProject as any as jest.SpyInstance).mockReturnValue(true); | ||
}); | ||
|
||
it('should return null', async () => { | ||
const packageJson = { | ||
dependencies: { '@storybook/angular': '^7.0.0-alpha.0' }, | ||
}; | ||
|
||
await expect(checkAngularBuilders({ packageJson })).resolves.toBeNull(); | ||
}); | ||
}); | ||
|
||
describe('is not Nx project', () => { | ||
beforeEach(() => { | ||
(helpers.isNxProject as any as jest.SpyInstance).mockReturnValue(false); | ||
}); | ||
|
||
describe('angular builders', () => { | ||
afterEach(jest.restoreAllMocks); | ||
|
||
describe('Angular not found', () => { | ||
const packageJson = { | ||
dependencies: { '@storybook/angular': '^7.0.0-alpha.0' }, | ||
}; | ||
|
||
it('should return null', async () => { | ||
await expect(checkAngularBuilders({ packageJson })).resolves.toBeNull(); | ||
}); | ||
}); | ||
|
||
describe('Angular < 14.0.0', () => { | ||
const packageJson = { | ||
dependencies: { '@storybook/angular': '^7.0.0-alpha.0', '@angular/core': '^12.0.0' }, | ||
}; | ||
|
||
it('should return null', async () => { | ||
await expect(checkAngularBuilders({ packageJson })).resolves.toBeNull(); | ||
}); | ||
}); | ||
|
||
describe('Angular >= 14.0.0', () => { | ||
const packageJson = { | ||
dependencies: { '@storybook/angular': '^7.0.0-alpha.0', '@angular/core': '^15.0.0' }, | ||
}; | ||
|
||
describe('has one Storybook builder defined', () => { | ||
beforeEach(() => { | ||
// Mock AngularJSON.constructor | ||
(angularHelpers.AngularJSON as jest.Mock).mockImplementation(() => ({ | ||
hasStorybookBuilder: true, | ||
})); | ||
}); | ||
|
||
it('should return null', async () => { | ||
await expect(checkAngularBuilders({ packageJson })).resolves.toBeNull(); | ||
}); | ||
}); | ||
|
||
describe('has one project', () => { | ||
beforeEach(() => { | ||
// Mock AngularJSON.constructor | ||
(angularHelpers.AngularJSON as jest.Mock).mockImplementation(() => ({ | ||
hasStorybookBuilder: false, | ||
projects: { | ||
project1: { root: 'project1', architect: {} }, | ||
}, | ||
rootProject: 'project1', | ||
})); | ||
}); | ||
|
||
it('should return null', async () => { | ||
await expect(checkAngularBuilders({ packageJson })).resolves.toBeNull(); | ||
}); | ||
}); | ||
|
||
describe('has multiple projects without root project defined', () => { | ||
beforeEach(() => { | ||
// Mock AngularJSON.constructor | ||
(angularHelpers.AngularJSON as jest.Mock).mockImplementation(() => ({ | ||
hasStorybookBuilder: false, | ||
projects: { | ||
project1: { root: 'project1', architect: {} }, | ||
project2: { root: 'project2', architect: {} }, | ||
}, | ||
rootProject: null, | ||
})); | ||
}); | ||
|
||
it('should return an empty object', async () => { | ||
await expect(checkAngularBuilders({ packageJson })).resolves.toMatchObject({}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.