Skip to content

Commit

Permalink
Merge pull request #16 from def-studio/feat-blade-components-classes-…
Browse files Browse the repository at this point in the history
…watch

[Feat] Blade components classes watch
  • Loading branch information
fabio-ivona authored Aug 4, 2022
2 parents f8e160c + ce797ab commit a16bc47
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ interface LivewirePlugin extends Plugin {
export const defaultWatches: string[] = [
'**/resources/views/**/*.blade.php',
'**/app/**/Livewire/**/*.php',
'**/app/**/Filament/**/*.php'
'**/app/**/Filament/**/*.php',
'app/View/Components/**',
];

export const defaultConfig: PluginConfig = {
Expand Down
26 changes: 17 additions & 9 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
// noinspection JSUnusedLocalSymbols

import {afterEach, describe, expect, it, vi} from "vitest";
import livewire, {defaultWatches} from "../src";
import {HmrContext, HMRPayload, ViteDevServer} from "vite";
Expand All @@ -11,6 +14,7 @@ function fakeContext(file = ''): HmrContext {
},
server: {
ws: {

send: (payload: HMRPayload) => {
//.. do nothing
}
Expand All @@ -36,6 +40,7 @@ describe('configuration parse', () => {
'**/resources/views/**/*.blade.php',
'**/app/**/Livewire/**/*.php',
'**/app/**/Filament/**/*.php',
'app/View/Components/**',
]);
});

Expand Down Expand Up @@ -64,6 +69,7 @@ describe('configuration parse', () => {
'**/resources/views/**/*.blade.php',
'**/app/**/Livewire/**/*.php',
'**/app/**/Filament/**/*.php',
'app/View/Components/**',
]);
});

Expand Down Expand Up @@ -92,6 +98,7 @@ describe('configuration parse', () => {
'**/resources/views/**/*.blade.php',
'**/app/**/Livewire/**/*.php',
'**/app/**/Filament/**/*.php',
'app/View/Components/**',
]);
});

Expand All @@ -104,6 +111,7 @@ describe('configuration parse', () => {
'**/resources/views/**/*.blade.php',
'**/app/**/Livewire/**/*.php',
'**/app/**/Filament/**/*.php',
'app/View/Components/**',
]);
});
});
Expand All @@ -116,7 +124,7 @@ describe('hot update handling', () => {
it("should not trigger hot update if file doesn't match any pattern", function () {
const plugin = livewire();

plugin.handleHotUpdate(fakeContext());
plugin.handleHotUpdate?.(fakeContext());
});

it("should trigger hot update if file matches default class pattern", function () {
Expand All @@ -125,7 +133,7 @@ describe('hot update handling', () => {
const context = fakeContext('/var/www/app/Html/Livewire/Test.php');
const spy = vi.spyOn(context.server.ws, 'send');

plugin.handleHotUpdate(context);
plugin.handleHotUpdate?.(context);

expect(spy).toHaveBeenCalledWith({
type: 'custom',
Expand All @@ -142,11 +150,11 @@ describe('hot update handling', () => {
const context = fakeContext('/var/www/app/Html/Livewire/Test.php');
const spy = vi.spyOn(context.server.ws, 'send');

plugin.handleHotUpdate(context);
plugin.handleHotUpdate?.(context);
expect(spy).toHaveBeenCalledTimes(0);

context.file = 'var/www/app/modules/invoices/views/livewire/test.blade.php';
plugin.handleHotUpdate(context);
plugin.handleHotUpdate?.(context);
expect(spy).toHaveBeenCalledTimes(1);
});

Expand All @@ -161,15 +169,15 @@ describe('hot update handling', () => {
const context = fakeContext('/var/www/app/Html/Livewire/Test.php');
const spy = vi.spyOn(context.server.ws, 'send');

plugin.handleHotUpdate(context);
plugin.handleHotUpdate?.(context);
expect(spy).toHaveBeenCalledWith({
type: 'custom',
event: 'livewire-update',
data: {blade_updated: false},
});

context.file = 'var/www/app/modules/invoices/views/livewire/test.blade.php';
plugin.handleHotUpdate(context);
plugin.handleHotUpdate?.(context);
expect(spy).toHaveBeenCalledTimes(2);
expect(spy).toHaveBeenLastCalledWith({
type: 'custom',
Expand All @@ -184,7 +192,7 @@ describe('hot update handling', () => {
const context = fakeContext('/var/www/resources/views/test.blade.php');
const spy = vi.spyOn(context.server.ws, 'send');

plugin.handleHotUpdate(context);
plugin.handleHotUpdate?.(context);

expect(spy).toHaveBeenCalledTimes(1);
});
Expand All @@ -197,7 +205,7 @@ describe('hot update handling', () => {
const context = fakeContext('/var/www/resources/components/test.blade.php');
const spy = vi.spyOn(context.server.ws, 'send');

plugin.handleHotUpdate(context);
plugin.handleHotUpdate?.(context);

expect(spy).toHaveBeenCalledTimes(0);
});
Expand All @@ -212,7 +220,7 @@ describe('hot update handling', () => {

const time = freezeTime();

plugin.handleHotUpdate(context);
plugin.handleHotUpdate?.(context);

expect(spy).toHaveBeenCalledTimes(2);

Expand Down

0 comments on commit a16bc47

Please sign in to comment.