Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 22 additions & 2 deletions napi/angular-compiler/test/plugin-fast-paths.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,16 @@ async function callPluginHook(hook: any, ...args: unknown[]) {
}

/** Run the plugin through `config`/`configResolved`/`configureServer`. */
async function setupPlugin(plugin: Plugin, command: 'serve' | 'build' = 'serve') {
async function setupPlugin(
plugin: Plugin,
command: 'serve' | 'build' = 'serve',
serverHmr?: boolean,
) {
const mockServer = createMockServer()
await callPluginHook(plugin.config, {}, { command, mode: 'development' })
// A real resolved config: preprocessCSS needs one to run Sass.
const resolved = await resolveConfig(
{ configFile: false, root: tempDir, logLevel: 'silent' },
{ configFile: false, root: tempDir, logLevel: 'silent', server: { hmr: serverHmr } },
command,
)
await callPluginHook(plugin.configResolved, resolved)
Expand Down Expand Up @@ -180,6 +184,22 @@ function preprocessCallsFor(path: string): number {
).length
}

it('omits the component update import when Vite disables HMR (e.g. Vitest)', async () => {
const plugin = getAngularPlugin({})
await setupPlugin(plugin, 'serve', false)
const { code, errors } = await transform(
plugin,
`import { Component } from '@angular/core';
@Component({ selector: 'app-root', template: 'Hello' })
export class AppComponent {}`,
join(appDir, 'app.component.ts'),
)

expect(errors).toEqual([])
expect(code).toContain('ɵɵdefineComponent')
expect(code).not.toContain('ɵɵreplaceMetadata')
})

describe('transform skips the resource URL parse when no URL is spelled', () => {
it('does not call extractComponentUrls for an inline-only component', async () => {
const plugin = getAngularPlugin()
Expand Down
3 changes: 2 additions & 1 deletion napi/angular-compiler/vite-plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,8 @@ export function angular(options: PluginOptions = {}): Plugin[] {
// modules, as those are served via HTTP middleware only. This matches
// Angular's official behavior where _enableHmr is only set for browser
// bundles (see @angular/build application-code-bundle.js).
hmr: pluginOptions.liveReload && watchMode && !isSSR,
// Vitest uses client transforms for DOM tests but disables Vite's HMR server.
hmr: pluginOptions.liveReload && watchMode && !isSSR && resolvedConfig?.server?.hmr !== false,
angularVersion: pluginOptions.angularVersion,
minifyComponentStyles: getMinifyComponentStyles(context),
emitClassMetadata: pluginOptions.emitClassMetadata,
Expand Down