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

fix(workspace): fix glob pattern detection #6502

Merged
merged 5 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion packages/vitest/src/node/workspace/resolveWorkspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ async function resolveWorkspaceProjectConfigs(
const stringOption = definition.replace('<rootDir>', vitest.config.root)
// if the string doesn't contain a glob, we can resolve it directly
// ['./vitest.config.js']
if (!stringOption.includes('*')) {
if (!stringOption.includes('*') && !stringOption.startsWith('!')) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should probably use isDynamicPattern from fast-glob https://github.com/mrmlnc/fast-glob?tab=readme-ov-file#isdynamicpatternpattern-options, but it looks like it's not supported yet on tinyglobby SuperchupuDev/tinyglobby#28

Copy link
Member

Choose a reason for hiding this comment

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

Can we copy paste it maybe? Other cases includes {} for example

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good to me. I copied isDynamicPattern from fast-glob.

const file = resolve(vitest.config.root, stringOption)

if (!existsSync(file)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "a"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { test } from 'vitest';

test('test - a')
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "b"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { test } from 'vitest';

test('test - b')
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "c"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { test } from 'vitest';

test('test - c')
4 changes: 4 additions & 0 deletions test/config/fixtures/workspace/negated/vitest.workspace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default [
'packages/*',
'!packages/b'
]
11 changes: 11 additions & 0 deletions test/config/test/workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ it('correctly resolves workspace projects with a several folder globs', async ()
expect(stdout).toContain('test - b')
})

it('supports glob negation pattern', async () => {
const { stderr, stdout } = await runVitest({
root: 'fixtures/workspace/negated',
workspace: './fixtures/workspace/negated/vitest.workspace.ts',
})
expect(stderr).toBe('')
expect(stdout).toContain('test - a')
expect(stdout).toContain('test - c')
expect(stdout).not.toContain('test - b')
})

it('fails if project names are identical with a nice error message', async () => {
const { stderr } = await runVitest({
root: 'fixtures/workspace/invalid-duplicate-configs',
Expand Down
Loading