Skip to content

Commit

Permalink
chore(eslint-plugin): refactor test case layout to help with doc gen (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHenry committed Aug 2, 2021
1 parent dfb19ec commit 8106486
Show file tree
Hide file tree
Showing 81 changed files with 4,447 additions and 4,449 deletions.
2 changes: 1 addition & 1 deletion packages/eslint-plugin/jest.config.js
Expand Up @@ -5,7 +5,7 @@ module.exports = {
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
testRegex: './tests/.+\\.test\\.ts$',
testRegex: ['./tests/.+\\.test\\.ts$', './tests/.+/spec\\.ts$'],
collectCoverage: false,
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
Expand Down
118 changes: 0 additions & 118 deletions packages/eslint-plugin/tests/rules/component-class-suffix.test.ts

This file was deleted.

105 changes: 105 additions & 0 deletions packages/eslint-plugin/tests/rules/component-class-suffix/cases.ts
@@ -0,0 +1,105 @@
import { convertAnnotatedSourceToFailureCase } from '@angular-eslint/utils';
import type { MessageIds } from '../../../src/rules/component-class-suffix';

const messageId: MessageIds = 'componentClassSuffix';

export const valid = [
`
@Component({
selector: 'sg-foo-bar',
template: '<foo-bar [foo]="bar">{{baz + 42}}</foo-bar>'
})
class TestComponent {}
`,
`
@Directive({
selector: '[myHighlight]'
})
class TestDirective {}
`,
`
@Pipe({
selector: 'sg-test-pipe'
})
class TestPipe {}
`,
`
@Injectable()
class TestService {}
`,
`
class TestEmpty {}
`,
{
code: `
@Component({
selector: 'sgBarFoo'
})
class TestPage {}
`,
options: [{ suffixes: ['Page'] }],
},
{
code: `
@Component({
selector: 'sgBarFoo'
})
class TestPage {}
`,
options: [{ suffixes: ['Page', 'View'] }],
},
];

export const invalid = [
convertAnnotatedSourceToFailureCase({
description: 'it should fail when component class is with the wrong suffix',
annotatedSource: `
@Component({
selector: 'sg-foo-bar'
})
class Test {}
~~~~
`,
messageId,
data: { suffixes: '"Component"' },
}),
convertAnnotatedSourceToFailureCase({
description: `it should fail when a different list of suffixes is set and doesn't match`,
annotatedSource: `
@Component({
selector: 'sgBarFoo'
})
class TestPage {}
~~~~~~~~
`,
messageId,
options: [{ suffixes: ['Component', 'View'] }],
data: { suffixes: '"Component" or "View"' },
}),
convertAnnotatedSourceToFailureCase({
description: `it should fail when a different list of suffixes is set and doesn't match`,
annotatedSource: `
@Component({
selector: 'sgBarFoo'
})
class TestPage {}
~~~~~~~~
`,
messageId,
options: [{ suffixes: ['Component'] }],
data: { suffixes: '"Component"' },
}),
convertAnnotatedSourceToFailureCase({
description: `it should fail when a different list of suffixes is set and doesn't match`,
annotatedSource: `
@Component({
selector: 'sgBarFoo'
})
class TestDirective {}
~~~~~~~~~~~~~
`,
messageId,
options: [{ suffixes: ['Page'] }],
data: { suffixes: '"Page"' },
}),
];
12 changes: 12 additions & 0 deletions packages/eslint-plugin/tests/rules/component-class-suffix/spec.ts
@@ -0,0 +1,12 @@
import { RuleTester } from '@angular-eslint/utils';
import rule, { RULE_NAME } from '../../../src/rules/component-class-suffix';
import { invalid, valid } from './cases';

const ruleTester = new RuleTester({
parser: '@typescript-eslint/parser',
});

ruleTester.run(RULE_NAME, rule, {
valid,
invalid,
});

0 comments on commit 8106486

Please sign in to comment.