1- import { afterEach , beforeEach , describe , expect , it , MockedFunction , vi } from 'vitest'
1+ import { afterEach , describe , expect , it , vi } from 'vitest'
22import laravel from '../src'
33import fs from 'fs'
44
@@ -7,70 +7,69 @@ describe('laravel-vite-plugin', () => {
77 vi . clearAllMocks ( )
88 } )
99
10- it ( 'accepts a single input' , ( ) => {
11- const plugin = laravel ( 'resources/js/app.js' )
12-
13- const config = plugin . config ( { } , { command : 'build' , mode : 'development' } )
14-
10+ it ( 'provides sensible default values' , ( ) => {
11+ const plugin = laravel ( )
1512 expect ( plugin . name ) . toBe ( 'laravel' )
16- expect ( config . base ) . toBe ( '/build/' )
17- expect ( config . build ?. manifest ) . toBe ( true )
18- expect ( config . build ?. outDir ) . toBe ( 'public/build' )
19- expect ( config . build ?. rollupOptions ?. input ) . toBe ( 'resources/js/app.js' )
2013
21- const ssrConfig = plugin . config ( { build : { ssr : true } } , { command : 'build' , mode : 'development' } )
14+ const buildConfig = plugin . config ( { } , { command : 'build' , mode : 'production' } )
15+ expect ( buildConfig . base ) . toBe ( '/build/' )
16+ expect ( buildConfig . build . manifest ) . toBe ( true )
17+ expect ( buildConfig . build . outDir ) . toBe ( 'public/build' )
18+ expect ( buildConfig . build . rollupOptions . input ) . toBe ( 'resources/js/app.js' )
19+
20+ const serveConfig = plugin . config ( { } , { command : 'serve' , mode : 'development' } )
21+ expect ( serveConfig . base ) . toBe ( '' )
2222
23+ const ssrConfig = plugin . config ( { build : { ssr : true } } , { command : 'build' , mode : 'production' } )
2324 expect ( ssrConfig . base ) . toBe ( '/build/' )
24- expect ( ssrConfig . build ?. manifest ) . toBe ( false )
25- expect ( ssrConfig . build ?. outDir ) . toBe ( 'storage/ssr' )
26- expect ( ssrConfig . build ?. rollupOptions ?. input ) . toBe ( 'resources/js/app.js' )
25+ expect ( ssrConfig . build . manifest ) . toBe ( false )
26+ expect ( ssrConfig . build . outDir ) . toBe ( 'storage/ssr' )
27+ expect ( ssrConfig . build . rollupOptions . input ) . toBe ( 'resources/js/ssr.js' )
28+ } )
29+
30+ it ( 'accepts a single input' , ( ) => {
31+ const plugin = laravel ( 'resources/js/app.ts' )
32+
33+ const config = plugin . config ( { } , { command : 'build' , mode : 'production' } )
34+ expect ( config . build . rollupOptions . input ) . toBe ( 'resources/js/app.ts' )
35+
36+ const ssrConfig = plugin . config ( { build : { ssr : true } } , { command : 'build' , mode : 'production' } )
37+ expect ( ssrConfig . build . rollupOptions . input ) . toBe ( 'resources/js/app.ts' )
2738 } )
2839
2940 it ( 'accepts an array of inputs' , ( ) => {
3041 const plugin = laravel ( [
31- 'resources/js/app.js ' ,
42+ 'resources/js/app.ts ' ,
3243 'resources/js/other.js' ,
3344 ] )
3445
35- const config = plugin . config ( { } , { command : 'build' , mode : 'development' } )
46+ const config = plugin . config ( { } , { command : 'build' , mode : 'production' } )
47+ expect ( config . build . rollupOptions . input ) . toEqual ( [ 'resources/js/app.ts' , 'resources/js/other.js' ] )
3648
37- expect ( plugin . name ) . toBe ( 'laravel' )
38- expect ( config . base ) . toBe ( '/build/' )
39- expect ( config . build ?. manifest ) . toBe ( true )
40- expect ( config . build ?. outDir ) . toBe ( 'public/build' )
41- expect ( config . build ?. rollupOptions ?. input ) . toEqual ( [ 'resources/js/app.js' , 'resources/js/other.js' ] )
42-
43- const ssrConfig = plugin . config ( { build : { ssr : true } } , { command : 'build' , mode : 'development' } )
44-
45- expect ( ssrConfig . base ) . toBe ( '/build/' )
46- expect ( ssrConfig . build ?. manifest ) . toBe ( false )
47- expect ( ssrConfig . build ?. outDir ) . toBe ( 'storage/ssr' )
48- expect ( ssrConfig . build ?. rollupOptions ?. input ) . toEqual ( [ 'resources/js/app.js' , 'resources/js/other.js' ] )
49+ const ssrConfig = plugin . config ( { build : { ssr : true } } , { command : 'build' , mode : 'production' } )
50+ expect ( ssrConfig . build . rollupOptions . input ) . toEqual ( [ 'resources/js/app.ts' , 'resources/js/other.js' ] )
4951 } )
5052
5153 it ( 'accepts a full configuration' , ( ) => {
5254 const plugin = laravel ( {
53- input : 'resources/js/app.js ' ,
55+ input : 'resources/js/app.ts ' ,
5456 publicDirectory : 'other-public' ,
5557 buildDirectory : 'other-build' ,
56- ssr : 'resources/js/ssr.js ' ,
58+ ssr : 'resources/js/ssr.ts ' ,
5759 ssrOutputDirectory : 'other-ssr-output' ,
5860 } )
5961
60- const config = plugin . config ( { } , { command : 'build' , mode : 'development' } )
61-
62- expect ( plugin . name ) . toBe ( 'laravel' )
62+ const config = plugin . config ( { } , { command : 'build' , mode : 'production' } )
6363 expect ( config . base ) . toBe ( '/other-build/' )
64- expect ( config . build ?. manifest ) . toBe ( true )
65- expect ( config . build ?. outDir ) . toBe ( 'other-public/other-build' )
66- expect ( config . build ?. rollupOptions ?. input ) . toBe ( 'resources/js/app.js' )
67-
68- const ssrConfig = plugin . config ( { build : { ssr : true } } , { command : 'build' , mode : 'development' } )
64+ expect ( config . build . manifest ) . toBe ( true )
65+ expect ( config . build . outDir ) . toBe ( 'other-public/other-build' )
66+ expect ( config . build . rollupOptions . input ) . toBe ( 'resources/js/app.ts' )
6967
68+ const ssrConfig = plugin . config ( { build : { ssr : true } } , { command : 'build' , mode : 'production' } )
7069 expect ( ssrConfig . base ) . toBe ( '/other-build/' )
71- expect ( ssrConfig . build ? .manifest ) . toBe ( false )
72- expect ( ssrConfig . build ? .outDir ) . toBe ( 'other-ssr-output' )
73- expect ( ssrConfig . build ? .rollupOptions ? .input ) . toBe ( 'resources/js/ssr.js ' )
70+ expect ( ssrConfig . build . manifest ) . toBe ( false )
71+ expect ( ssrConfig . build . outDir ) . toBe ( 'other-ssr-output' )
72+ expect ( ssrConfig . build . rollupOptions . input ) . toBe ( 'resources/js/ssr.ts ' )
7473 } )
7574
7675 it ( 'accepts a partial configuration' , ( ) => {
@@ -79,28 +78,24 @@ describe('laravel-vite-plugin', () => {
7978 ssr : 'resources/js/ssr.js' ,
8079 } )
8180
82- const config = plugin . config ( { } , { command : 'build' , mode : 'development' } )
83-
84- expect ( plugin . name ) . toBe ( 'laravel' )
81+ const config = plugin . config ( { } , { command : 'build' , mode : 'production' } )
8582 expect ( config . base ) . toBe ( '/build/' )
86- expect ( config . build ?. manifest ) . toBe ( true )
87- expect ( config . build ?. outDir ) . toBe ( 'public/build' )
88- expect ( config . build ?. rollupOptions ?. input ) . toBe ( 'resources/js/app.js' )
89-
90- const ssrConfig = plugin . config ( { build : { ssr : true } } , { command : 'build' , mode : 'development' } )
83+ expect ( config . build . manifest ) . toBe ( true )
84+ expect ( config . build . outDir ) . toBe ( 'public/build' )
85+ expect ( config . build . rollupOptions . input ) . toBe ( 'resources/js/app.js' )
9186
87+ const ssrConfig = plugin . config ( { build : { ssr : true } } , { command : 'build' , mode : 'production' } )
9288 expect ( ssrConfig . base ) . toBe ( '/build/' )
93- expect ( ssrConfig . build ? .manifest ) . toBe ( false )
94- expect ( ssrConfig . build ? .outDir ) . toBe ( 'storage/ssr' )
95- expect ( ssrConfig . build ? .rollupOptions ? .input ) . toBe ( 'resources/js/ssr.js' )
89+ expect ( ssrConfig . build . manifest ) . toBe ( false )
90+ expect ( ssrConfig . build . outDir ) . toBe ( 'storage/ssr' )
91+ expect ( ssrConfig . build . rollupOptions . input ) . toBe ( 'resources/js/ssr.js' )
9692 } )
9793
9894 it ( 'prefixes the base with ASSET_URL' , ( ) => {
9995 process . env . ASSET_URL = 'http://example.com'
10096 const plugin = laravel ( 'resources/js/app.js' )
10197
102- const config = plugin . config ( { } , { command : 'build' , mode : 'development' } )
103-
98+ const config = plugin . config ( { } , { command : 'build' , mode : 'production' } )
10499 expect ( config . base ) . toBe ( 'http://example.com/build/' )
105100
106101 delete process . env . ASSET_URL
@@ -123,13 +118,11 @@ describe('laravel-vite-plugin', () => {
123118 ssrOutputDirectory : '/ssr-output/test/' ,
124119 } )
125120
126- const config = plugin . config ( { } , { command : 'build' , mode : 'development' } )
127-
121+ const config = plugin . config ( { } , { command : 'build' , mode : 'production' } )
128122 expect ( config . base ) . toBe ( '/build/test/' )
129123 expect ( config . build . outDir ) . toBe ( 'public/test/build/test' )
130124
131- const ssrConfig = plugin . config ( { build : { ssr : true } } , { command : 'build' , mode : 'development' } )
132-
125+ const ssrConfig = plugin . config ( { build : { ssr : true } } , { command : 'build' , mode : 'production' } )
133126 expect ( ssrConfig . build . outDir ) . toBe ( 'ssr-output/test' )
134127 } )
135128
@@ -195,11 +188,4 @@ describe('laravel-vite-plugin', () => {
195188
196189 expect ( config . resolve . alias ) . toContainEqual ( { find : 'ziggy' , replacement : 'vendor/tightenco/ziggy/dist/index.es.js' } )
197190 } )
198-
199- it ( 'prevents empty input' , ( ) => {
200- /* eslint-disable-next-line @typescript-eslint/ban-ts-comment */
201- /* @ts -ignore */
202- expect ( ( ) => laravel ( ) )
203- . toThrowError ( 'Laravel plugin requires configuration.' )
204- } )
205191} )
0 commit comments