Repository navigation
feat(migrate): add warnings if certain packages and config files are found #3275
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
Merged
+189
−6
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
393579c
feat(migrate): add warnings if certain packages and config files are …
KTrain5169 5376aac
Merge branch 'main' into tool-recognisers
KTrain5169 ae3f39f
feat: add detection for all config variants instead of just one
KTrain5169 3c9180b
Merge branch 'main' into tool-recognisers
KTrain5169 20bf6ac
fix: also detect dependencies declared at project root & preserve ear…
KTrain5169 e72445b
Merge branch 'main' into tool-recognisers
KTrain5169 7f3ed34
fix(migrate): update Jest migration guide URL
fengmk2 f9370a6
fix(migrate): require --full for existing project tool warnings
fengmk2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,80 @@ | ||
| import fs from 'node:fs'; | ||
| import os from 'node:os'; | ||
| import path from 'node:path'; | ||
|
|
||
| import { afterEach, beforeEach, describe, expect, it } from 'vitest'; | ||
|
|
||
| import { detectMigrationWarnings } from '../detector.ts'; | ||
|
|
||
| function writeProject(projectPath: string, packageJson: object, configFiles: string[] = []): void { | ||
| fs.mkdirSync(projectPath, { recursive: true }); | ||
| fs.writeFileSync(path.join(projectPath, 'package.json'), JSON.stringify(packageJson)); | ||
| for (const configFile of configFiles) { | ||
| fs.writeFileSync(path.join(projectPath, configFile), ''); | ||
| } | ||
| } | ||
|
|
||
| describe('detectMigrationWarnings', () => { | ||
| let tmpDir: string; | ||
|
|
||
| beforeEach(() => { | ||
| tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'vp-migration-detector-')); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| fs.rmSync(tmpDir, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| it('detects matching packages and config file variants', () => { | ||
| writeProject( | ||
| tmpDir, | ||
| { | ||
| devDependencies: { rollup: '^4.0.0', jest: '^30.0.0' }, | ||
| dependencies: { rolldown: '^1.0.0' }, | ||
| }, | ||
| ['rollup.config.mjs', 'rolldown.config.cjs', 'jest.config.json'], | ||
| ); | ||
|
|
||
| expect(detectMigrationWarnings(tmpDir)).toEqual([ | ||
| 'Rollup configuration detected. Rollup is API-compatible with Rolldown and can be migrated first before migrating further to tsdown or Vite. Once migrated to tsdown or Vite, re-run vp migrate.', | ||
| 'Rolldown configuration detected. Rolldown can be migrated to tsdown or Vite, and it is recommended to do so. Once migrated, re-run vp migrate.', | ||
| 'Jest configuration detected. Vitest is highly compatible with Jest, and so we recommend migrating. See the Vitest Jest migration guide: https://vitest.dev/guide/migration/jest, then re-run vp migrate.', | ||
| ]); | ||
| }); | ||
|
|
||
| it('does not warn when the package and config are not both present', () => { | ||
| writeProject(tmpDir, { devDependencies: { rollup: '^4.0.0' } }, ['jest.config.ts']); | ||
|
|
||
| expect(detectMigrationWarnings(tmpDir)).toEqual([]); | ||
| }); | ||
|
|
||
| it('detects Jest configuration in package.json', () => { | ||
| writeProject(tmpDir, { | ||
| devDependencies: { jest: '^30.0.0' }, | ||
| jest: { testEnvironment: 'node' }, | ||
| }); | ||
|
|
||
| expect(detectMigrationWarnings(tmpDir)).toEqual([ | ||
| 'Jest configuration detected. Vitest is highly compatible with Jest, and so we recommend migrating. See the Vitest Jest migration guide: https://vitest.dev/guide/migration/jest, then re-run vp migrate.', | ||
| ]); | ||
| }); | ||
|
|
||
| it('detects matching packages and configs in workspace packages', () => { | ||
| writeProject(path.join(tmpDir, 'packages/app'), { dependencies: { jest: '^30.0.0' } }, [ | ||
| 'jest.config.ts', | ||
| ]); | ||
|
|
||
| expect(detectMigrationWarnings(tmpDir, [{ name: 'app', path: 'packages/app' }])).toEqual([ | ||
| 'Jest configuration detected. Vitest is highly compatible with Jest, and so we recommend migrating. See the Vitest Jest migration guide: https://vitest.dev/guide/migration/jest, then re-run vp migrate.', | ||
| ]); | ||
| }); | ||
|
|
||
| it('detects workspace configs with dependencies declared at the root', () => { | ||
| writeProject(tmpDir, { devDependencies: { jest: '^30.0.0' } }); | ||
| writeProject(path.join(tmpDir, 'packages/app'), {}, ['jest.config.js']); | ||
|
|
||
| expect(detectMigrationWarnings(tmpDir, [{ name: 'app', path: 'packages/app' }])).toEqual([ | ||
| 'Jest configuration detected. Vitest is highly compatible with Jest, and so we recommend migrating. See the Vitest Jest migration guide: https://vitest.dev/guide/migration/jest, then re-run vp migrate.', | ||
| ]); | ||
| }); | ||
| }); |
This file contains hidden or 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 contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.