import { checkFilesExist, cleanupProject, getSelectedPackageManager, packageInstall, readJson, runCLI, runCommand, runCreateWorkspace, uniq, } from '@nrwl/e2e/utils'; describe('create-nx-workspace --preset=npm', () => { const wsName = uniq('npm'); let orginalGlobCache; beforeAll(() => { orginalGlobCache = process.env.NX_PROJECT_GLOB_CACHE; // glob cache is causing previous projects to show in Workspace for maxWorkers overrides // which fails due to files no longer being available process.env.NX_PROJECT_GLOB_CACHE = 'false'; runCreateWorkspace(wsName, { preset: 'npm', packageManager: getSelectedPackageManager(), }); }); afterEach(() => { // cleanup previous projects runCommand(`rm -rf packages/** tsconfig.base.json`); }); afterAll(() => { process.env.NX_PROJECT_GLOB_CACHE = orginalGlobCache; cleanupProject({ skipReset: true }); }); it('should add angular application', () => { packageInstall('@nrwl/angular', wsName); const appName = uniq('my-app'); expect(() => { runCLI(`generate @nrwl/angular:app ${appName} --no-interactive`); }).not.toThrowError(); checkFilesExist('tsconfig.base.json'); }, 1_000_000); it('should add angular library', () => { packageInstall('@nrwl/angular', wsName); const libName = uniq('lib'); expect(() => { runCLI(`generate @nrwl/angular:lib ${libName} --no-interactive`); }).not.toThrowError(); checkFilesExist('tsconfig.base.json'); const tsconfig = readJson(`tsconfig.base.json`); expect(tsconfig.compilerOptions.paths).toEqual({ [libName]: [`packages/${libName}/src/index.ts`], }); }, 1_000_000); it('should add js library', () => { packageInstall('@nrwl/js', wsName); const libName = uniq('lib'); expect(() => runCLI(`generate @nrwl/js:library ${libName} --no-interactive`) ).not.toThrowError(); checkFilesExist('tsconfig.base.json'); const tsconfig = readJson(`tsconfig.base.json`); expect(tsconfig.compilerOptions.paths).toEqual({ [libName]: [`packages/${libName}/src/index.ts`], }); }); it('should add web application', () => { packageInstall('@nrwl/web', wsName); const appName = uniq('my-app'); expect(() => runCLI(`generate @nrwl/web:app ${appName} --no-interactive`) ).not.toThrowError(); checkFilesExist('tsconfig.base.json'); }); it('should add react application', () => { packageInstall('@nrwl/react', wsName); const appName = uniq('my-app'); expect(() => { runCLI(`generate @nrwl/react:app ${appName} --no-interactive`); }).not.toThrowError(); checkFilesExist('tsconfig.base.json'); }); it('should add react library', () => { packageInstall('@nrwl/react', wsName); const libName = uniq('lib'); expect(() => { runCLI(`generate @nrwl/react:lib ${libName} --no-interactive`); }).not.toThrowError(); checkFilesExist('tsconfig.base.json'); const tsconfig = readJson(`tsconfig.base.json`); expect(tsconfig.compilerOptions.paths).toEqual({ [libName]: [`packages/${libName}/src/index.ts`], }); }); it('should add next application', () => { packageInstall('@nrwl/next', wsName); const appName = uniq('my-app'); expect(() => { runCLI(`generate @nrwl/next:app ${appName} --no-interactive`); }).not.toThrowError(); checkFilesExist('tsconfig.base.json'); }); it('should add next library', () => { packageInstall('@nrwl/next', wsName); const libName = uniq('lib'); expect(() => { runCLI(`generate @nrwl/next:lib ${libName} --no-interactive`); }).not.toThrowError(); checkFilesExist('tsconfig.base.json'); const tsconfig = readJson(`tsconfig.base.json`); expect(tsconfig.compilerOptions.paths).toEqual({ [libName]: [`packages/${libName}/src/index.ts`], [`${libName}/server`]: [`packages/${libName}/src/server.ts`], }); }); it('should add react-native application', () => { packageInstall('@nrwl/react-native', wsName); const appName = uniq('my-app'); expect(() => { runCLI( `generate @nrwl/react-native:app ${appName} --install=false --no-interactive` ); }).not.toThrowError(); checkFilesExist('tsconfig.base.json'); }); it('should add react-native library', () => { packageInstall('@nrwl/react-native', wsName); const libName = uniq('lib'); expect(() => { runCLI(`generate @nrwl/react-native:lib ${libName} --no-interactive`); }).not.toThrowError(); checkFilesExist('tsconfig.base.json'); const tsconfig = readJson(`tsconfig.base.json`); expect(tsconfig.compilerOptions.paths).toEqual({ [libName]: [`packages/${libName}/src/index.ts`], }); }); it('should add node application', () => { packageInstall('@nrwl/node', wsName); const appName = uniq('my-app'); expect(() => { runCLI(`generate @nrwl/node:app ${appName} --no-interactive`); }).not.toThrowError(); checkFilesExist('tsconfig.base.json'); }); it('should add node library', () => { packageInstall('@nrwl/node', wsName); const libName = uniq('lib'); expect(() => { runCLI(`generate @nrwl/node:lib ${libName} --no-interactive`); }).not.toThrowError(); checkFilesExist('tsconfig.base.json'); const tsconfig = readJson(`tsconfig.base.json`); expect(tsconfig.compilerOptions.paths).toEqual({ [libName]: [`packages/${libName}/src/index.ts`], }); }); it('should add nest application', () => { packageInstall('@nrwl/nest', wsName); const appName = uniq('my-app'); expect(() => { runCLI(`generate @nrwl/nest:app ${appName} --no-interactive`); }).not.toThrowError(); checkFilesExist('tsconfig.base.json'); }); it('should add nest library', () => { packageInstall('@nrwl/nest', wsName); const libName = uniq('lib'); expect(() => { runCLI(`generate @nrwl/nest:lib ${libName} --no-interactive`); }).not.toThrowError(); checkFilesExist('tsconfig.base.json'); const tsconfig = readJson(`tsconfig.base.json`); expect(tsconfig.compilerOptions.paths).toEqual({ [libName]: [`packages/${libName}/src/index.ts`], }); }); it('should add express application', () => { packageInstall('@nrwl/express', wsName); const appName = uniq('my-app'); expect(() => { runCLI(`generate @nrwl/express:app ${appName} --no-interactive`); }).not.toThrowError(); checkFilesExist('tsconfig.base.json'); }); });