1- import { describe , expect , it , vi } from 'vitest' ;
1+ import { describe , expect , it } from 'vitest' ;
22import * as path from 'path' ;
3- import { build , BuildOptions , PluginBuild } from 'esbuild' ;
3+ import { build , BuildOptions } from 'esbuild' ;
44import { lessLoader , LoaderOptions } from '../src/index' ;
55
66const entryPoints = [
77 path . resolve ( __dirname , '../' , 'example' , 'index.ts' ) ,
88 path . resolve ( __dirname , '../' , 'example' , 'index-custom-filter.ts' ) ,
99 path . resolve ( __dirname , '../' , 'example' , 'index.less' ) ,
10+ path . resolve ( __dirname , '../' , 'example' , 'test.module.ts' ) ,
1011] ;
1112
1213const commonOptions : BuildOptions = {
@@ -21,20 +22,29 @@ const commonOptions: BuildOptions = {
2122 } ,
2223} ;
2324
24- const buildLess = async ( {
25+ type BuildLessProps = {
26+ lessOptions ?: Less . Options ;
27+ loaderOptions ?: LoaderOptions ;
28+ entryPoint ?: string ;
29+ buildOptions ?: BuildOptions ;
30+ } ;
31+
32+ async function buildLess ( {
2533 lessOptions,
2634 loaderOptions,
2735 entryPoint = entryPoints [ 0 ] ,
28- } : { lessOptions ?: Less . Options ; loaderOptions ?: LoaderOptions ; entryPoint ?: string } = { } ) => {
36+ buildOptions : _buildOptions = { } ,
37+ } : BuildLessProps = { } ) {
2938 const buildOptions : BuildOptions = {
3039 ...commonOptions ,
3140 entryPoints : [ entryPoint ] ,
3241 plugins : [ lessLoader ( lessOptions , loaderOptions ) ] ,
42+ ..._buildOptions ,
3343 } ;
3444
3545 const { outputFiles } = await build ( buildOptions ) ;
3646 return outputFiles ;
37- } ;
47+ }
3848
3949describe ( 'less-loader' , ( ) => {
4050 it ( 'exported module' , ( ) => {
@@ -137,4 +147,18 @@ describe('less-loader', () => {
137147 } ) ,
138148 ) . rejects . toThrow ( ) ;
139149 } ) ;
150+
151+ it ( 'works with module.less' , async ( ) => {
152+ const result = await buildLess ( {
153+ entryPoint : entryPoints [ 3 ] ,
154+ buildOptions : {
155+ format : 'iife' ,
156+ } ,
157+ } ) ;
158+
159+ expect ( result ! . length ) . toEqual ( 2 ) ;
160+
161+ // Result has compiled .less
162+ expect ( result ! [ 1 ] . text ) . toMatchSnapshot ( ) ;
163+ } ) ;
140164} ) ;
0 commit comments