99
1010'use strict' ;
1111
12- import { describe , it , expect } from 'vitest' ;
12+ import { describe , it , expect , vi } from 'vitest' ;
1313const WebpackConfig = require ( '../../lib/WebpackConfig' ) ;
1414const RuntimeConfig = require ( '../../lib/config/RuntimeConfig' ) ;
1515const sassLoader = require ( '../../lib/loaders/sass' ) ;
1616const cssLoader = require ( '../../lib/loaders/css' ) ;
17- const sinon = require ( 'sinon' ) ;
1817
1918function createConfig ( ) {
2019 const runtimeConfig = new RuntimeConfig ( ) ;
@@ -30,8 +29,8 @@ describe('loaders/sass', () => {
3029 config . enableSourceMaps ( true ) ;
3130
3231 // make the cssLoader return nothing
33- const cssLoaderStub = sinon . stub ( cssLoader , 'getLoaders' )
34- . callsFake ( ( ) => [ ] ) ;
32+ const cssLoaderStub = vi . spyOn ( cssLoader , 'getLoaders' )
33+ . mockImplementation ( ( ) => [ ] ) ;
3534
3635 const actualLoaders = sassLoader . getLoaders ( config ) ;
3736 expect ( actualLoaders ) . to . have . lengthOf ( 2 ) ;
@@ -40,18 +39,18 @@ describe('loaders/sass', () => {
4039
4140 expect ( actualLoaders [ 1 ] . loader ) . to . contain ( 'sass-loader' ) ;
4241 expect ( actualLoaders [ 1 ] . options . sourceMap ) . to . be . true ;
43- expect ( cssLoaderStub . getCall ( 0 ) . args [ 1 ] ) . to . be . false ;
42+ expect ( cssLoaderStub . mock . calls [ 0 ] [ 1 ] ) . to . be . false ;
4443
45- cssLoader . getLoaders . restore ( ) ;
44+ cssLoaderStub . mockRestore ( ) ;
4645 } ) ;
4746
4847 it ( 'getLoaders() with resolve-url-loader but not sourcemaps' , ( ) => {
4948 const config = createConfig ( ) ;
5049 config . enableSourceMaps ( false ) ;
5150
5251 // make the cssLoader return nothing
53- sinon . stub ( cssLoader , 'getLoaders' )
54- . callsFake ( ( ) => [ ] ) ;
52+ const cssLoaderStub = vi . spyOn ( cssLoader , 'getLoaders' )
53+ . mockImplementation ( ( ) => [ ] ) ;
5554
5655 const actualLoaders = sassLoader . getLoaders ( config ) ;
5756 expect ( actualLoaders ) . to . have . lengthOf ( 2 ) ;
@@ -62,7 +61,7 @@ describe('loaders/sass', () => {
6261 // sourcemaps always enabled when resolve-url-loader is enabled
6362 expect ( actualLoaders [ 1 ] . options . sourceMap ) . to . be . true ;
6463
65- cssLoader . getLoaders . restore ( ) ;
64+ cssLoaderStub . mockRestore ( ) ;
6665 } ) ;
6766
6867 it ( 'getLoaders() with resolve-url-loader options' , ( ) => {
@@ -74,15 +73,15 @@ describe('loaders/sass', () => {
7473 } ) ;
7574
7675 // make the cssLoader return nothing
77- sinon . stub ( cssLoader , 'getLoaders' )
78- . callsFake ( ( ) => [ ] ) ;
76+ const cssLoaderStub = vi . spyOn ( cssLoader , 'getLoaders' )
77+ . mockImplementation ( ( ) => [ ] ) ;
7978
8079 const actualLoaders = sassLoader . getLoaders ( config ) ;
8180 expect ( actualLoaders ) . to . have . lengthOf ( 2 ) ;
8281 expect ( actualLoaders [ 0 ] . loader ) . to . contain ( 'resolve-url-loader' ) ;
8382 expect ( actualLoaders [ 0 ] . options . removeCR ) . to . be . true ;
8483
85- cssLoader . getLoaders . restore ( ) ;
84+ cssLoaderStub . mockRestore ( ) ;
8685 } ) ;
8786
8887 it ( 'getLoaders() without resolve-url-loader' , ( ) => {
@@ -93,23 +92,23 @@ describe('loaders/sass', () => {
9392 config . enableSourceMaps ( false ) ;
9493
9594 // make the cssLoader return nothing
96- sinon . stub ( cssLoader , 'getLoaders' )
97- . callsFake ( ( ) => [ ] ) ;
95+ const cssLoaderStub = vi . spyOn ( cssLoader , 'getLoaders' )
96+ . mockImplementation ( ( ) => [ ] ) ;
9897
9998 const actualLoaders = sassLoader . getLoaders ( config ) ;
10099 expect ( actualLoaders ) . to . have . lengthOf ( 1 ) ;
101100 expect ( actualLoaders [ 0 ] . loader ) . to . contain ( 'sass-loader' ) ;
102101 expect ( actualLoaders [ 0 ] . options . sourceMap ) . to . be . false ;
103102
104- cssLoader . getLoaders . restore ( ) ;
103+ cssLoaderStub . mockRestore ( ) ;
105104 } ) ;
106105
107106 it ( 'getLoaders() with options callback' , ( ) => {
108107 const config = createConfig ( ) ;
109108
110109 // make the cssLoader return nothing
111- sinon . stub ( cssLoader , 'getLoaders' )
112- . callsFake ( ( ) => [ ] ) ;
110+ const cssLoaderStub = vi . spyOn ( cssLoader , 'getLoaders' )
111+ . mockImplementation ( ( ) => [ ] ) ;
113112
114113 config . enableSassLoader ( function ( options ) {
115114 options . sassOptions . custom_option = 'baz' ;
@@ -126,15 +125,15 @@ describe('loaders/sass', () => {
126125 other_option : true
127126 }
128127 } ) ;
129- cssLoader . getLoaders . restore ( ) ;
128+ cssLoaderStub . mockRestore ( ) ;
130129 } ) ;
131130
132131 it ( 'getLoaders() with a callback that returns an object' , ( ) => {
133132 const config = createConfig ( ) ;
134133
135134 // make the cssLoader return nothing
136- sinon . stub ( cssLoader , 'getLoaders' )
137- . callsFake ( ( ) => [ ] ) ;
135+ const cssLoaderStub = vi . spyOn ( cssLoader , 'getLoaders' )
136+ . mockImplementation ( ( ) => [ ] ) ;
138137
139138 config . enableSassLoader ( function ( options ) {
140139 options . custom_option = 'baz' ;
@@ -147,16 +146,16 @@ describe('loaders/sass', () => {
147146 const actualLoaders = sassLoader . getLoaders ( config ) ;
148147 expect ( actualLoaders [ 1 ] . options ) . to . deep . equals ( { foo : true } ) ;
149148
150- cssLoader . getLoaders . restore ( ) ;
149+ cssLoaderStub . mockRestore ( ) ;
151150 } ) ;
152151
153152 it ( 'getLoaders() with CSS modules enabled' , ( ) => {
154153 const config = createConfig ( ) ;
155154 config . enableSourceMaps ( true ) ;
156155
157156 // make the cssLoader return nothing
158- const cssLoaderStub = sinon . stub ( cssLoader , 'getLoaders' )
159- . callsFake ( ( ) => [ ] ) ;
157+ const cssLoaderStub = vi . spyOn ( cssLoader , 'getLoaders' )
158+ . mockImplementation ( ( ) => [ ] ) ;
160159
161160 const actualLoaders = sassLoader . getLoaders ( config , true ) ;
162161 expect ( actualLoaders ) . to . have . lengthOf ( 2 ) ;
@@ -165,8 +164,8 @@ describe('loaders/sass', () => {
165164
166165 expect ( actualLoaders [ 1 ] . loader ) . to . contain ( 'sass-loader' ) ;
167166 expect ( actualLoaders [ 1 ] . options . sourceMap ) . to . be . true ;
168- expect ( cssLoaderStub . getCall ( 0 ) . args [ 1 ] ) . to . be . true ;
167+ expect ( cssLoaderStub . mock . calls [ 0 ] [ 1 ] ) . to . be . true ;
169168
170- cssLoader . getLoaders . restore ( ) ;
169+ cssLoaderStub . mockRestore ( ) ;
171170 } ) ;
172171} ) ;
0 commit comments