Skip to content

Commit 35e6429

Browse files
committed
Do not run parse test on windows
1 parent b381e1d commit 35e6429

File tree

2 files changed

+101
-87
lines changed

2 files changed

+101
-87
lines changed

__tests__/newVsOld.test.ts

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,52 +7,58 @@ import {isNull} from 'lodash';
77

88
const des = process.platform === 'win32' ? describe.skip : describe;
99

10-
des('Compare perivous schema gen to new', () => {
11-
test.each([
12-
{file: 'ComplexExample.ts'},
13-
{file: 'Example.ts'},
14-
{file: 'DisjointUnionExample.ts'},
15-
{file: 'OmitExample.ts'},
16-
])('$file', (tc) => {
17-
if (process.platform === 'win32') {
18-
return;
19-
}
20-
const oldSchema = parse(
21-
[
10+
if (process.platform === 'win32') {
11+
describe('Old parse does not work on windows', () => {
12+
test('temp', () => {});
13+
});
14+
} else {
15+
describe('Compare perivous schema gen to new', () => {
16+
test.each([
17+
{file: 'ComplexExample.ts'},
18+
{file: 'Example.ts'},
19+
{file: 'DisjointUnionExample.ts'},
20+
{file: 'OmitExample.ts'},
21+
])('$file', (tc) => {
22+
if (process.platform === 'win32') {
23+
return;
24+
}
25+
const oldSchema = parse(
26+
[
27+
path.normalize(
28+
path.posix.join(
29+
path.posix.normalize(__dirname),
30+
`/build-parameters/src/${tc.file}`,
31+
),
32+
),
33+
],
34+
loadTsConfig(),
35+
).getAllTypes();
36+
const newSchema = createParser(
2237
path.normalize(
2338
path.posix.join(
2439
path.posix.normalize(__dirname),
2540
`/build-parameters/src/${tc.file}`,
2641
),
2742
),
28-
],
29-
loadTsConfig(),
30-
).getAllTypes();
31-
const newSchema = createParser(
32-
path.normalize(
33-
path.posix.join(
34-
path.posix.normalize(__dirname),
35-
`/build-parameters/src/${tc.file}`,
36-
),
37-
),
38-
loadTsConfig(),
39-
{encodeRefs: true},
40-
).getAllTypes();
41-
expect(oldSchema).toMatchSnapshot('oldSchema');
42-
expect(newSchema).toMatchSnapshot('newSchema');
43-
const difference = diff(oldSchema, newSchema, {
44-
aColor: (s: string) => s,
45-
bColor: (s: string) => s,
46-
commonColor: (s: string) => s,
47-
patchColor: (s: string) => s,
48-
changeColor: (s: string) => s,
49-
contextLines: 3,
50-
});
51-
if (isNull(difference)) {
52-
fail();
53-
}
54-
//Uncomment line to have test fail, to see the differences with color
55-
//expect(newSchema).toStrictEqual(oldSchema);
56-
expect(difference.replaceAll('\r', '')).toMatchSnapshot('diff');
57-
}); //
58-
});
43+
loadTsConfig(),
44+
{encodeRefs: true},
45+
).getAllTypes();
46+
expect(oldSchema).toMatchSnapshot('oldSchema');
47+
expect(newSchema).toMatchSnapshot('newSchema');
48+
const difference = diff(oldSchema, newSchema, {
49+
aColor: (s: string) => s,
50+
bColor: (s: string) => s,
51+
commonColor: (s: string) => s,
52+
patchColor: (s: string) => s,
53+
changeColor: (s: string) => s,
54+
contextLines: 3,
55+
});
56+
if (isNull(difference)) {
57+
fail();
58+
}
59+
//Uncomment line to have test fail, to see the differences with color
60+
//expect(newSchema).toStrictEqual(oldSchema);
61+
expect(difference.replaceAll('\r', '')).toMatchSnapshot('diff');
62+
}); //
63+
});
64+
}

__tests__/parse.test.ts

Lines changed: 52 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,59 @@ import parse from './parse';
22
import Ajv from 'ajv';
33
import loadTsConfig from '../src/loadTsConfig';
44

5-
const it = process.platform === 'win32' ? describe.skip : describe;
5+
if (process.platform === 'win32') {
6+
describe('Old parse does not work on windows', () => {
7+
test('temp', () => {});
8+
});
9+
} else {
10+
test('parse', () => {
11+
if (process.platform === 'win32') {
12+
return;
13+
}
14+
expect(
15+
parse(
16+
[__dirname + '/build-parameters/src/ComplexExample.ts'],
17+
loadTsConfig(),
18+
).getAllTypes(),
19+
).toMatchSnapshot();
20+
});
621

7-
it('parse', () => {
8-
if (process.platform === 'win32') {
9-
return;
10-
}
11-
expect(
12-
parse(
22+
test('ajv', () => {
23+
if (process.platform === 'win32') {
24+
return;
25+
}
26+
const parsed = parse(
1327
[__dirname + '/build-parameters/src/ComplexExample.ts'],
1428
loadTsConfig(),
15-
).getAllTypes(),
16-
).toMatchSnapshot();
17-
});
29+
{
30+
titles: true,
31+
},
32+
);
33+
const {schema} = parsed.getAllTypes();
34+
const ajv = new Ajv({
35+
coerceTypes: false,
36+
allErrors: true,
37+
useDefaults: true,
38+
});
39+
ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-06.json'));
40+
ajv.addSchema(schema, 'root');
41+
const validateMyEnum = ajv.getSchema('root#/definitions/MyEnum')!;
42+
expect(validateMyEnum).toBeDefined();
43+
expect(typeof validateMyEnum).toBe('function');
44+
expect(validateMyEnum(1)).toBe(true);
45+
expect(validateMyEnum(10)).toBe(false);
46+
expect(
47+
ajv.errorsText(validateMyEnum.errors, {dataVar: 'x'}),
48+
).toMatchInlineSnapshot(`"x should be equal to one of the allowed values"`);
1849

19-
it('ajv', () => {
20-
if (process.platform === 'win32') {
21-
return;
22-
}
23-
const parsed = parse(
24-
[__dirname + '/build-parameters/src/ComplexExample.ts'],
25-
loadTsConfig(),
26-
{
27-
titles: true,
28-
},
29-
);
30-
const {schema} = parsed.getAllTypes();
31-
const ajv = new Ajv({coerceTypes: false, allErrors: true, useDefaults: true});
32-
ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-06.json'));
33-
ajv.addSchema(schema, 'root');
34-
const validateMyEnum = ajv.getSchema('root#/definitions/MyEnum')!;
35-
expect(validateMyEnum).toBeDefined();
36-
expect(typeof validateMyEnum).toBe('function');
37-
expect(validateMyEnum(1)).toBe(true);
38-
expect(validateMyEnum(10)).toBe(false);
39-
expect(
40-
ajv.errorsText(validateMyEnum.errors, {dataVar: 'x'}),
41-
).toMatchInlineSnapshot(`"x should be equal to one of the allowed values"`);
42-
43-
const validateRequestA = ajv.getSchema('root#/definitions/RequestA')!;
44-
expect(
45-
validateRequestA({query: {id: 'x', value: 'y'}, params: {e: 42}}),
46-
).toBe(false);
47-
expect(
48-
ajv.errorsText(validateRequestA.errors, {dataVar: 'req'}),
49-
).toMatchInlineSnapshot(
50-
`"req.query.id should be number, req should have required property 'body', req.params.e should be equal to one of the allowed values"`,
51-
);
52-
});
50+
const validateRequestA = ajv.getSchema('root#/definitions/RequestA')!;
51+
expect(
52+
validateRequestA({query: {id: 'x', value: 'y'}, params: {e: 42}}),
53+
).toBe(false);
54+
expect(
55+
ajv.errorsText(validateRequestA.errors, {dataVar: 'req'}),
56+
).toMatchInlineSnapshot(
57+
`"req.query.id should be number, req should have required property 'body', req.params.e should be equal to one of the allowed values"`,
58+
);
59+
});
60+
}

0 commit comments

Comments
 (0)