Skip to content

Commit 9e9ac49

Browse files
committed
Updated template
- Updated dependencies - Provided example usage of fast-check - Added gitattributes for compatibility with microsoft
1 parent c160ab8 commit 9e9ac49

File tree

7 files changed

+10978
-4770
lines changed

7 files changed

+10978
-4770
lines changed

.eslintrc.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ module.exports = {
3030
},
3131
rules: {
3232
'import/no-extraneous-dependencies': warn,
33+
3334
// Temporal?
3435
'no-console': warn,
3536
'no-return-await': warn,
36-
'no-unused-vars': warn,
37+
'no-unused-vars': off,
38+
'@typescript-eslint/no-unused-vars': off,
3739
eqeqeq: [error, 'smart'],
3840
'no-else-return': [
3941
error,
@@ -63,6 +65,9 @@ module.exports = {
6365
'@typescript-eslint/indent': off,
6466
'@typescript-eslint/explicit-member-accessibility': warn,
6567
'@typescript-eslint/no-explicit-any': off,
68+
'@typescript-eslint/no-unsafe-return': off,
69+
'@typescript-eslint/no-unsafe-assignment': off,
70+
'@typescript-eslint/explicit-function-return-type': off,
6671
'@typescript-eslint/no-var-requires': off,
6772
'@typescript-eslint/no-empty-function': off,
6873
'@typescript-eslint/no-object-literal-type-assertion': off,
@@ -71,16 +76,7 @@ module.exports = {
7176
overrides: [
7277
{
7378
files: ['*.ts', '*.tsx'],
74-
rules: {
75-
'@typescript-eslint/explicit-function-return-type': [
76-
error,
77-
{
78-
allowExpressions: true,
79-
allowTypedFunctionExpressions: true,
80-
allowHigherOrderFunctions: true,
81-
},
82-
],
83-
},
79+
rules: {},
8480
},
8581
{
8682
// TESTING CONFIGURATION
@@ -105,6 +101,7 @@ module.exports = {
105101
// "extends": ["plugin:jest/recommended"]
106102
plugins: ['jest'],
107103
rules: {
104+
'no-restricted-imports': off,
108105
'jest/no-disabled-tests': warn,
109106
'jest/no-focused-tests': error,
110107
'jest/no-identical-title': error,

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

__tests__/datetime.test.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

__tests__/replace.test.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import fc, { Arbitrary } from 'fast-check';
2+
import { replace } from '../src';
3+
4+
const EachSimpleType = [
5+
['string', fc.string()],
6+
['integers', fc.integer()],
7+
] as const;
8+
9+
describe.each(EachSimpleType)('Simple replacements works for %p', (_, arb: Arbitrary<any>) => {
10+
test('Should replace simple types', () => {
11+
fc.assert(
12+
fc.property(arb, fc.func(arb), (s, f) => {
13+
return replace(f, (t: string): t is any => true)(s) === f(s);
14+
}),
15+
);
16+
});
17+
});
18+
19+
describe.each(EachSimpleType)('Simple replacements works for arrays of %p', (_, arb: Arbitrary<any>) => {
20+
test('Should replace only elements', () => {
21+
fc.assert(
22+
fc.property(fc.array(arb), fc.func(arb), (arr, f) => {
23+
const obtainedResult = replace(f, (t): t is any => !Array.isArray(t))(arr);
24+
const realResult = arr.map((v) => f(v));
25+
expect(obtainedResult).toStrictEqual(realResult);
26+
}),
27+
);
28+
});
29+
});
30+
31+
describe.each(EachSimpleType)('Simple replacements works for objects of %p', (_, arb: Arbitrary<any>) => {
32+
test('Should replace only properties', () => {
33+
fc.assert(
34+
fc.property(fc.dictionary(fc.string(), arb), fc.func(arb), (obj, f) => {
35+
const realResult = Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, f(v)]));
36+
const obtainedResult = replace(f, (t): t is any => !Array.isArray(t) && typeof t !== 'object')(obj);
37+
38+
expect(obtainedResult).toStrictEqual(realResult);
39+
}),
40+
);
41+
});
42+
});
43+
44+
describe('Ignoring values', () => {
45+
const f = (v: any) => {
46+
throw new Error();
47+
};
48+
test('should leave json objects alone', () => {
49+
const throwOnReplace = replace(f, (t): t is any => false);
50+
fc.assert(
51+
fc.property(fc.jsonObject(), (json) => {
52+
expect(() => expect(throwOnReplace(json)).toStrictEqual(json)).not.toThrow();
53+
}),
54+
);
55+
});
56+
57+
test('Should leave numbers unchanged when searching for strings', () => {
58+
const throwOnReplace = replace(f, (t): t is string => typeof t === 'string');
59+
const objectArbitrary = fc.object({ maxDepth: 4, withTypedArray: true, values: [fc.integer()] });
60+
fc.assert(
61+
fc.property(objectArbitrary, (obj) => {
62+
expect(() => throwOnReplace(obj)).not.toThrow();
63+
}),
64+
);
65+
});
66+
});

0 commit comments

Comments
 (0)