Skip to content

Commit 10c7079

Browse files
author
Vlad Balin
committed
Added jest tests
1 parent cd26510 commit 10c7079

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+66103
-43410
lines changed

dist/index.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext-types/dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext-types/lib/email.d.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
import { ChainableAttributeSpec } from 'type-r';
21
export declare function isEmail(x: string): boolean;
3-
export declare const Email: ChainableAttributeSpec;
2+
export declare const Email: import("../../lib/record/attributes/attrDef").ChainableAttributeSpec;

ext-types/lib/email.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext-types/lib/integer.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext-types/lib/url.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext-types/tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"experimentalDecorators": true,
1313
"baseUrl": ".",
1414
"paths" : {
15-
"type-r":[ "../lib" ]
15+
"type-r":[ "../lib" ],
16+
"type-r/ext-types":[ "../lib" ]
1617
}
1718
},
1819
"files":[

globals/dist/index.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

globals/dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

globals/lib/index.d.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1+
import { Integer } from "type-r/ext-types";
12
import { ChainableAttributeSpec } from "type-r";
23
declare global {
4+
interface Function {
5+
value: (x: any) => ChainableAttributeSpec;
6+
isRequired: ChainableAttributeSpec;
7+
asProp: PropertyDecorator;
8+
has: ChainableAttributeSpec;
9+
}
310
interface DateConstructor {
411
microsoft: ChainableAttributeSpec;
512
timestamp: ChainableAttributeSpec;
613
}
7-
}
8-
declare global {
914
interface Window {
1015
Integer: Function;
1116
}
17+
interface NumberConstructor {
18+
integer: typeof Integer;
19+
}
1220
}

globals/lib/index.js

+18-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

globals/lib/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

globals/src/index.ts

+44-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,57 @@
1-
import { Integer, MicrosoftDate, Timestamp } from "ext-types";
2-
import { ChainableAttributeSpec } from "type-r";
1+
import { Integer, MicrosoftDate, Timestamp } from "type-r/ext-types";
2+
import { type, ChainableAttributeSpec } from "type-r";
33

44
/*
55
* dates
66
*/
77
declare global {
8+
// Legacy has-notation
9+
interface Function{
10+
value : ( x : any ) => ChainableAttributeSpec;
11+
isRequired : ChainableAttributeSpec;
12+
asProp : PropertyDecorator
13+
has : ChainableAttributeSpec;
14+
}
15+
16+
// Date type extensions
817
interface DateConstructor {
918
microsoft : ChainableAttributeSpec
1019
timestamp : ChainableAttributeSpec
1120
}
21+
22+
// Integer type
23+
interface Window {
24+
Integer : Function;
25+
}
26+
27+
interface NumberConstructor {
28+
integer : typeof Integer
29+
}
1230
}
1331

32+
Function.prototype.value = function( x ) {
33+
return new ChainableAttributeSpec( { type : this, value : x, hasCustomDefault : true } );
34+
};
35+
36+
Object.defineProperty( Function.prototype, 'isRequired', {
37+
get() { return this._isRequired || this.has.isRequired; },
38+
set( x ){ this._isRequired = x; }
39+
});
40+
41+
Object.defineProperty( Function.prototype, 'asProp', {
42+
get() { return this.has.asProp; },
43+
});
44+
45+
Object.defineProperty( Function.prototype, 'has', {
46+
get() {
47+
// workaround for sinon.js and other libraries overriding 'has'
48+
return this._has || type( this );
49+
},
50+
51+
set( value ) { this._has = value; }
52+
} );
53+
54+
1455
Object.defineProperties( Date, {
1556
microsoft: {
1657
value: MicrosoftDate
@@ -25,13 +66,8 @@ Object.defineProperties( Date, {
2566
/*
2667
* integer
2768
*/
28-
declare global {
29-
interface Window {
30-
Integer : Function;
31-
}
32-
}
3369

34-
(Number as any).integer = Integer;
70+
Number.integer = Integer;
3571

3672
if( typeof window !== 'undefined' ) {
3773
window.Integer = Integer;

globals/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"baseUrl": ".",
1414
"paths" : {
1515
"type-r":[ "../lib" ],
16-
"ext-types": ["../ext-types/lib"]
16+
"type-r/ext-types": ["../ext-types/lib"]
1717
}
1818
},
1919
"files":[

jest.config.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module.exports = {
2+
testEnvironment: 'node',
3+
transform: {
4+
"^.+\\.tsx?$": "ts-jest"
5+
},
6+
moduleFileExtensions: [
7+
"ts",
8+
"tsx",
9+
"js",
10+
"jsx",
11+
"json",
12+
"node",
13+
],
14+
testRegex: '/tests/.+\\.(test|spec)\\.(ts|js)x?$',
15+
coverageDirectory: 'coverage',
16+
collectCoverageFrom: [
17+
'src/**/*.{ts,tsx,js,jsx}',
18+
'!src/**/*.d.ts',
19+
],
20+
globals: {
21+
'ts-jest': {
22+
tsConfig: 'tests/tsconfig.json'
23+
}
24+
}
25+
};

lib/index.d.ts

+6-12
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
1-
declare global {
2-
interface ObjectConstructor {
3-
setPrototypeOf(target: Object, proto: Object): any;
4-
}
5-
}
6-
export * from './object-plus';
1+
import { Mixable as Class } from './object-plus/';
2+
import { ChainableAttributeSpec, Record as Model } from './record';
73
export * from './collection';
8-
export * from './relations';
4+
export * from './io-tools';
5+
export * from './object-plus';
96
export * from './record';
7+
export * from './relations';
108
export * from './transactions';
11-
export * from './io-tools';
12-
export declare const on: any, off: any, trigger: any, once: any, listenTo: any, stopListening: any, listenToOnce: any;
13-
import { Record as Model } from './record';
14-
import { Mixable as Class } from './object-plus/';
159
export { Model, Class };
10+
export declare const on: any, off: any, trigger: any, once: any, listenTo: any, stopListening: any, listenToOnce: any;
1611
export declare function attributes(attrDefs: any): typeof Model;
17-
import { ChainableAttributeSpec } from './record';
1812
export declare function value(x: any): ChainableAttributeSpec;
1913
export declare function transaction<F extends Function>(method: F): F;

lib/index.js

+6-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/object-plus/logging.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ export declare class Logger extends Messenger {
1010
[name in LogLevel]: LoggerEventHandler;
1111
} | LogLevel, handler?: LoggerEventHandler) => this;
1212
}
13-
export declare const logRouter: Logger;
14-
export declare const log: typeof logRouter.trigger;
13+
export declare const logger: Logger;
14+
export declare const log: typeof logger.trigger;

lib/object-plus/logging.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)