Skip to content

Commit

Permalink
Merge pull request ferdikoomen#1664 from krokettenkoal/bugfix/os-agno…
Browse files Browse the repository at this point in the history
…stic-tests

OS-agnostic unit tests
  • Loading branch information
ferdikoomen authored Jul 28, 2023
2 parents b3aec32 + d97edce commit a5b7233
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 19 deletions.
11 changes: 3 additions & 8 deletions src/utils/formatCode.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {EOL} from 'os';
import { formatCode } from './formatCode';

const input1 = `{ foo: true }`;
Expand All @@ -13,20 +14,14 @@ foo: true,
bar: 123
}`;

const output3 = `{
\tfoo: true,
\tbar: 123
}`;
const output3 = `{${EOL}\tfoo: true,${EOL}\tbar: 123${EOL}}`;

const input4 = `{
\t\t\t\tfoo: true,
\t\t\t\tbar: 123
}`;

const output4 = `{
\tfoo: true,
\tbar: 123
}`;
const output4 = `{${EOL}\tfoo: true,${EOL}\tbar: 123${EOL}}`;

describe('format', () => {
it('should produce correct result', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/formatCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { EOL } from 'os';

export const formatCode = (s: string): string => {
let indent: number = 0;
let lines = s.split(EOL);
let lines = s.split(/[\r\n]+/);
lines = lines.map(line => {
line = line.trim().replace(/^\*/g, ' *');
let i = indent;
Expand Down
13 changes: 7 additions & 6 deletions src/utils/writeClientCore.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { EOL } from 'os';
import { resolve } from 'path';

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

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

expect(writeFile).toBeCalledWith('/OpenAPI.ts', `settings${EOL}`);
expect(writeFile).toBeCalledWith('/ApiError.ts', `apiError${EOL}`);
expect(writeFile).toBeCalledWith('/ApiRequestOptions.ts', `apiRequestOptions${EOL}`);
expect(writeFile).toBeCalledWith('/ApiResult.ts', `apiResult${EOL}`);
expect(writeFile).toBeCalledWith('/CancelablePromise.ts', `cancelablePromise${EOL}`);
expect(writeFile).toBeCalledWith('/request.ts', `request${EOL}`);
expect(writeFile).toBeCalledWith(resolve('/', '/OpenAPI.ts'), `settings${EOL}`);
expect(writeFile).toBeCalledWith(resolve('/', '/ApiError.ts'), `apiError${EOL}`);
expect(writeFile).toBeCalledWith(resolve('/', '/ApiRequestOptions.ts'), `apiRequestOptions${EOL}`);
expect(writeFile).toBeCalledWith(resolve('/', '/ApiResult.ts'), `apiResult${EOL}`);
expect(writeFile).toBeCalledWith(resolve('/', '/CancelablePromise.ts'), `cancelablePromise${EOL}`);
expect(writeFile).toBeCalledWith(resolve('/', '/request.ts'), `request${EOL}`);
});
});
4 changes: 3 additions & 1 deletion src/utils/writeClientIndex.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { resolve } from 'path';

import type { Client } from '../client/interfaces/Client';
import { writeFile } from './fileSystem';
import type { Templates } from './registerHandlebarTemplates';
Expand Down Expand Up @@ -36,6 +38,6 @@ describe('writeClientIndex', () => {

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

expect(writeFile).toBeCalledWith('/index.ts', 'index');
expect(writeFile).toBeCalledWith(resolve('/', '/index.ts'), 'index');
});
});
3 changes: 2 additions & 1 deletion src/utils/writeClientModels.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { EOL } from 'os';
import { resolve } from 'path';

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

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

expect(writeFile).toBeCalledWith('/User.ts', `model${EOL}`);
expect(writeFile).toBeCalledWith(resolve('/', '/User.ts'), `model${EOL}`);
});
});
3 changes: 2 additions & 1 deletion src/utils/writeClientSchemas.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { EOL } from 'os';
import { resolve } from 'path';

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

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

expect(writeFile).toBeCalledWith('/$User.ts', `schema${EOL}`);
expect(writeFile).toBeCalledWith(resolve('/', '/$User.ts'), `schema${EOL}`);
});
});
3 changes: 2 additions & 1 deletion src/utils/writeClientServices.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { EOL } from 'os';
import { resolve } from 'path';

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

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

expect(writeFile).toBeCalledWith('/UserService.ts', `service${EOL}`);
expect(writeFile).toBeCalledWith(resolve('/', '/UserService.ts'), `service${EOL}`);
});
});

0 comments on commit a5b7233

Please sign in to comment.