From f27282a633b357a1d01be367b2fe55f664bc2e46 Mon Sep 17 00:00:00 2001 From: Alfonso Date: Wed, 30 Mar 2022 07:55:30 +0200 Subject: [PATCH] MOBILE-4017 testing utils: make error path agnostic and set default eol as LF in vscode settings --- .gitattributes | 2 ++ .vscode/settings.json | 1 + src/core/classes/tests/error.test.ts | 6 ++++-- src/testing/utils.ts | 11 +++++++++++ 4 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..dac53350e --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +* text=auto +*.ts eol=lf diff --git a/.vscode/settings.json b/.vscode/settings.json index 592fc58af..8c748420b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -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, diff --git a/src/core/classes/tests/error.test.ts b/src/core/classes/tests/error.test.ts index a8f90e5be..f3c4865fc 100644 --- a/src/core/classes/tests/error.test.ts +++ b/src/core/classes/tests/error.test.ts @@ -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')); }); }); diff --git a/src/testing/utils.ts b/src/testing/utils.ts index e31f69047..cd9a09696 100644 --- a/src/testing/utils.ts +++ b/src/testing/utils.ts @@ -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( return renderTemplate(component, `<${tag} ${inputAttributes}>`, 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); +}