view data tests
This commit is contained in:
131
core/eslint-rules/no-index-files.test.js
Normal file
131
core/eslint-rules/no-index-files.test.js
Normal file
@@ -0,0 +1,131 @@
|
||||
const { RuleTester } = require('eslint');
|
||||
const rule = require('./no-index-files');
|
||||
|
||||
const ruleTester = new RuleTester({
|
||||
parser: require.resolve('@typescript-eslint/parser'),
|
||||
parserOptions: {
|
||||
ecmaVersion: 2020,
|
||||
sourceType: 'module',
|
||||
ecmaFeatures: {
|
||||
jsx: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
ruleTester.run('no-index-files', rule, {
|
||||
valid: [
|
||||
// Regular file in domain
|
||||
{
|
||||
filename: '/path/to/core/domain/user/User.ts',
|
||||
code: "export class User {}",
|
||||
},
|
||||
// Regular file in application
|
||||
{
|
||||
filename: '/path/to/core/application/user/CreateUser.ts',
|
||||
code: "export class CreateUser {}",
|
||||
},
|
||||
// Regular file in shared
|
||||
{
|
||||
filename: '/path/to/core/shared/ValueObject.ts',
|
||||
code: "export class ValueObject {}",
|
||||
},
|
||||
// Regular file in ports
|
||||
{
|
||||
filename: '/path/to/core/ports/UserRepository.ts',
|
||||
code: "export interface UserRepository {}",
|
||||
},
|
||||
// File with index in the middle of the path
|
||||
{
|
||||
filename: '/path/to/core/domain/user/index/User.ts',
|
||||
code: "export class User {}",
|
||||
},
|
||||
// File with index in the name but not at the end
|
||||
{
|
||||
filename: '/path/to/core/domain/user/indexHelper.ts',
|
||||
code: "export class IndexHelper {}",
|
||||
},
|
||||
// Root index.ts is allowed
|
||||
{
|
||||
filename: '/path/to/core/index.ts',
|
||||
code: "export * from './domain';",
|
||||
},
|
||||
// File with index.ts in the middle of the path
|
||||
{
|
||||
filename: '/path/to/core/domain/index/User.ts',
|
||||
code: "export class User {}",
|
||||
},
|
||||
],
|
||||
|
||||
invalid: [
|
||||
// index.ts in domain
|
||||
{
|
||||
filename: '/path/to/core/domain/user/index.ts',
|
||||
code: "export * from './User';",
|
||||
errors: [
|
||||
{
|
||||
messageId: 'indexFile',
|
||||
},
|
||||
],
|
||||
},
|
||||
// index.ts in application
|
||||
{
|
||||
filename: '/path/to/core/application/user/index.ts',
|
||||
code: "export * from './CreateUser';",
|
||||
errors: [
|
||||
{
|
||||
messageId: 'indexFile',
|
||||
},
|
||||
],
|
||||
},
|
||||
// index.ts in shared
|
||||
{
|
||||
filename: '/path/to/core/shared/index.ts',
|
||||
code: "export * from './ValueObject';",
|
||||
errors: [
|
||||
{
|
||||
messageId: 'indexFile',
|
||||
},
|
||||
],
|
||||
},
|
||||
// index.ts in ports
|
||||
{
|
||||
filename: '/path/to/core/ports/index.ts',
|
||||
code: "export * from './UserRepository';",
|
||||
errors: [
|
||||
{
|
||||
messageId: 'indexFile',
|
||||
},
|
||||
],
|
||||
},
|
||||
// index.ts with Windows path separator
|
||||
{
|
||||
filename: 'C:\\path\\to\\core\\domain\\user\\index.ts',
|
||||
code: "export * from './User';",
|
||||
errors: [
|
||||
{
|
||||
messageId: 'indexFile',
|
||||
},
|
||||
],
|
||||
},
|
||||
// index.ts at the start of path
|
||||
{
|
||||
filename: 'index.ts',
|
||||
code: "export * from './domain';",
|
||||
errors: [
|
||||
{
|
||||
messageId: 'indexFile',
|
||||
},
|
||||
],
|
||||
},
|
||||
// index.ts in nested directory
|
||||
{
|
||||
filename: '/path/to/core/domain/user/profile/index.ts',
|
||||
code: "export * from './Profile';",
|
||||
errors: [
|
||||
{
|
||||
messageId: 'indexFile',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
Reference in New Issue
Block a user