forked from vitest-dev/vitest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(vitest): correctly filter changed files when Vitest workspace is …
…used (vitest-dev#4693)
- Loading branch information
1 parent
c66fbed
commit 5c8ecc7
Showing
22 changed files
with
107 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
test/related/tests/not-related.test.ts → ...nged/fixtures/related/not-related.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
test/related/tests/related.test.ts → .../changed/fixtures/related/related.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "commonjs" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function getLetter() { | ||
return 'c'; | ||
} |
8 changes: 8 additions & 0 deletions
8
test/changed/fixtures/workspace/packages/packageA/index.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import getLetter from './index'; | ||
describe('getLetter', () => { | ||
const result = getLetter(); | ||
it('should return c', () => { | ||
expect(result).toBe('c'); | ||
}); | ||
}); |
3 changes: 3 additions & 0 deletions
3
test/changed/fixtures/workspace/packages/packageA/vitest.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { defineConfig } from "vitest/config"; | ||
|
||
export default defineConfig({}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function getNumber() { | ||
return 3; | ||
} |
8 changes: 8 additions & 0 deletions
8
test/changed/fixtures/workspace/packages/packageB/index.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import getNumber from './index'; | ||
describe('getNumber', () => { | ||
const result = getNumber(); | ||
it('should return 3', () => { | ||
expect(result).toBe(3); | ||
}); | ||
}); |
3 changes: 3 additions & 0 deletions
3
test/changed/fixtures/workspace/packages/packageB/vitest.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { defineConfig } from "vitest/config"; | ||
|
||
export default defineConfig({}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default [ | ||
"packages/*/vitest.config.js", | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "@vitest/test-changed", | ||
"type": "module", | ||
"private": true, | ||
"scripts": { | ||
"test": "vitest" | ||
}, | ||
"devDependencies": { | ||
"vitest": "workspace:*" | ||
} | ||
} |
29 changes: 17 additions & 12 deletions
29
test/related/tests/force-rerun.test.ts → test/changed/tests/forceRerunTrigger.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,36 @@ | ||
import { unlink, writeFile } from 'node:fs' | ||
import { join } from 'node:path' | ||
import { beforeEach, describe, expect, it } from 'vitest' | ||
|
||
import { runVitest } from '../../test-utils' | ||
|
||
async function run() { | ||
return runVitest({ | ||
include: ['tests/related.test.ts'], | ||
forceRerunTriggers: ['**/rerun.temp/**'], | ||
changed: true, | ||
}) | ||
} | ||
|
||
const fileName = 'rerun.temp' | ||
const fileName = 'fixtures/related/rerun.temp' | ||
|
||
describe('forceRerunTrigger', () => { | ||
async function run() { | ||
return runVitest({ | ||
root: join(process.cwd(), 'fixtures/related'), | ||
include: ['related.test.ts'], | ||
forceRerunTriggers: ['**/rerun.temp/**'], | ||
changed: true, | ||
}) | ||
} | ||
|
||
beforeEach(async () => { | ||
unlink(fileName, () => {}) | ||
}) | ||
|
||
it('should run the whole test suite if file exists', async () => { | ||
writeFile(fileName, '', () => {}) | ||
const { stdout } = await run() | ||
const { stdout, stderr } = await run() | ||
expect(stderr).toBe('') | ||
expect(stdout).toContain('1 passed') | ||
}, 60_000) | ||
expect(stdout).toContain('related.test.ts') | ||
expect(stdout).not.toContain('not-related.test.ts') | ||
}) | ||
|
||
it('should run no tests if file does not exist', async () => { | ||
const { stdout } = await run() | ||
expect(stdout).toContain('No test files found, exiting with code 0') | ||
}, 60_000) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { join } from 'node:path' | ||
import { expect, it } from 'vitest' | ||
|
||
import { runVitestCli } from '../../test-utils' | ||
|
||
it('related correctly runs only related tests', async () => { | ||
const { stdout, stderr } = await runVitestCli('related', join(process.cwd(), 'fixtures/related/src/sourceA.ts'), '--root', join(process.cwd(), './fixtures/related'), '--globals', '--no-watch') | ||
expect(stderr).toBe('') | ||
expect(stdout).toContain('1 passed') | ||
expect(stdout).toContain('related.test.ts') | ||
expect(stdout).not.toContain('not-related.test.ts') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { join } from 'node:path' | ||
import { expect, it } from 'vitest' | ||
|
||
import { editFile, resolvePath, runVitestCli } from '../../test-utils' | ||
|
||
it('doesn\'t run any test in a workspace because there are no changes', async () => { | ||
const { stdout } = await runVitestCli('--root', join(process.cwd(), './fixtures/workspace'), '--no-watch', '--changed') | ||
expect(stdout).toContain('No test files found, exiting with code 0') | ||
}) | ||
|
||
// Fixes #4674 | ||
it('related correctly runs only related tests inside a workspace', async () => { | ||
editFile(resolvePath(import.meta.url, '../fixtures/workspace/packages/packageA/index.js'), content => `${content}\n`) | ||
const { stdout, stderr } = await runVitestCli('--root', join(process.cwd(), './fixtures/workspace'), '--no-watch', '--changed') | ||
expect(stderr).toBe('') | ||
expect(stdout).toContain('1 passed') | ||
expect(stdout).toContain('packageA') | ||
expect(stdout).not.toContain('packageB') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.