Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement inclusion/exclusion operators on VFS #80

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/quick-timers-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'steiger': minor
---

Implement the inclusion/exclusion operators on VFS
1 change: 1 addition & 0 deletions packages/steiger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"effector": "^23.2.1",
"globby": "^14.0.1",
"immer": "^10.1.1",
"minimatch": "^10.0.1",
"patronum": "^2.2.0",
"prexit": "^2.2.0",
"yargs": "^17.7.2",
Expand Down
328 changes: 328 additions & 0 deletions packages/steiger/src/features/apply-globs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,328 @@
import { expect, it, describe } from 'vitest'

import applyGlobs from './apply-globs'
import { joinFromRoot, parseIntoFsdRoot } from '../../../steiger-plugin-fsd/src/_lib/prepare-test'
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we create a shared folder for test utilities for both Steiger and the fsd-plugin? Because, maybe it's just me, but I don't really like this import

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can just copy-paste that file, no need to set up a whole separate folder for it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if you'd like to do it before merging, because I'm honestly fine merging it as is

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to copy that file after all, so Steiger package has a separate test utility. Also fixed several minor things in the code


describe('applyGlobs', () => {
it('should return the passed folder if no globs are provided', () => {
const root = parseIntoFsdRoot(
`
📂 shared
📂 ui
📄 styles.css
📄 Button.tsx
📄 TextField.tsx
📄 index.ts
`,
joinFromRoot('src'),
)

expect(applyGlobs(root, {})).toEqual(root)
expect(
applyGlobs(root, {
inclusions: [],
exclusions: [],
}),
).toEqual(root)
})

it('should return the picked folder if a specific folder is passed to inclusion patterns', () => {
const root = parseIntoFsdRoot(
`
📂 shared
📂 ui
📄 styles.css
📄 Button.tsx
📄 TextField.tsx
📄 index.ts
📂 entities
📂 user
📄 UserAvatar.tsx
📂 product
📄 ProductCard.tsx
`,
joinFromRoot('src'),
)

const expected = parseIntoFsdRoot(
`
📂 shared
📂 ui
📄 styles.css
📄 Button.tsx
📄 TextField.tsx
📄 index.ts
`,
joinFromRoot('src'),
)

const actual = applyGlobs(root, {
inclusions: ['/src/shared/**'],
exclusions: [],
})

expect(actual).toEqual(expected)
})

it('should return all __mock__ folders if the inclusion pattern says to include them all', () => {
const root = parseIntoFsdRoot(
`
📂 shared
📂 ui
📂 __mocks__
📄 Button.tsx
📄 styles.css
📄 Button.tsx
📄 TextField.tsx
📄 index.ts
📂 entities
📂 user
📂 __mocks__
📄 UserAvatar.tsx
📄 UserAvatar.tsx
📂 product
📄 ProductCard.tsx
`,
joinFromRoot('src'),
)

const expected = parseIntoFsdRoot(
`
📂 shared
📂 ui
📂 __mocks__
📄 Button.tsx
📂 entities
📂 user
📂 __mocks__
📄 UserAvatar.tsx
`,
joinFromRoot('src'),
)

const actual = applyGlobs(root, {
inclusions: ['**/__mocks__/**'],
exclusions: [],
})

expect(actual).toEqual(expected)
})

it('should return files picked by extension if the inclusion patterns pick by extension', () => {
const root = parseIntoFsdRoot(
`
📂 shared
📂 ui
📄 styles.css
📄 Button.tsx
📄 TextField.tsx
📄 index.ts
📂 entities
📂 user
📄 styles.css
📄 UserAvatar.tsx
📂 product
📄 ProductCard.tsx
`,
joinFromRoot('src'),
)

const expected = parseIntoFsdRoot(
`
📂 shared
📂 ui
📄 styles.css
📂 entities
📂 user
📄 styles.css
`,
joinFromRoot('src'),
)

const actual = applyGlobs(root, {
inclusions: ['**/*.css'],
exclusions: [],
})

expect(actual).toEqual(expected)
})

it('should return a specific single file if the inclusion pattern pick that only file', () => {
const root = parseIntoFsdRoot(
`
📂 shared
📂 ui
📄 styles.css
📄 Button.tsx
📄 TextField.tsx
📄 index.ts
📂 entities
📂 user
📄 styles.css
📄 UserAvatar.tsx
📂 product
📄 ProductCard.tsx
`,
joinFromRoot('src'),
)

const expected = parseIntoFsdRoot(
`
📂 shared
📂 ui
📄 TextField.tsx
`,
joinFromRoot('src'),
)

const actual = applyGlobs(root, {
inclusions: ['/src/shared/ui/TextField.tsx'],
exclusions: [],
})

expect(actual).toEqual(expected)
})

it('should correctly handle negations in exclusion patterns', () => {
const root = parseIntoFsdRoot(
`
📂 shared
📂 ui
📄 styles.css
📄 Button.tsx
📄 TextField.tsx
📄 index.ts
📂 config
📄 eslint.config.js
📄 styling.config.js
📂 entities
📂 user
📄 styles.css
📄 UserAvatar.tsx
📂 product
📄 ProductCard.tsx
`,
joinFromRoot('src'),
)

const expected = parseIntoFsdRoot(
`
📂 shared
📂 ui
📄 styles.css
📄 Button.tsx
📄 TextField.tsx
📄 index.ts
📂 config
📄 eslint.config.js
📂 entities
📂 user
📄 styles.css
📄 UserAvatar.tsx
📂 product
📄 ProductCard.tsx
`,
joinFromRoot('src'),
)

const actual = applyGlobs(root, {
exclusions: ['**/*.config.js', '!**/eslint.config.js'],
})

expect(actual).toEqual(expected)
})

it('should return the fs tree without all __mock__ folders if the exclusion pattern says to ignore them all', () => {
const root = parseIntoFsdRoot(
`
📂 shared
📂 ui
📂 __mocks__
📄 Button.tsx
📄 styles.css
📄 Button.tsx
📄 TextField.tsx
📄 index.ts
📂 entities
📂 user
📂 __mocks__
📄 UserAvatar.tsx
📄 UserAvatar.tsx
📂 product
📄 ProductCard.tsx
`,
joinFromRoot('src'),
)

const expected = parseIntoFsdRoot(
`
📂 shared
📂 ui
📄 styles.css
📄 Button.tsx
📄 TextField.tsx
📄 index.ts
📂 entities
📂 user
📄 UserAvatar.tsx
📂 product
📄 ProductCard.tsx
`,
joinFromRoot('src'),
)

const actual = applyGlobs(root, {
inclusions: [],
exclusions: ['**/__mocks__/**'],
})

expect(actual).toEqual(expected)
})

it('should exclude files with specific extension if exclusion pattern is set up accordingly', () => {
const root = parseIntoFsdRoot(
`
📂 shared
📂 lib
📄 get-query-params.ts
📄 get-query-params.test.ts
📂 ui
📄 styles.css
📄 Button.tsx
📄 Button.test.tsx
📄 TextField.tsx
📄 TextField.test.tsx
📄 index.ts
📂 entities
📂 user
📄 styles.css
📄 UserAvatar.tsx
📄 UserAvatar.test.tsx
📂 product
📄 ProductCard.tsx
`,
joinFromRoot('src'),
)

const expected = parseIntoFsdRoot(
`
📂 shared
📂 lib
📄 get-query-params.ts
📂 ui
📄 styles.css
📄 Button.tsx
📄 TextField.tsx
📄 index.ts
`,
joinFromRoot('src'),
)

const actual = applyGlobs(root, {
inclusions: ['/src/shared/**'],
exclusions: ['**/*.test.{tsx,ts}'],
})

expect(actual).toEqual(expected)
})
})
Loading