MOBILE-4017 testing utils: make error path agnostic and set default eol

as LF in vscode settings
main
Alfonso 2022-03-30 07:55:30 +02:00
parent c139683631
commit f27282a633
4 changed files with 18 additions and 2 deletions

2
.gitattributes vendored 100644
View File

@ -0,0 +1,2 @@
* text=auto
*.ts eol=lf

View File

@ -11,6 +11,7 @@
"eslint.format.enable": true,
"html.format.endWithNewline": true,
"html.format.wrapLineLength": 140,
"files.eol": "\n",
"files.trimFinalNewlines": true,
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true,

View File

@ -16,6 +16,8 @@ import Faker from 'faker';
import { CoreError } from '@classes/errors/error';
import { agnosticPath } from '@/testing/utils';
describe('CoreError', () => {
it('behaves like an error', () => {
@ -38,7 +40,7 @@ describe('CoreError', () => {
expect(error!.name).toEqual('CoreError');
expect(error!.message).toEqual(message);
expect(error!.stack).not.toBeNull();
expect(error!.stack).toContain('src/core/classes/tests/error.test.ts');
expect(error!.stack).toContain(agnosticPath('src/core/classes/tests/error.test.ts'));
});
it('can be subclassed', () => {
@ -70,7 +72,7 @@ describe('CoreError', () => {
expect(error!.name).toEqual('CustomCoreError');
expect(error!.message).toEqual(`Custom message: ${message}`);
expect(error!.stack).not.toBeNull();
expect(error!.stack).toContain('src/core/classes/tests/error.test.ts');
expect(error!.stack).toContain(agnosticPath('src/core/classes/tests/error.test.ts'));
});
});

View File

@ -16,6 +16,7 @@ import { AbstractType, Component, CUSTOM_ELEMENTS_SCHEMA, Type, ViewChild } from
import { BrowserModule } from '@angular/platform-browser';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { Observable, Subject } from 'rxjs';
import { sep } from 'path';
import { CORE_SITE_SCHEMAS } from '@services/sites';
import { CoreSingletonProxy, Network, Platform } from '@singletons';
@ -245,3 +246,13 @@ export async function renderWrapperComponent<T>(
return renderTemplate(component, `<${tag} ${inputAttributes}></${tag}>`, config);
}
/**
* Transform the provided path into a cross-platform path.
*
* @param unixPath path in unix format.
* @returns cross-platform path.
*/
export function agnosticPath(unixPath: string): string {
return unixPath.replace(/\//g, sep);
}