Skip to content

Commit 5fd0e11

Browse files
committed
unit test fixes
1 parent e80ecab commit 5fd0e11

2 files changed

Lines changed: 8 additions & 15 deletions

File tree

src/mockVscode.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ afterEach(() => {
1717
delete vscode.workspace.workspaceFile;
1818
delete vscode.workspace._configuration;
1919
vscode.workspace.workspaceFolders = [] as any;
20+
vscode.workspace.findFiles = () => [] as any;
2021
vscode.context.globalState['_data'] = {};
2122
vscode.context.workspaceState['_data'] = {};
2223
});

src/util.spec.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -464,42 +464,34 @@ describe('Util', () => {
464464
});
465465

466466
function makeUri(relativePath: string) {
467-
sinon.stub(vscode.workspace, 'asRelativePath').returns(relativePath);
468467
return { fsPath: relativePath } as any;
469468
}
470469

471-
it('returns false and skips asRelativePath when there are no patterns', () => {
472-
const stub = sinon.stub(vscode.workspace, 'asRelativePath');
473-
expect(util.isUriExcluded({ fsPath: 'src/foo.ts' } as any, [])).to.be.false;
474-
expect(stub.called).to.be.false;
470+
it('returns false when there are no patterns', () => {
471+
expect(util.isUriExcluded(makeUri('src/foo.ts'), [])).to.be.false;
475472
});
476473

477474
it('returns true when the URI matches an additional pattern', () => {
478-
const uri = makeUri('node_modules/some-lib/index.js');
479-
expect(util.isUriExcluded(uri, ['**/node_modules/**'])).to.be.true;
475+
expect(util.isUriExcluded(makeUri('node_modules/some-lib/index.js'), ['**/node_modules/**'])).to.be.true;
480476
});
481477

482478
it('returns false when the URI does not match any pattern', () => {
483-
const uri = makeUri('src/foo.ts');
484-
expect(util.isUriExcluded(uri, ['**/node_modules/**'])).to.be.false;
479+
expect(util.isUriExcluded(makeUri('src/foo.ts'), ['**/node_modules/**'])).to.be.false;
485480
});
486481

487482
it('returns true when the URI matches an enabled files.exclude entry', () => {
488483
vscode.workspace._configuration['files.exclude'] = { '**/.git': true };
489-
const uri = makeUri('.git');
490-
expect(util.isUriExcluded(uri, [])).to.be.true;
484+
expect(util.isUriExcluded(makeUri('.git'), [])).to.be.true;
491485
});
492486

493487
it('returns true for a file nested inside an excluded directory', () => {
494488
vscode.workspace._configuration['files.exclude'] = { '**/.git': true };
495-
const uri = makeUri('.git/config');
496-
expect(util.isUriExcluded(uri, [])).to.be.true;
489+
expect(util.isUriExcluded(makeUri('.git/config'), [])).to.be.true;
497490
});
498491

499492
it('returns false when the URI only matches a disabled files.exclude entry', () => {
500493
vscode.workspace._configuration['files.exclude'] = { '**/node_modules/**': false };
501-
const uri = makeUri('node_modules/some-lib/index.js');
502-
expect(util.isUriExcluded(uri, [])).to.be.false;
494+
expect(util.isUriExcluded(makeUri('node_modules/some-lib/index.js'), [])).to.be.false;
503495
});
504496
});
505497
});

0 commit comments

Comments
 (0)