Skip to content

Commit

Permalink
fix: test fixes, semantic release, renovate config
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-north committed Nov 7, 2018
1 parent fc51494 commit ffaacca
Show file tree
Hide file tree
Showing 9 changed files with 3,458 additions and 101 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ npm install --save-dev json-typescript

2. Import this package
```ts
import _JSON from 'json-typescript';
import * as _JSON from 'json-typescript';
```

3. Check to see if json types are validated correctly

```ts
import _JSON from 'json-typescript';
import * as _JSON from 'json-typescript';

// ✅ This should be OK
let doc: _JSON.Value = {
Expand Down
20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,39 @@
},
"homepage": "https://github.com/mike-north/json-typescript#readme",
"devDependencies": {
"@commitlint/cli": "7.2.1",
"@commitlint/config-conventional": "7.1.2",
"@commitlint/travis-cli": "7.2.1",
"@mike-north/js-lib-renovate-config": "^0.0.1",
"@mike-north/js-lib-semantic-release-config": "^0.0.0-development",
"@types/chai": "^4.0.10",
"@types/mocha": "^2.2.44",
"@types/node": "^10.12.3",
"chai": "^4.1.2",
"chalk": "^2.3.0",
"dtslint": "^0.3.0",
"husky": "1.1.2",
"mocha": "^5.0.0",
"mocha-typescript": "^1.1.12",
"nodemon": "^1.17.5",
"semantic-release": "^15.10.8",
"ts-node": "^4.0.1",
"tsconfig": "^7.0.0",
"tslint": "^5.8.0",
"typescript": "^2.6.2",
"typings-tester": "^0.3.0"
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"husky": {
"hooks": {
"commit-msg": "./node_modules/.bin/commitlint -e $HUSKY_GIT_PARAMS"
}
},
"release": {
"extends": "@mike-north/js-lib-semantic-release-config"
}
}
2 changes: 1 addition & 1 deletion tests/examples/array-isnt-object.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import JSON from '../../index';
import * as JSON from '../../index';
let o: JSON.Object = [{ foo: 'bar' }];
2 changes: 1 addition & 1 deletion tests/examples/function.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import JSON from '../../index';
import * as JSON from '../../index';
let o: JSON.Value = {
b: {
c: {
Expand Down
2 changes: 1 addition & 1 deletion tests/examples/object-isnt-array.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import JSON from '../../index';
import * as JSON from '../../index';
let o: JSON.Arr = { foo: 'bar' };
64 changes: 36 additions & 28 deletions tests/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,47 @@
import { assert } from 'chai';
import { check } from 'typings-tester';
import { join, dirname } from 'path';
import { dirname } from 'path';
import * as tsconfig from 'tsconfig';
export async function assertTsThrows(fileName: string, message?: string): Promise<void>;
export async function assertTsThrows(fileName: string, errType: RegExp|Function, message?: string): Promise<void>;
export async function assertTsThrows(fileName: string, errType: Function, regExp: RegExp): Promise<void>;
export async function assertTsThrows(
fileName: string,
errType?: string | RegExp | Function,
message?: string | RegExp
message?: string
): Promise<void>;
export async function assertTsThrows(
fileName: string,
errType: RegExp | Function,
message?: string
): Promise<void>;
export async function assertTsThrows(
fileName: string,
errType: Function,
regExp: RegExp
): Promise<void>;
export async function assertTsThrows(
fileName: string,
errType?: string | RegExp | Function,
message?: string | RegExp
): Promise<void> {
return tsFileAssert(fileName, errType, message, assert.throws);
return tsFileAssert(fileName, errType, message, assert.throws);
}
async function tsFileAssert(
fileName: string,
errType?: string | RegExp | Function,
message?: string | RegExp,
assertMethod = assert.throws
errType?: string | RegExp | Function,
message?: string | RegExp,
assertMethod = assert.throws
): Promise<void> {
let typescriptConfig = await tsconfig.resolve(dirname(fileName));
let cb = () => {
check(
[fileName],
typescriptConfig as string
);
};
if (!errType) {
assertMethod(cb);
} else if (typeof errType === 'string') {
assertMethod(cb, errType);
} else if (message && typeof message === 'string') {
assertMethod(cb, errType, message);
} else if (errType instanceof Function && message instanceof RegExp) {
assertMethod(cb, errType, message);
} else {
assertMethod(cb, errType);
}
let typescriptConfig = await tsconfig.resolve(dirname(fileName));
let cb = () => {
check([fileName], typescriptConfig as string);
};
if (!errType) {
assertMethod(cb);
} else if (typeof errType === 'string') {
assertMethod(cb, errType);
} else if (message && typeof message === 'string') {
assertMethod(cb, errType, message);
} else if (errType instanceof Function && message instanceof RegExp) {
assertMethod(cb, errType, message);
} else {
assertMethod(cb, errType);
}
}
15 changes: 7 additions & 8 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { suite, test, slow, timeout, only } from 'mocha-typescript';
import { assert } from 'chai';
import { check, checkDirectory } from 'typings-tester';
import { suite, test } from 'mocha-typescript';
import { join } from 'path';
import { assertTsThrows } from './helpers';
import JSON from '../index';
import * as J from '../index';

@suite('JSON Type Definition Tests')
class JSONTests {
@test('functions are not allowed in JSON values')
Expand Down Expand Up @@ -32,7 +31,7 @@ class JSONTests {

@test('Some valid JSON values')
validValues() {
let v: JSON.Value;
let v: J.Value;
v = 'string';
v = 4;
v = true;
Expand All @@ -42,7 +41,7 @@ class JSONTests {

@test('Nested JSON values')
nestedValues() {
let v: JSON.Value = {
let v: J.Value = {
a: {
b: {
c: 'd',
Expand All @@ -54,7 +53,7 @@ class JSONTests {

@test('JSON.Object')
jsonObject() {
let v: JSON.Value = {
let v: J.Value = {
a: {
b: {
c: 'd',
Expand All @@ -66,7 +65,7 @@ class JSONTests {

@test('JSON.Array')
jsonArray() {
let v: JSON.Arr = [
let v: J.Arr = [
{
a: {
b: {
Expand Down
1 change: 1 addition & 0 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"ban-types": false,
"jsdoc-format": false,
"no-misused-new": false,
"file-name-casing": false,

// these are disabled because of rfc176 module exports
"strict-export-declare-modifiers": false,
Expand Down

0 comments on commit ffaacca

Please sign in to comment.