Skip to content

Commit

Permalink
feat(linter): remove tslint from empty workspace and fix tslint support
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Jan 27, 2021
1 parent 1eda4dc commit 9a7fb5a
Show file tree
Hide file tree
Showing 11 changed files with 360 additions and 144 deletions.
101 changes: 101 additions & 0 deletions e2e/workspace/src/workspace-lib.test.ts
@@ -0,0 +1,101 @@
import {
checkFilesExist,
newProject,
runCLI,
runCLIAsync,
uniq,
updateFile,
} from '@nrwl/e2e/utils';

let proj: string;

beforeAll(() => {
proj = newProject();
});

describe('@nrwl/workspace:library', () => {
it('should be able to be created', () => {
const libName = uniq('mylib');
const dirName = uniq('dir');

runCLI(`generate @nrwl/workspace:lib ${libName} --directory ${dirName}`);

checkFilesExist(
`libs/${dirName}/${libName}/src/index.ts`,
`libs/${dirName}/${libName}/README.md`
);
});

describe('linting', () => {
it('should support eslint', () => {
const libName = uniq('mylib');

runCLI(`generate @nrwl/workspace:lib ${libName}`);

const result = runCLI(`lint ${libName}`);

expect(result).toContain(`Linting "${libName}"...`);
expect(result).toContain('All files pass linting.');
});

it('should support tslint', () => {
const libName = uniq('mylib');

runCLI(`generate @nrwl/workspace:lib ${libName} --linter tslint`);

const result = runCLI(`lint ${libName}`);

expect(result).toContain(`Linting "${libName}"...`);
expect(result).toContain('All files pass linting.');
});
});

describe('unit testing', () => {
it('should support jest', async () => {
const libName = uniq('mylib');

runCLI(`generate @nrwl/workspace:lib ${libName} --linter tslint`);

const { stderr: result } = await runCLIAsync(`test ${libName}`);

expect(result).toContain(`Test Suites: 1 passed, 1 total`);
expect(result).toContain('Tests: 1 passed, 1 total');
});
});

it('should be able to use and be used by other libs', () => {
const consumerLib = uniq('consumer');
const producerLib = uniq('producer');

runCLI(`generate @nrwl/workspace:lib ${consumerLib}`);
runCLI(`generate @nrwl/workspace: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}`);
});
});
2 changes: 2 additions & 0 deletions packages/linter/src/generators/init/init.ts
Expand Up @@ -10,6 +10,7 @@ import {
eslintVersion,
typescriptESLintVersion,
tslintVersion,
buildAngularVersion,
} from '../../utils/versions';
import { Linter } from '../utils/linter';

Expand Down Expand Up @@ -160,6 +161,7 @@ function initTsLint(tree: Tree) {
{},
{
tslint: tslintVersion,
'@angular-devkit/build-angular': buildAngularVersion,
}
);
}
Expand Down
1 change: 1 addition & 0 deletions packages/linter/src/utils/versions.ts
@@ -1,6 +1,7 @@
export const nxVersion = '*';

export const tslintVersion = '~6.1.0';
export const buildAngularVersion = '~0.1100.1';

export const typescriptESLintVersion = '4.3.0';
export const eslintVersion = '7.10.0';
Expand Down

0 comments on commit 9a7fb5a

Please sign in to comment.