Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bd8a7df
fix: filter projects eagerly during config resolution
sheremet-va Jan 20, 2025
570e403
chore: cleanup
sheremet-va Jan 20, 2025
48209a6
chore: cleanup
sheremet-va Jan 20, 2025
a9dd4d7
chore: cleanup
sheremet-va Jan 21, 2025
8c28185
chore: improve error message
sheremet-va Jan 21, 2025
79b6d78
chore: fix glob
sheremet-va Jan 21, 2025
bad745f
fix: restart server on project name change
sheremet-va Jan 21, 2025
96a609f
fix: correctly set the name for browser instances
sheremet-va Jan 21, 2025
0fdaf8f
fix: correctly inject name
sheremet-va Jan 21, 2025
4eea6be
test: cleanup
sheremet-va Jan 21, 2025
e8f2251
chore: cleanup
sheremet-va Jan 21, 2025
dde22a6
chore: add comment
sheremet-va Jan 21, 2025
d0581fd
Merge branch 'main' of github.com:vitest-dev/vitest into fix/project-…
sheremet-va Jan 21, 2025
a30a5d4
chore: cleanup error msg
sheremet-va Jan 21, 2025
e5de674
test: oops
sheremet-va Jan 21, 2025
59e0b04
Merge branch 'main' of github.com:vitest-dev/vitest into fix/project-…
sheremet-va Jan 22, 2025
64b039d
refactor: keep project filter in a hidden vitest field
sheremet-va Jan 22, 2025
dfab725
chore: fix check
sheremet-va Jan 22, 2025
eeac4bd
test: cleanup
sheremet-va Jan 22, 2025
572a9d8
test: add workspace test for filtering
sheremet-va Jan 22, 2025
07331ba
fix: don't resolve `node:` and `internal:` in the error stack
sheremet-va Jan 22, 2025
4457ad0
test: add test for project change
sheremet-va Jan 22, 2025
86f9758
chore: cleanup
sheremet-va Jan 22, 2025
85dd916
Merge branch 'main' into fix/project-filter-eager
AriPerkkio Jan 22, 2025
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
Prev Previous commit
Next Next commit
chore: improve error message
  • Loading branch information
sheremet-va committed Jan 21, 2025
commit 8c28185a64b14b56ee18447e29b06f337e5f8878
2 changes: 1 addition & 1 deletion packages/browser/src/node/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export function createBrowserPool(vitest: Vitest): ProcessPool {
await project._initBrowserProvider()

if (!project.browser) {
throw new TypeError(`The browser server was not initialized for the ${project.name} project. This is a bug in Vitest. Please, open a new issue with reproduction.`)
throw new TypeError(`The browser server was not initialized${project.name ? ` for the "${project.name}" project` : ''}. This is a bug in Vitest. Please, open a new issue with reproduction.`)
}
await executeTests(method, project, files)
}
Expand Down
8 changes: 1 addition & 7 deletions packages/vitest/src/node/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,9 @@ export class Vitest {
const projects = await this.resolveWorkspace(cliOptions)
this.resolvedProjects = projects
this.projects = projects
// const filters = toArray(resolved.project).map(s => wildcardPatternToRegExp(s))
// if (filters.length > 0) {
// this.projects = this.projects.filter(p =>
// filters.some(pattern => pattern.test(p.name)),
// )
if (!this.projects.length) {
throw new Error(`No projects matched the filter "${toArray(resolved.project).join('", "')}".`)
}
// }
if (!this.coreWorkspaceProject) {
this.coreWorkspaceProject = TestProject._createBasicProject(this)
}
Expand Down Expand Up @@ -404,7 +398,7 @@ export class Vitest {
// user doesn't have a workspace config, return default project
if (!workspaceConfigPath) {
// user can filter projects with --project flag, `getDefaultTestProject`
// return the project only if it matches the filter
// returns the project only if it matches the filter
const project = getDefaultTestProject(this)
if (!project) {
return []
Expand Down
13 changes: 11 additions & 2 deletions packages/vitest/src/node/workspace/resolveWorkspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,13 @@ export async function resolveWorkspace(

// pretty rare case - the glob didn't match anything and there are no inline configs
if (!projectPromises.length) {
throw new Error(`No projects were found. Make sure your configuration is correct. The workspace: ${JSON.stringify(workspaceDefinition)}`)
throw new Error(
[
'No projects were found. Make sure your configuration is correct. ',
vitest.config.project.length ? `The filter matched no projects: ${vitest.config.project.map(p => p.toString()).join(', ')}. ` : '',
`The workspace: ${JSON.stringify(workspaceDefinition, null, 4)}.`,
].join(''),
)
}

const resolvedProjectsPromises = await Promise.allSettled(projectPromises)
Expand Down Expand Up @@ -445,7 +451,10 @@ export function getDefaultTestProject(vitest: Vitest): TestProject | null {
if (!filter.length) {
return project
}
const hasProjects = getPotentialProjectNames(project).some(p => filter.some(pattern => pattern.test(p)))
// check for the project name and browser names
const hasProjects = getPotentialProjectNames(project).some(p =>
filter.some(pattern => pattern.test(p)),
)
if (hasProjects) {
return project
}
Expand Down
3 changes: 3 additions & 0 deletions test/config/fixtures/workspace/config-empty/vitest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({})
21 changes: 21 additions & 0 deletions test/config/test/workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,24 @@ it('correctly inherits the root config', async () => {
expect(stderr).toBe('')
expect(stdout).toContain('repro.test.js > importing a virtual module')
})

it('fails if workspace is empty', async () => {
const { stderr } = await runVitest({
workspace: [],
})
expect(stderr).toContain('No projects were found. Make sure your configuration is correct. The workspace: [].')
})

it('fails if workspace is filtered by the project', async () => {
const { stderr } = await runVitest({
project: 'non-existing',
root: 'fixtures/workspace/config-empty',
config: './vitest.config.js',
workspace: [
'./vitest.config.js',
],
})
expect(stderr).toContain(`No projects were found. Make sure your configuration is correct. The filter matched no projects: /^non-existing$/i. The workspace: [
"./vitest.config.js"
].`)
})