Skip to content

Commit

Permalink
fix(core): use path.relative to check if two urls are the same (#69)
Browse files Browse the repository at this point in the history
* fix(core): use path.relative to check if two urls are the same to avoid differences between unix and windows path styles

* log error only when the file includes create mock but the url is different
  • Loading branch information
Pmyl authored and uittorio committed Jul 5, 2019
1 parent e03b448 commit e79b29c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/transformer/matcher/matcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ export function isFromTsAutoMock(signature: ts.Signature): boolean {
const createMockListTs: string = path.join(__dirname, `../create-mock-list.d.ts`);
const fileName: string = signature.declaration.getSourceFile().fileName;

if (fileName.indexOf('create-mock.d.ts') > -1 && fileName !== createMockTs) {
const isCreateMockUrl: boolean = path.relative(fileName, createMockTs) === '';
if (fileName.indexOf('create-mock.d.ts') > -1 && isCreateMockUrl) {
TransformerLogger().unexpectedCreateMock(fileName, createMockTs);
}

if (fileName.indexOf('create-mock-list.d.ts') > -1 && fileName !== createMockListTs) {
const isCreateMockListUrl: boolean = path.relative(fileName, createMockListTs) === '';
if (fileName.indexOf('create-mock-list.d.ts') > -1 && !isCreateMockListUrl) {
TransformerLogger().unexpectedCreateMock(fileName, createMockListTs);
}

return fileName === createMockTs || fileName === createMockListTs;
return isCreateMockUrl || isCreateMockListUrl;
}

function isDeclarationDefined(signature: ts.Signature): boolean {
Expand Down

0 comments on commit e79b29c

Please sign in to comment.