-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
172 additions
and
19 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
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 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
69 changes: 63 additions & 6 deletions
69
packages/vite/src/migrations/update-17-2-0/add-vite-plugin.spec.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,17 +1,74 @@ | ||
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; | ||
import { Tree } from '@nx/devkit'; | ||
|
||
import { | ||
readProjectConfiguration, | ||
Tree, | ||
updateProjectConfiguration, | ||
} from '@nx/devkit'; | ||
import update from './add-vite-plugin'; | ||
import { TempFs } from 'nx/src/internal-testing-utils/temp-fs'; | ||
import { UserConfig } from 'vite'; | ||
|
||
describe('add-vite-plugin migration', () => { | ||
let tree: Tree; | ||
let tempFs: TempFs; | ||
|
||
function mockViteConfig(configPath: string, config: UserConfig) { | ||
jest.mock( | ||
configPath, | ||
() => ({ | ||
default: config, | ||
}), | ||
{ | ||
virtual: true, | ||
} | ||
); | ||
} | ||
|
||
beforeEach(async () => { | ||
tempFs = new TempFs('test'); | ||
tree = createTreeWithEmptyWorkspace(); | ||
tree.root = tempFs.tempDir; | ||
await tempFs.createFiles({ | ||
'my-app/vite.config.ts': '', | ||
'my-app/project.json': '{ "name": "my-app" }', | ||
}); | ||
tree.write('my-app/vite.config.ts', `console.log('hi');`); | ||
}); | ||
|
||
beforeEach(() => { | ||
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); | ||
afterEach(() => { | ||
jest.resetModules(); | ||
tempFs.cleanup(); | ||
}); | ||
|
||
it('should run successfully', async () => { | ||
it('should remove the serve target', async () => { | ||
mockViteConfig('my-app/vite.config.ts', {}); | ||
updateProjectConfiguration(tree, 'my-app', { | ||
root: 'my-app', | ||
targets: { | ||
serve: { | ||
executor: '@nx/vite:dev-server', | ||
defaultConfiguration: 'development', | ||
options: { | ||
buildTarget: 'build', | ||
}, | ||
configurations: { | ||
development: { | ||
buildTarget: 'build:development', | ||
hmr: true, | ||
}, | ||
production: { | ||
buildTarget: 'build:production', | ||
hmr: false, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
await update(tree); | ||
// ... expect changes made | ||
|
||
expect( | ||
readProjectConfiguration(tree, 'my-app').targets.serve | ||
).toBeUndefined(); | ||
}); | ||
}); |
95 changes: 95 additions & 0 deletions
95
packages/vite/src/plugins/__snapshots__/plugin.spec.ts.snap
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 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 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