Skip to content

Commit f27282a

Browse files
committedMar 31, 2022
MOBILE-4017 testing utils: make error path agnostic and set default eol
as LF in vscode settings
1 parent c139683 commit f27282a

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed
 

‎.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* text=auto
2+
*.ts eol=lf

‎.vscode/settings.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"eslint.format.enable": true,
1212
"html.format.endWithNewline": true,
1313
"html.format.wrapLineLength": 140,
14+
"files.eol": "\n",
1415
"files.trimFinalNewlines": true,
1516
"files.insertFinalNewline": true,
1617
"files.trimTrailingWhitespace": true,

‎src/core/classes/tests/error.test.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import Faker from 'faker';
1616

1717
import { CoreError } from '@classes/errors/error';
1818

19+
import { agnosticPath } from '@/testing/utils';
20+
1921
describe('CoreError', () => {
2022

2123
it('behaves like an error', () => {
@@ -38,7 +40,7 @@ describe('CoreError', () => {
3840
expect(error!.name).toEqual('CoreError');
3941
expect(error!.message).toEqual(message);
4042
expect(error!.stack).not.toBeNull();
41-
expect(error!.stack).toContain('src/core/classes/tests/error.test.ts');
43+
expect(error!.stack).toContain(agnosticPath('src/core/classes/tests/error.test.ts'));
4244
});
4345

4446
it('can be subclassed', () => {
@@ -70,7 +72,7 @@ describe('CoreError', () => {
7072
expect(error!.name).toEqual('CustomCoreError');
7173
expect(error!.message).toEqual(`Custom message: ${message}`);
7274
expect(error!.stack).not.toBeNull();
73-
expect(error!.stack).toContain('src/core/classes/tests/error.test.ts');
75+
expect(error!.stack).toContain(agnosticPath('src/core/classes/tests/error.test.ts'));
7476
});
7577

7678
});

‎src/testing/utils.ts

+11
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { AbstractType, Component, CUSTOM_ELEMENTS_SCHEMA, Type, ViewChild } from
1616
import { BrowserModule } from '@angular/platform-browser';
1717
import { ComponentFixture, TestBed } from '@angular/core/testing';
1818
import { Observable, Subject } from 'rxjs';
19+
import { sep } from 'path';
1920

2021
import { CORE_SITE_SCHEMAS } from '@services/sites';
2122
import { CoreSingletonProxy, Network, Platform } from '@singletons';
@@ -245,3 +246,13 @@ export async function renderWrapperComponent<T>(
245246

246247
return renderTemplate(component, `<${tag} ${inputAttributes}></${tag}>`, config);
247248
}
249+
250+
/**
251+
* Transform the provided path into a cross-platform path.
252+
*
253+
* @param unixPath path in unix format.
254+
* @returns cross-platform path.
255+
*/
256+
export function agnosticPath(unixPath: string): string {
257+
return unixPath.replace(/\//g, sep);
258+
}

0 commit comments

Comments
 (0)
Please sign in to comment.