Skip to content

Commit a5b7233

Browse files
authored
Merge pull request ferdikoomen#1664 from krokettenkoal/bugfix/os-agnostic-tests
OS-agnostic unit tests
2 parents b3aec32 + d97edce commit a5b7233

7 files changed

+20
-19
lines changed

src/utils/formatCode.spec.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {EOL} from 'os';
12
import { formatCode } from './formatCode';
23

34
const input1 = `{ foo: true }`;
@@ -13,20 +14,14 @@ foo: true,
1314
bar: 123
1415
}`;
1516

16-
const output3 = `{
17-
\tfoo: true,
18-
\tbar: 123
19-
}`;
17+
const output3 = `{${EOL}\tfoo: true,${EOL}\tbar: 123${EOL}}`;
2018

2119
const input4 = `{
2220
\t\t\t\tfoo: true,
2321
\t\t\t\tbar: 123
2422
}`;
2523

26-
const output4 = `{
27-
\tfoo: true,
28-
\tbar: 123
29-
}`;
24+
const output4 = `{${EOL}\tfoo: true,${EOL}\tbar: 123${EOL}}`;
3025

3126
describe('format', () => {
3227
it('should produce correct result', () => {

src/utils/formatCode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { EOL } from 'os';
22

33
export const formatCode = (s: string): string => {
44
let indent: number = 0;
5-
let lines = s.split(EOL);
5+
let lines = s.split(/[\r\n]+/);
66
lines = lines.map(line => {
77
line = line.trim().replace(/^\*/g, ' *');
88
let i = indent;

src/utils/writeClientCore.spec.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { EOL } from 'os';
2+
import { resolve } from 'path';
23

34
import type { Client } from '../client/interfaces/Client';
45
import { HttpClient } from '../HttpClient';
@@ -40,11 +41,11 @@ describe('writeClientCore', () => {
4041

4142
await writeClientCore(client, templates, '/', HttpClient.FETCH, Indent.SPACE_4);
4243

43-
expect(writeFile).toBeCalledWith('/OpenAPI.ts', `settings${EOL}`);
44-
expect(writeFile).toBeCalledWith('/ApiError.ts', `apiError${EOL}`);
45-
expect(writeFile).toBeCalledWith('/ApiRequestOptions.ts', `apiRequestOptions${EOL}`);
46-
expect(writeFile).toBeCalledWith('/ApiResult.ts', `apiResult${EOL}`);
47-
expect(writeFile).toBeCalledWith('/CancelablePromise.ts', `cancelablePromise${EOL}`);
48-
expect(writeFile).toBeCalledWith('/request.ts', `request${EOL}`);
44+
expect(writeFile).toBeCalledWith(resolve('/', '/OpenAPI.ts'), `settings${EOL}`);
45+
expect(writeFile).toBeCalledWith(resolve('/', '/ApiError.ts'), `apiError${EOL}`);
46+
expect(writeFile).toBeCalledWith(resolve('/', '/ApiRequestOptions.ts'), `apiRequestOptions${EOL}`);
47+
expect(writeFile).toBeCalledWith(resolve('/', '/ApiResult.ts'), `apiResult${EOL}`);
48+
expect(writeFile).toBeCalledWith(resolve('/', '/CancelablePromise.ts'), `cancelablePromise${EOL}`);
49+
expect(writeFile).toBeCalledWith(resolve('/', '/request.ts'), `request${EOL}`);
4950
});
5051
});

src/utils/writeClientIndex.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { resolve } from 'path';
2+
13
import type { Client } from '../client/interfaces/Client';
24
import { writeFile } from './fileSystem';
35
import type { Templates } from './registerHandlebarTemplates';
@@ -36,6 +38,6 @@ describe('writeClientIndex', () => {
3638

3739
await writeClientIndex(client, templates, '/', true, true, true, true, true, 'Service', '');
3840

39-
expect(writeFile).toBeCalledWith('/index.ts', 'index');
41+
expect(writeFile).toBeCalledWith(resolve('/', '/index.ts'), 'index');
4042
});
4143
});

src/utils/writeClientModels.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { EOL } from 'os';
2+
import { resolve } from 'path';
23

34
import type { Model } from '../client/interfaces/Model';
45
import { HttpClient } from '../HttpClient';
@@ -53,6 +54,6 @@ describe('writeClientModels', () => {
5354

5455
await writeClientModels(models, templates, '/', HttpClient.FETCH, false, Indent.SPACE_4);
5556

56-
expect(writeFile).toBeCalledWith('/User.ts', `model${EOL}`);
57+
expect(writeFile).toBeCalledWith(resolve('/', '/User.ts'), `model${EOL}`);
5758
});
5859
});

src/utils/writeClientSchemas.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { EOL } from 'os';
2+
import { resolve } from 'path';
23

34
import type { Model } from '../client/interfaces/Model';
45
import { HttpClient } from '../HttpClient';
@@ -53,6 +54,6 @@ describe('writeClientSchemas', () => {
5354

5455
await writeClientSchemas(models, templates, '/', HttpClient.FETCH, false, Indent.SPACE_4);
5556

56-
expect(writeFile).toBeCalledWith('/$User.ts', `schema${EOL}`);
57+
expect(writeFile).toBeCalledWith(resolve('/', '/$User.ts'), `schema${EOL}`);
5758
});
5859
});

src/utils/writeClientServices.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { EOL } from 'os';
2+
import { resolve } from 'path';
23

34
import type { Service } from '../client/interfaces/Service';
45
import { HttpClient } from '../HttpClient';
@@ -41,6 +42,6 @@ describe('writeClientServices', () => {
4142

4243
await writeClientServices(services, templates, '/', HttpClient.FETCH, false, false, Indent.SPACE_4, 'Service');
4344

44-
expect(writeFile).toBeCalledWith('/UserService.ts', `service${EOL}`);
45+
expect(writeFile).toBeCalledWith(resolve('/', '/UserService.ts'), `service${EOL}`);
4546
});
4647
});

0 commit comments

Comments
 (0)