import { Tree } from '@angular-devkit/schematics'; import { NxJson, readJsonInTree } from '@nrwl/workspace'; import { createEmptyWorkspace } from '@nrwl/workspace/testing'; import { runSchematic } from '../../utils/testing'; describe('app', () => { let appTree: Tree; beforeEach(() => { appTree = Tree.empty(); appTree = createEmptyWorkspace(appTree); }); it('should update workspace.json', async () => { const tree = await runSchematic('app', { name: 'myApp' }, appTree); const workspaceJson = readJsonInTree(tree, '/workspace.json'); expect(workspaceJson.projects['my-app'].root).toEqual('apps/my-app'); expect(workspaceJson.projects['my-app-e2e'].root).toEqual( 'apps/my-app-e2e' ); expect(workspaceJson.defaultProject).toEqual('my-app'); }); it('should update nx.json', async () => { const tree = await runSchematic( 'app', { name: 'myApp', tags: 'one,two' }, appTree ); const nxJson = readJsonInTree(tree, '/nx.json'); expect(nxJson.projects).toEqual({ 'my-app': { tags: ['one', 'two'], }, 'my-app-e2e': { tags: [], implicitDependencies: ['my-app'], }, }); }); it('should generate files', async () => { const tree = await runSchematic('app', { name: 'myApp' }, appTree); expect(tree.exists('apps/my-app/tsconfig.json')).toBeTruthy(); expect(tree.exists('apps/my-app/tsconfig.app.json')).toBeTruthy(); expect(tree.exists('apps/my-app/src/pages/index.tsx')).toBeTruthy(); expect(tree.exists('apps/my-app/src/pages/index.spec.tsx')).toBeTruthy(); expect(tree.exists('apps/my-app/src/pages/index.module.css')).toBeTruthy(); }); describe('--style scss', () => { it('should generate scss styles', async () => { const result = await runSchematic( 'app', { name: 'myApp', style: 'scss' }, appTree ); expect( result.exists('apps/my-app/src/pages/index.module.scss') ).toBeTruthy(); const indexContent = result .read('apps/my-app/src/pages/index.tsx') .toString(); expect(indexContent).toContain( `import styles from './index.module.scss'` ); }); }); describe('--style less', () => { it('should generate less styles', async () => { const result = await runSchematic( 'app', { name: 'myApp', style: 'less' }, appTree ); expect( result.exists('apps/my-app/src/pages/index.module.less') ).toBeTruthy(); const indexContent = result .read('apps/my-app/src/pages/index.tsx') .toString(); expect(indexContent).toContain( `import styles from './index.module.less'` ); }); }); describe('--style styl', () => { it('should generate stylus styles', async () => { const result = await runSchematic( 'app', { name: 'myApp', style: 'styl' }, appTree ); expect( result.exists('apps/my-app/src/pages/index.module.styl') ).toBeTruthy(); const indexContent = result .read('apps/my-app/src/pages/index.tsx') .toString(); expect(indexContent).toContain( `import styles from './index.module.styl'` ); }); }); describe('--style styled-components', () => { it('should generate scss styles', async () => { const result = await runSchematic( 'app', { name: 'myApp', style: 'styled-components' }, appTree ); expect( result.exists('apps/my-app/src/pages/index.module.styled-components') ).toBeFalsy(); const indexContent = result .read('apps/my-app/src/pages/index.tsx') .toString(); expect(indexContent).not.toContain(`import styles from './index.module`); expect(indexContent).toContain(`import styled from 'styled-components'`); }); }); describe('--style @emotion/styled', () => { it('should generate emotion styles', async () => { const result = await runSchematic( 'app', { name: 'myApp', style: '@emotion/styled' }, appTree ); expect( result.exists('apps/my-app/src/pages/index.module.styled-components') ).toBeFalsy(); const indexContent = result .read('apps/my-app/src/pages/index.tsx') .toString(); expect(indexContent).not.toContain(`import styles from './index.module`); expect(indexContent).toContain(`import styled from '@emotion/styled'`); }); }); // TODO: We should also add styled-jsx support for Gatsby to keep React plugins consistent. // This needs to be here before Nx 12 is released. xdescribe('--style styled-jsx', () => { it('should use