import { NxJsonConfiguration, readProjectConfiguration } from '@nrwl/devkit'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import { applicationGenerator } from './application'; import { readJson, Tree } from '@nrwl/devkit'; describe('app', () => { let tree: Tree; beforeEach(() => { tree = createTreeWithEmptyWorkspace(); tree.write('.gitignore', '# empty'); tree.write('.prettierignore', '# empty'); }); it('should update workspace.json', async () => { await applicationGenerator(tree, { name: 'myApp', style: 'css', standaloneConfig: false, }); const workspaceJson = readJson(tree, '/workspace.json'); const nxJson = readJson(tree, 'nx.json'); expect(workspaceJson.projects['my-app'].root).toEqual('apps/my-app'); expect(workspaceJson.projects['my-app-e2e'].root).toEqual( 'apps/my-app-e2e' ); expect(nxJson.defaultProject).toEqual('my-app'); }); it('should update tags + implicitDependencies', async () => { await applicationGenerator(tree, { name: 'myApp', style: 'css', tags: 'one,two', standaloneConfig: false, }); const myAppConfig = readProjectConfiguration(tree, 'my-app'); const myAppConfigE2E = readProjectConfiguration(tree, 'my-app-e2e'); expect({ 'my-app': { tags: myAppConfig.tags }, 'my-app-e2e': { tags: myAppConfigE2E.tags, implicitDependencies: myAppConfigE2E.implicitDependencies, }, }).toEqual({ 'my-app': { tags: ['one', 'two'], }, 'my-app-e2e': { tags: [], implicitDependencies: ['my-app'], }, }); }); it('should generate files', async () => { await applicationGenerator(tree, { name: 'myApp', style: 'css', standaloneConfig: false, }); 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 () => { await applicationGenerator(tree, { name: 'myApp', style: 'scss', standaloneConfig: false, }); expect( tree.exists('apps/my-app/src/pages/index.module.scss') ).toBeTruthy(); const indexContent = tree .read('apps/my-app/src/pages/index.tsx') .toString(); expect(indexContent).toContain( `import * as styles from './index.module.scss'` ); const nxJson = readJson(tree, 'nx.json'); expect(nxJson.generators['@nrwl/gatsby'].application.style).toEqual( 'scss' ); }); }); describe('--style less', () => { it('should generate less styles', async () => { await applicationGenerator(tree, { name: 'myApp', style: 'less', standaloneConfig: false, }); expect( tree.exists('apps/my-app/src/pages/index.module.less') ).toBeTruthy(); const indexContent = tree .read('apps/my-app/src/pages/index.tsx') .toString(); expect(indexContent).toContain( `import * as styles from './index.module.less'` ); const nxJson = readJson(tree, 'nx.json'); expect(nxJson.generators['@nrwl/gatsby'].application.style).toEqual( 'less' ); }); }); describe('--style styl', () => { it('should generate stylus styles', async () => { await applicationGenerator(tree, { name: 'myApp', style: 'styl', standaloneConfig: false, }); expect( tree.exists('apps/my-app/src/pages/index.module.styl') ).toBeTruthy(); const indexContent = tree .read('apps/my-app/src/pages/index.tsx') .toString(); expect(indexContent).toContain( `import * as styles from './index.module.styl'` ); const nxJson = readJson(tree, 'nx.json'); expect(nxJson.generators['@nrwl/gatsby'].application.style).toEqual( 'styl' ); }); }); describe('--style styled-components', () => { it('should generate scss styles', async () => { await applicationGenerator(tree, { name: 'myApp', style: 'styled-components', standaloneConfig: false, }); expect( tree.exists('apps/my-app/src/pages/index.module.styled-components') ).toBeFalsy(); const indexContent = tree .read('apps/my-app/src/pages/index.tsx') .toString(); expect(indexContent).not.toContain( `import * as styles from './index.module` ); expect(indexContent).toContain(`import styled from 'styled-components'`); const nxJson = readJson(tree, 'nx.json'); expect(nxJson.generators['@nrwl/gatsby'].application.style).toEqual( 'styled-components' ); }); }); describe('--style @emotion/styled', () => { it('should generate emotion styles', async () => { await applicationGenerator(tree, { name: 'myApp', style: '@emotion/styled', standaloneConfig: false, }); expect( tree.exists('apps/my-app/src/pages/index.module.styled-components') ).toBeFalsy(); const indexContent = tree .read('apps/my-app/src/pages/index.tsx') .toString(); expect(indexContent).not.toContain( `import * as styles from './index.module` ); expect(indexContent).toContain(`import styled from '@emotion/styled'`); const nxJson = readJson(tree, 'nx.json'); expect(nxJson.generators['@nrwl/gatsby'].application.style).toEqual( '@emotion/styled' ); }); }); describe('--style styled-jsx', () => { it('should use