nx/packages/angular/src/migrations/update-12-3-0/update-storybook.spec.ts
Leosvel Pérez Espinosa 678818a58b
feat(angular): upgrade Angular to v12.0.0-rc.3 (#5630)
* feat(angular): upgrade Angular to v12.0.0-rc.3

* feat(angular): target Nx v12.4.0-beta.0 for Angular v12.0.0-rc.0 upgrade

* fix(angular): use defaultConfiguration if no other configuration is passed

* cleanup(angular): sync migration folder name to target version

* fix(repo): creating custom schema flattener for docs

* chore(repo): amend yarn.lock

* feat(angular): update angular storybook to use webpack 5

* fix(angular): add legacy peer deps for angular+jest

* fix(angular): move migrations to 12.3.0-rc.0

Co-authored-by: Zack DeRose <zack.derose@gmail.com>
Co-authored-by: Jason Jean <jasonjean1993@gmail.com>
2021-05-12 12:20:12 -04:00

133 lines
3.6 KiB
TypeScript

import { addProjectConfiguration, readJson, Tree } from '@nrwl/devkit';
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
import update from './update-storybook';
describe('12.4.0 - Update Storybook', () => {
let tree: Tree;
beforeEach(() => {
tree = createTreeWithEmptyWorkspace();
jest.mock('@storybook/core/package.json', () => ({
version: '6.2.0',
}));
});
afterEach(() => {
jest.resetAllMocks();
});
it('should update storybook config', async () => {
addProjectConfiguration(tree, 'proj', {
projectType: 'library',
root: 'proj',
targets: {
storybook: {
executor: '@nrwl/storybook:storybook',
options: {
uiFramework: '@storybook/angular',
config: {
configFolder: 'proj/.storybook',
},
},
},
},
});
tree.write('proj/.storybook/main.js', 'module.exports = {};');
jest.requireMock('@storybook/core/package.json').version = '6.2.0';
jest.mock('/virtual/proj/.storybook/main.js', () => ({}), {
virtual: true,
});
await update(tree);
expect(tree.read('proj/.storybook/main.js').toString())
.toMatchInlineSnapshot(`
"module.exports = {};
module.exports.core = { ...module.exports.core, builder: 'webpack5' };"
`);
expect(
readJson(tree, 'package.json').devDependencies[
'@storybook/builder-webpack5'
]
).toEqual('6.2.0');
// Should not do it again if run again
jest.requireMock('/virtual/proj/.storybook/main.js').core = {
builder: 'webpack5',
};
await update(tree);
expect(tree.read('proj/.storybook/main.js').toString())
.toMatchInlineSnapshot(`
"module.exports = {};
module.exports.core = { ...module.exports.core, builder: 'webpack5' };"
`);
});
it('should error if storybook 5 is installed', async () => {
addProjectConfiguration(tree, 'proj', {
projectType: 'library',
root: 'proj',
targets: {
storybook: {
executor: '@nrwl/storybook:storybook',
options: {
uiFramework: '@storybook/angular',
config: {
configFolder: 'proj/.storybook',
},
},
},
},
});
tree.write('proj/.storybook/main.js', 'module.exports = {};');
jest.requireMock('@storybook/core/package.json').version = '5.2.0';
jest.mock('/virtual/proj/.storybook/main.js', () => ({}), {
virtual: true,
});
try {
await update(tree);
fail('Should fail');
} catch (e) {
expect(e.message).toMatchInlineSnapshot(
`"Could not migrate to Angular 12"`
);
}
});
it('should not update projects that are not angular', async () => {
addProjectConfiguration(tree, 'proj', {
projectType: 'library',
root: 'proj',
targets: {
storybook: {
executor: '@nrwl/storybook:storybook',
options: {
uiFramework: '@storybook/react',
config: {
configFolder: 'proj/.storybook',
},
},
},
},
});
tree.write('proj/.storybook/main.js', 'module.exports = {};');
jest.requireMock('@storybook/core/package.json').version = '6.2.0';
jest.mock('/virtual/proj/.storybook/main.js', () => ({}), {
virtual: true,
});
await update(tree);
expect(
tree.read('proj/.storybook/main.js').toString()
).toMatchInlineSnapshot(`"module.exports = {};"`);
expect(
readJson(tree, 'package.json').devDependencies[
'@storybook/builder-webpack5'
]
).not.toBeDefined();
});
});