From 2cc4d4804d198be887bdf2037d8259d178034ba0 Mon Sep 17 00:00:00 2001 From: Miroslav Jonas Date: Thu, 6 Apr 2023 12:49:57 +0200 Subject: [PATCH] feat(js): move workspace tests --- e2e/js/src/js.test.ts | 93 +++++++++++++++++++++++++++++-- e2e/nx-misc/src/workspace.test.ts | 81 --------------------------- 2 files changed, 89 insertions(+), 85 deletions(-) diff --git a/e2e/js/src/js.test.ts b/e2e/js/src/js.test.ts index 4ab8cced35d0d4..e4726b839165eb 100644 --- a/e2e/js/src/js.test.ts +++ b/e2e/js/src/js.test.ts @@ -1,10 +1,12 @@ import { + checkFilesDoNotExist, + checkFilesExist, cleanupProject, createFile, - expectJestTestsToPass, newProject, readJson, runCLI, + runCLIAsync, uniq, updateFile, updateJson, @@ -87,7 +89,90 @@ export function ${lib}Wildcard() { ); }, 240_000); - it('should run default jest tests', async () => { - await expectJestTestsToPass('@nrwl/js:lib'); - }, 240_000); + it('should create a library that can be linted, tested and built', async () => { + const libName = uniq('mylib'); + const dirName = uniq('dir'); + + runCLI(`generate @nrwl/js:lib ${libName} --directory ${dirName}`); + + checkFilesExist( + `libs/${dirName}/${libName}/src/index.ts`, + `libs/${dirName}/${libName}/README.md` + ); + + // Lint + const result = runCLI(`lint ${dirName}-${libName}`); + + expect(result).toContain(`Linting "${dirName}-${libName}"...`); + expect(result).toContain('All files pass linting.'); + + // Test + const testResult = await runCLIAsync(`test ${dirName}-${libName}`); + expect(testResult.combinedOutput).toContain( + 'Test Suites: 1 passed, 1 total' + ); + + // Build + const buildResult = runCLI(`build ${dirName}-${libName}`); + + expect(buildResult).toContain( + `Compiling TypeScript files for project "${dirName}-${libName}"...` + ); + expect(buildResult).toContain( + `Done compiling TypeScript files for project "${dirName}-${libName}".` + ); + }, 500_000); + + it('should be able to use and be used by other libs', () => { + const consumerLib = uniq('consumer'); + const producerLib = uniq('producer'); + + runCLI(`generate @nrwl/js:lib ${consumerLib} --bundler=none`); + runCLI(`generate @nrwl/js:lib ${producerLib} --bundler=none`); + + updateFile( + `libs/${producerLib}/src/lib/${producerLib}.ts`, + 'export const a = 0;' + ); + + updateFile( + `libs/${consumerLib}/src/lib/${consumerLib}.ts`, + ` + import { a } from '@${scope}/${producerLib}'; + + export function ${consumerLib}() { + return a + 1; + }` + ); + updateFile( + `libs/${consumerLib}/src/lib/${consumerLib}.spec.ts`, + ` + import { ${consumerLib} } from './${consumerLib}'; + + describe('', () => { + it('should return 1', () => { + expect(${consumerLib}()).toEqual(1); + }); + });` + ); + + runCLI(`test ${consumerLib}`); + }); + + it('should not be able to be built when it has no bundler', () => { + const nonBuildable = uniq('buildable'); + + runCLI(`generate @nrwl/js:lib ${nonBuildable} --bundler=none`); + + const result = runCLI(`build ${nonBuildable}`); + + expect(result).toContain( + `Compiling TypeScript files for project "${nonBuildable}"...` + ); + expect(result).toContain( + `Done compiling TypeScript files for project "${nonBuildable}".` + ); + + checkFilesDoNotExist(`dist/libs/${nonBuildable}/README.md`); + }); }); diff --git a/e2e/nx-misc/src/workspace.test.ts b/e2e/nx-misc/src/workspace.test.ts index 9cbcf34b10ca0e..c0328f26b699da 100644 --- a/e2e/nx-misc/src/workspace.test.ts +++ b/e2e/nx-misc/src/workspace.test.ts @@ -6,7 +6,6 @@ import { runCLI, uniq, updateFile, - expectJestTestsToPass, readFile, exists, updateProjectConfig, @@ -27,86 +26,6 @@ describe('Workspace Tests', () => { afterAll(() => cleanupProject()); - describe('@nrwl/js:library', () => { - it('should create a library that can be tested and linted', async () => { - const libName = uniq('mylib'); - const dirName = uniq('dir'); - - runCLI(`generate @nrwl/js:lib ${libName} --directory ${dirName}`); - - checkFilesExist( - `libs/${dirName}/${libName}/src/index.ts`, - `libs/${dirName}/${libName}/README.md` - ); - - // Lint - const result = runCLI(`lint ${dirName}-${libName}`); - - expect(result).toContain(`Linting "${dirName}-${libName}"...`); - expect(result).toContain('All files pass linting.'); - - // Test - await expectJestTestsToPass('@nrwl/js:lib'); - }, 100000); - - it('should be able to use and be used by other libs', () => { - const consumerLib = uniq('consumer'); - const producerLib = uniq('producer'); - - runCLI(`generate @nrwl/js:lib ${consumerLib}`); - runCLI(`generate @nrwl/js:lib ${producerLib}`); - - updateFile( - `libs/${producerLib}/src/lib/${producerLib}.ts`, - 'export const a = 0;' - ); - - updateFile( - `libs/${consumerLib}/src/lib/${consumerLib}.ts`, - ` - import { a } from '@${proj}/${producerLib}'; - - export function ${consumerLib}() { - return a + 1; - }` - ); - updateFile( - `libs/${consumerLib}/src/lib/${consumerLib}.spec.ts`, - ` - import { ${consumerLib} } from './${consumerLib}'; - - describe('', () => { - it('should return 1', () => { - expect(${consumerLib}()).toEqual(1); - }); - });` - ); - - runCLI(`test ${consumerLib}`); - }); - - it('should be able to be built when it is buildable', () => { - const buildableLib = uniq('buildable'); - - runCLI(`generate @nrwl/js:lib ${buildableLib} --buildable`); - - const result = runCLI(`build ${buildableLib}`); - - expect(result).toContain( - `Compiling TypeScript files for project "${buildableLib}"...` - ); - expect(result).toContain( - `Done compiling TypeScript files for project "${buildableLib}".` - ); - - checkFilesExist(`dist/libs/${buildableLib}/README.md`); - - const json = readJson(`dist/libs/${buildableLib}/package.json`); - expect(json.main).toEqual('./src/index.js'); - expect(json.types).toEqual('./src/index.d.ts'); - }); - }); - describe('@nrwl/workspace:npm-package', () => { it('should create a minimal npm package', () => { const npmPackage = uniq('npm-package');