|
1 | | -import { describe, expect, it } from 'vitest' |
| 1 | +import { afterEach, beforeEach, describe, expect, it, MockedFunction, vi } from 'vitest' |
2 | 2 | import laravel from '../src' |
| 3 | +import fs from 'fs' |
3 | 4 |
|
4 | 5 | describe('laravel-vite-plugin', () => { |
| 6 | + afterEach(() => { |
| 7 | + vi.clearAllMocks() |
| 8 | + }) |
| 9 | + |
5 | 10 | it('accepts a single input', () => { |
6 | 11 | const plugin = laravel('resources/js/app.js') |
7 | 12 |
|
@@ -128,6 +133,69 @@ describe('laravel-vite-plugin', () => { |
128 | 133 | expect(ssrConfig.build.outDir).toBe('ssr-output/test') |
129 | 134 | }) |
130 | 135 |
|
| 136 | + it('provides an @ alias by default', () => { |
| 137 | + const plugin = laravel('resources/js/app.js') |
| 138 | + |
| 139 | + const config = plugin.config({}, { command: 'build', mode: 'development' }) |
| 140 | + |
| 141 | + expect(config.resolve.alias['@']).toBe('/resources/js') |
| 142 | + }) |
| 143 | + |
| 144 | + it('respects a users existing @ alias', () => { |
| 145 | + const plugin = laravel('resources/js/app.js') |
| 146 | + |
| 147 | + const config = plugin.config({ |
| 148 | + resolve: { |
| 149 | + alias: { |
| 150 | + '@': '/somewhere/else' |
| 151 | + } |
| 152 | + } |
| 153 | + }, { command: 'build', mode: 'development' }) |
| 154 | + |
| 155 | + expect(config.resolve.alias['@']).toBe('/somewhere/else') |
| 156 | + }) |
| 157 | + |
| 158 | + it('appends an Alias object when using an alias array', () => { |
| 159 | + const plugin = laravel('resources/js/app.js') |
| 160 | + |
| 161 | + const config = plugin.config({ |
| 162 | + resolve: { |
| 163 | + alias: [ |
| 164 | + { find: '@', replacement: '/something/else' } |
| 165 | + ], |
| 166 | + } |
| 167 | + }, { command: 'build', mode: 'development' }) |
| 168 | + |
| 169 | + expect(config.resolve.alias).toEqual([ |
| 170 | + { find: '@', replacement: '/something/else' }, |
| 171 | + { find: '@', replacement: '/resources/js' }, |
| 172 | + ]) |
| 173 | + }) |
| 174 | + |
| 175 | + it('provides an ziggy alias when installed', () => { |
| 176 | + vi.spyOn(fs, 'existsSync').mockReturnValueOnce(true) |
| 177 | + |
| 178 | + const plugin = laravel('resources/js/app.js') |
| 179 | + |
| 180 | + const config = plugin.config({}, { command: 'build', mode: 'development' }) |
| 181 | + |
| 182 | + expect(config.resolve.alias['ziggy']).toBe('vendor/tightenco/ziggy/dist/index.es.js') |
| 183 | + }) |
| 184 | + |
| 185 | + it('provides an ziggy alias when installed and using an alias array', () => { |
| 186 | + vi.spyOn(fs, 'existsSync').mockReturnValueOnce(true) |
| 187 | + |
| 188 | + const plugin = laravel('resources/js/app.js') |
| 189 | + |
| 190 | + const config = plugin.config({ |
| 191 | + resolve: { |
| 192 | + alias: [], |
| 193 | + } |
| 194 | + }, { command: 'build', mode: 'development' }) |
| 195 | + |
| 196 | + expect(config.resolve.alias).toContainEqual({ find: 'ziggy', replacement: 'vendor/tightenco/ziggy/dist/index.es.js' }) |
| 197 | + }) |
| 198 | + |
131 | 199 | it('prevents empty input', () => { |
132 | 200 | /* eslint-disable-next-line @typescript-eslint/ban-ts-comment */ |
133 | 201 | /* @ts-ignore */ |
|
0 commit comments