10
10
const { expect } = require ( 'chai' ) ;
11
11
const LwcBundle = require ( '../../lib/lwc-bundle' ) ;
12
12
const { FilesystemProvider } = require ( '../../lib/util/filesystem-provider' ) ;
13
+ const { join } = require ( 'path' ) ;
13
14
14
15
class MockFilesystemProvider extends FilesystemProvider {
15
16
constructor ( ) {
@@ -232,22 +233,22 @@ describe('LwcBundle', () => {
232
233
233
234
describe ( 'lwcBundleFromFilesystem' , ( ) => {
234
235
let mockFs ;
236
+ const testDir = join ( 'path' , 'to' ) ;
237
+ const testJsPath = join ( testDir , 'test.js' ) ;
238
+ const testHtmlPath = join ( testDir , 'test.html' ) ;
239
+ const nonexistentPath = join ( testDir , 'nonexistent.js' ) ;
240
+ const cssPath = join ( testDir , 'test.css' ) ;
235
241
236
242
beforeEach ( ( ) => {
237
243
mockFs = new MockFilesystemProvider ( ) ;
238
- mockFs . addFile ( '/path/to/test.js' , 'export default class Test {}' ) ;
239
- mockFs . addFile ( '/path/to/test.html' , '<template></template>' ) ;
240
- mockFs . addDirectory ( '/path/to' , [ 'test.js' , 'test.html' ] ) ;
244
+ mockFs . addFile ( testJsPath , 'export default class Test {}' ) ;
245
+ mockFs . addFile ( testHtmlPath , '<template></template>' ) ;
246
+ mockFs . addDirectory ( testDir , [ 'test.js' , 'test.html' ] ) ;
241
247
} ) ;
242
248
243
249
it ( 'should create bundle from filesystem files' , ( ) => {
244
250
const jsContent = 'export default class Test {}' ;
245
- const bundle = LwcBundle . lwcBundleFromFilesystem (
246
- jsContent ,
247
- '/path/to/test.js' ,
248
- '.js' ,
249
- mockFs
250
- ) ;
251
+ const bundle = LwcBundle . lwcBundleFromFilesystem ( jsContent , testJsPath , '.js' , mockFs ) ;
251
252
252
253
expect ( bundle . componentBaseName ) . to . equal ( 'test' ) ;
253
254
expect ( bundle . js . filename ) . to . equal ( 'test.js' ) ;
@@ -261,7 +262,7 @@ describe('LwcBundle', () => {
261
262
it ( 'should return null for non-existent file' , ( ) => {
262
263
const bundle = LwcBundle . lwcBundleFromFilesystem (
263
264
'content' ,
264
- '/path/to/nonexistent.js' ,
265
+ nonexistentPath ,
265
266
'.js' ,
266
267
mockFs
267
268
) ;
@@ -270,7 +271,7 @@ describe('LwcBundle', () => {
270
271
271
272
it ( 'should throw error for unsupported file extension' , ( ) => {
272
273
expect ( ( ) => {
273
- LwcBundle . lwcBundleFromFilesystem ( 'content' , '/path/to/test.css' , '.css' , mockFs ) ;
274
+ LwcBundle . lwcBundleFromFilesystem ( 'content' , cssPath , '.css' , mockFs ) ;
274
275
} ) . to . throw ( 'Unsupported file extension: .css' ) ;
275
276
} ) ;
276
277
} ) ;
0 commit comments