diff --git a/e2e/linter/src/linter.test.ts b/e2e/linter/src/linter.test.ts index fedba0a6aefc16..e340fd6d5094ce 100644 --- a/e2e/linter/src/linter.test.ts +++ b/e2e/linter/src/linter.test.ts @@ -261,9 +261,9 @@ describe('Linter', () => { }, 1000000); describe('workspace boundary rules', () => { - const libA = uniq('lib-a'); - const libB = uniq('lib-b'); - const libC = uniq('lib-c'); + const libA = uniq('tslib-a'); + const libB = uniq('tslib-b'); + const libC = uniq('tslib-c'); let projScope; beforeAll(() => { @@ -272,54 +272,122 @@ describe('Linter', () => { runCLI(`generate @nrwl/workspace:lib ${libB}`); runCLI(`generate @nrwl/workspace:lib ${libC}`); - // updateFile(`apps/${myapp}/src/main.ts`, `console.log("should fail");`); - }); + /** + * create tslib-a structure + */ + createFile( + `libs/${libA}/src/lib/tslib-a.ts`, + ` + export function libASayHello(): string { + return 'Hi from tslib-a'; + } + ` + ); - xdescribe('aaashould autofix noSelfCircularDependencies', () => { - beforeAll(() => { - /* - import { func1, func2 } from '@scope/same-lib'; + createFile( + `libs/${libA}/src/lib/some-non-exported-function.ts`, + ` + export function someNonPublicLibFunction() { + return 'this function is exported, but not via the libs barrel file'; + } + + export function someSelectivelyExportedFn() { + return 'this fn is exported selectively in the barrel file'; + } + ` + ); - should be transformed into + createFile( + `libs/${libA}/src/index.ts`, + ` + export * from './lib/tslib-a'; - import { func1 } from './func1'; - import { func2 } from './func2'; - */ + export { someSelectivelyExportedFn } from './lib/some-non-exported-function'; + ` + ); - createFile( - `libs/${libC}/src/lib/another-func.ts`, - ` - export function anotherFunc() { - return 'hi'; - } - ` - ); + /** + * create tslib-b structure + */ + createFile( + `libs/${libB}/src/index.ts`, + ` + export * from './lib/tslib-b'; + ` + ); - updateFile( - `libs/${libC}/src/lib/index.ts`, - ` - export * from './lib/${names(libC).fileName}'; - export * from './lib/another-func'; + createFile( + `libs/${libB}/src/lib/tslib-b.ts`, ` - ); + import { libASayHello } from '@${projScope}/tslib-a'; + // import { someNonPublicLibFunction } from '../../../tslib-a/src/lib/some-non-exported-function'; + import { someSelectivelyExportedFn } from '@${projScope}/@rabobank/tslib-a'; + + export function tslibB(): string { + someNonPublicLibFunction(); + someSelectivelyExportedFn(); + libASayHello(); + return 'hi there'; + } + ` + ); + + /** + * create tslib-c structure + */ - createFile( - `libs/${libC}/src/lib/lib-c-another.ts`, - ` -import { ${ - names(libC).propertyName - }, anotherFunc } from '@${projScope}/${libC}'; + createFile( + `libs/${libC}/src/index.ts`, + ` + export * from './lib/tslib-c'; + export * from './lib/constant'; + + ` + ); + + createFile( + `libs/${libC}/src/lib/constant.ts`, + ` + export const SOME_CONSTANT = 'some constant value'; + export const someFunc1 = () => 'hi'; + export function someFunc2() { + return 'hi2'; + } + ` + ); + + createFile( + `libs/${libC}/src/lib/tslib-c-another.ts`, + ` + import { tslibC } from './tslib-c'; +import { SOME_CONSTANT, someFunc1, someFunc2 } from './constant'; export function someStuff() { - anotherFunc(); - return ${names(libC).propertyName}(); + someFunc1(); + someFunc2(); + tslibC(); + console.log(SOME_CONSTANT); + return 'hi'; } + ` + ); + + createFile( + `libs/${libC}/src/lib/tslib-c.ts`, ` - ); + import { someFunc1, someFunc2, SOME_CONSTANT } from './constant'; - // scenario 2 - }); +export function tslibC(): string { + someFunc1(); + someFunc2(); + console.log(SOME_CONSTANT); + return 'tslib-c'; +} + ` + ); + }); + describe('aaashould autofix noSelfCircularDependencies', () => { it('should fix a circular self reference', () => { const stdout = runCLI(`lint ${libC}`, { silenceError: true, @@ -335,15 +403,16 @@ export function someStuff() { expect(fixedStout).not.toContain( 'Projects should use relative imports to import from other files within the same project' ); - const fileContent = readFile(`libs/${libC}/src/lib/lib-c-another.ts`); - expect(fileContent).toContain( - `import { ${names(libC).propertyName} } from './${ - names(libC).fileName - }';` - ); - expect(fileContent).toContain( - `import { anotherFunc } from './another-func';` - ); + const fileContent = readFile(`libs/${libC}/src/lib/tslib-c-another.ts`); + expect(fileContent).toContain(` + import { tslibC } from './tslib-c'; + import { SOME_CONSTANT, someFunc1, someFunc2 } from './constant'; + `); + + const fileContentTslibC = readFile(`libs/${libC}/src/lib/tslib-c.ts`); + expect(fileContentTslibC).toContain(` + import { someFunc1, someFunc2, SOME_CONSTANT } from './constant'; + `); }); }); });