Skip to content

Commit 7acb1a4

Browse files
committed
Fix Windows tests (paths)
1 parent 88f3d0f commit 7acb1a4

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

test/lib/lwc-bundle.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
const { expect } = require('chai');
1111
const LwcBundle = require('../../lib/lwc-bundle');
1212
const { FilesystemProvider } = require('../../lib/util/filesystem-provider');
13+
const { join } = require('path');
1314

1415
class MockFilesystemProvider extends FilesystemProvider {
1516
constructor() {
@@ -232,22 +233,22 @@ describe('LwcBundle', () => {
232233

233234
describe('lwcBundleFromFilesystem', () => {
234235
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');
235241

236242
beforeEach(() => {
237243
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']);
241247
});
242248

243249
it('should create bundle from filesystem files', () => {
244250
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);
251252

252253
expect(bundle.componentBaseName).to.equal('test');
253254
expect(bundle.js.filename).to.equal('test.js');
@@ -261,7 +262,7 @@ describe('LwcBundle', () => {
261262
it('should return null for non-existent file', () => {
262263
const bundle = LwcBundle.lwcBundleFromFilesystem(
263264
'content',
264-
'/path/to/nonexistent.js',
265+
nonexistentPath,
265266
'.js',
266267
mockFs
267268
);
@@ -270,7 +271,7 @@ describe('LwcBundle', () => {
270271

271272
it('should throw error for unsupported file extension', () => {
272273
expect(() => {
273-
LwcBundle.lwcBundleFromFilesystem('content', '/path/to/test.css', '.css', mockFs);
274+
LwcBundle.lwcBundleFromFilesystem('content', cssPath, '.css', mockFs);
274275
}).to.throw('Unsupported file extension: .css');
275276
});
276277
});

test/lib/util/filesystem-provider.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const {
1212
FilesystemProvider,
1313
DefaultFilesystemProvider
1414
} = require('../../../lib/util/filesystem-provider');
15+
const { join } = require('path');
1516

1617
describe('FilesystemProvider', () => {
1718
describe('FilesystemProvider (abstract class)', () => {
@@ -22,30 +23,38 @@ describe('FilesystemProvider', () => {
2223
});
2324

2425
it('should throw error for unimplemented existsSync', () => {
25-
expect(() => provider.existsSync('/some/path')).to.throw('Method not implemented');
26+
expect(() => provider.existsSync(join('some', 'path'))).to.throw(
27+
'Method not implemented'
28+
);
2629
});
2730

2831
it('should throw error for unimplemented readdirSync', () => {
29-
expect(() => provider.readdirSync('/some/path')).to.throw('Method not implemented');
32+
expect(() => provider.readdirSync(join('some', 'path'))).to.throw(
33+
'Method not implemented'
34+
);
3035
});
3136

3237
it('should throw error for unimplemented readFileSync', () => {
33-
expect(() => provider.readFileSync('/some/path')).to.throw('Method not implemented');
38+
expect(() => provider.readFileSync(join('some', 'path'))).to.throw(
39+
'Method not implemented'
40+
);
3441
});
3542
});
3643

3744
describe('DefaultFilesystemProvider', () => {
3845
let provider;
3946
const testDir = __dirname;
4047
const testFile = __filename;
48+
const nonexistentFile = join('nonexistent', 'file');
49+
const nonexistentDir = join('nonexistent', 'directory');
4150

4251
beforeEach(() => {
4352
provider = new DefaultFilesystemProvider();
4453
});
4554

4655
it('should check if file exists', () => {
4756
expect(provider.existsSync(testFile)).to.be.true;
48-
expect(provider.existsSync('/nonexistent/file')).to.be.false;
57+
expect(provider.existsSync(nonexistentFile)).to.be.false;
4958
});
5059

5160
it('should read directory contents', () => {
@@ -67,13 +76,13 @@ describe('FilesystemProvider', () => {
6776

6877
it('should throw error for nonexistent file read', () => {
6978
expect(() => {
70-
provider.readFileSync('/nonexistent/file');
79+
provider.readFileSync(nonexistentFile);
7180
}).to.throw();
7281
});
7382

7483
it('should throw error for nonexistent directory read', () => {
7584
expect(() => {
76-
provider.readdirSync('/nonexistent/directory');
85+
provider.readdirSync(nonexistentDir);
7786
}).to.throw();
7887
});
7988
});

0 commit comments

Comments
 (0)