Skip to content

Commit

Permalink
chore: improve test coverage after migrating ts project (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyjake authored Nov 7, 2023
1 parent dc9056b commit 834c80b
Show file tree
Hide file tree
Showing 49 changed files with 93 additions and 90 deletions.
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
"eslint --no-ignore --fix"
]
},
"nyc": {
"extends": "@istanbuljs/nyc-config-typescript",
"include": [
"src"
]
},
"dependencies": {
"dayjs": "^1.10.3",
"debug": "^3.1.0",
Expand Down Expand Up @@ -101,6 +107,7 @@
"@babel/core": "^7.14.6",
"@babel/eslint-parser": "^7.14.7",
"@cara/minami": "^1.2.3",
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@journeyapps/sqlcipher": "^5.2.0",
"@tsconfig/node16": "^16.1.1",
"@types/mocha": "^9.0.0",
Expand Down
2 changes: 1 addition & 1 deletion test/integration/custom.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const path = require('path');
const sinon = require('sinon');
const SqlString = require('sqlstring');

const { connect, raw, Bone, disconnect, Raw, SqliteDriver } = require('../..');
const { connect, raw, Bone, disconnect, Raw, SqliteDriver } = require('../../src');
const { checkDefinitions } = require('./helpers');
const { formatConditions, collectLiteral } = require('../../src/expr_formatter');
const { findExpr } = require('../../src/expr');
Expand Down
2 changes: 1 addition & 1 deletion test/integration/helpers/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const assert = require('assert').strict;
const { Bone } = require('../../..');
const { Bone } = require('../../../src');

async function checkDefinitions(table, definitions) {
const { database } = Bone.options;
Expand Down
2 changes: 1 addition & 1 deletion test/integration/mysql.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const assert = require('assert').strict;
const path = require('path');
const dayjs = require('dayjs');

const { connect } = require('../..');
const { connect } = require('../../src');

before(async function() {
await connect({
Expand Down
2 changes: 1 addition & 1 deletion test/integration/mysql2.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const path = require('path');
const { connect } = require('../..');
const { connect } = require('../../src');

before(async function() {
await connect({
Expand Down
2 changes: 1 addition & 1 deletion test/integration/postgres.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const assert = require('assert').strict;
const path = require('path');
const sinon = require('sinon');

const { connect, raw } = require('../..');
const { connect, raw } = require('../../src');

before(async function() {
await connect({
Expand Down
2 changes: 1 addition & 1 deletion test/integration/sqlcipher.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const fs = require('fs').promises;
const path = require('path');
const sqlcipher = require('@journeyapps/sqlcipher');
const Realm = require('../..');
const Realm = require('../../src');

before(async function() {
const plaintext = '/tmp/leoric.sqlite3';
Expand Down
2 changes: 1 addition & 1 deletion test/integration/sqlite.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const assert = require('assert').strict;
const path = require('path');
const sinon = require('sinon');

const { connect, raw, Bone } = require('../..');
const { connect, raw, Bone } = require('../../src');
const { checkDefinitions } = require('./helpers');

before(async function() {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/sqljs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const path = require('path');
const fs = require('fs').promises;
const sinon = require('sinon');

const Realm = require('../..');
const Realm = require('../../src');
const { checkDefinitions } = require('./helpers');

const { raw, Bone, SqljsDriver } = Realm;
Expand Down
2 changes: 1 addition & 1 deletion test/integration/suite/basics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const assert = require('assert').strict;
const expect = require('expect.js');

const { Collection, Bone } = require('../../..');
const { Collection, Bone } = require('../../../src');
const Book = require('../../models/book');
const Comment = require('../../models/comment');
const Post = require('../../models/post');
Expand Down
22 changes: 11 additions & 11 deletions test/integration/suite/data_types.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const assert = require('assert').strict;
const dayjs = require('dayjs');

const { Bone, DataTypes } = require('../../..');
const { Bone, DataTypes } = require('../../../src');
const { INTEGER, STRING, DATE, DATEONLY, TEXT, BOOLEAN, JSON, JSONB, BIGINT } = DataTypes;


Expand All @@ -17,7 +17,7 @@ describe('=> Data types', () => {
createdAt: DATE,
updatedAt: DATE,
publishedAt: DATE(6),
}
};
};

before(async () => {
Expand Down Expand Up @@ -77,7 +77,7 @@ describe('=> Data types - JSON', () => {
publishedAt: DATE(6),
meta: JSON,
metab: JSONB,
}
};
}

before(async () => {
Expand Down Expand Up @@ -146,7 +146,7 @@ describe('=> Data types - BINARY', () => {
meta: BINARY,
metab: VARBINARY,
metac: BLOB
}
};
}
Note = NoteClass;
});
Expand Down Expand Up @@ -202,7 +202,7 @@ describe('=> Data Types - INTEGER', function() {
static attributes = {
word_count: INTEGER,
createdAt: DATE,
}
};
}

before(async function() {
Expand Down Expand Up @@ -250,7 +250,7 @@ describe('=> Data types - DATE', function() {
static attributes = {
createdAt: DATE(6),
updatedAt: DATE(6),
}
};
}

before(async function() {
Expand Down Expand Up @@ -307,7 +307,7 @@ describe('=> Data types - DATEONLY', function() {
class Note extends Bone {
static attributes = {
createdAt: DATEONLY,
}
};
}

before(async function() {
Expand Down Expand Up @@ -363,7 +363,7 @@ describe('=> Data types - JSON', function() {
class Note extends Bone {
static attributes = {
meta: JSON,
}
};
}

before(async () => {
Expand Down Expand Up @@ -392,7 +392,7 @@ describe('=> Data types - TEXT', function() {
class Note extends Bone {
static attributes = {
meta: TEXT,
}
};
}

before(async () => {
Expand Down Expand Up @@ -426,7 +426,7 @@ describe('=> Data types - STRING', function() {
class Note extends Bone {
static attributes = {
meta: STRING,
}
};
}

before(async () => {
Expand Down Expand Up @@ -461,7 +461,7 @@ describe('=> Data types - complementary', function() {
static attributes = {
createdAt: DATE,
updatedAt: new DATE(3),
}
};
}

before(async function() {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/suite/definitions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const assert = require('assert').strict;
const sinon = require('sinon');
const { Bone, DataTypes } = require('../../..');
const { Bone, DataTypes } = require('../../../src');
const { checkDefinitions } = require('../helpers');

const { INTEGER, STRING, TEXT } = DataTypes;
Expand Down
2 changes: 1 addition & 1 deletion test/integration/suite/migrations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const fs = require('fs').promises;
const path = require('path');
const dayjs = require('dayjs');

const Realm = require('../../..');
const Realm = require('../../../src');
const Logger = require('../../../src/drivers/abstract/logger');
const { checkDefinitions } = require('../helpers');

Expand Down
2 changes: 1 addition & 1 deletion test/integration/suite/querying.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const assert = require('assert').strict;
const expect = require('expect.js');
const sinon = require('sinon');

const { raw } = require('../../../');
const { raw } = require('../../../src');

const Attachment = require('../../models/attachment');
const Book = require('../../models/book');
Expand Down
2 changes: 1 addition & 1 deletion test/models/attachment.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { Bone } = require('../..');
const { Bone } = require('../../src');

class Attachment extends Bone {
static initialize() {
Expand Down
2 changes: 1 addition & 1 deletion test/models/book.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { Bone } = require('../..');
const { Bone } = require('../../src');

class Book extends Bone {
// static get primaryKey() {
Expand Down
2 changes: 1 addition & 1 deletion test/models/comment.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { Bone } = require('../..');
const { Bone } = require('../../src');

class Comment extends Bone {
static initialize() {
Expand Down
2 changes: 1 addition & 1 deletion test/models/like.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { Bone } =require('../..');
const { Bone } =require('../../src');

const TARGET_TYPE = {
post: 0,
Expand Down
2 changes: 1 addition & 1 deletion test/models/photo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BelongsTo, Bone, Column } from '../..';
import { BelongsTo, Bone, Column } from '../../src';
import User from './user';

export default class Photo extends Bone {
Expand Down
2 changes: 1 addition & 1 deletion test/models/post.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { Bone } = require('../..');
const { Bone } = require('../../src');

class Post extends Bone {
static table = 'articles';
Expand Down
4 changes: 2 additions & 2 deletions test/models/tag.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { Bone, DataTypes } = require('../..');
const { Bone, DataTypes } = require('../../src');

const CHARSET = 'abcdefghigklmnopqrstuvwxyz0123456789';

Expand Down Expand Up @@ -29,7 +29,7 @@ class Tag extends Bone {
type: DataTypes.STRING,
unique: true,
}
}
};

static beforeCreate(obj) {
if (!obj.uuid) {
Expand Down
2 changes: 1 addition & 1 deletion test/models/tagMap.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { Bone } = require('../..');
const { Bone } = require('../../src');

class TagMap extends Bone {
static initialize() {
Expand Down
2 changes: 1 addition & 1 deletion test/models/user.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { Bone, DataTypes } = require('../..');
const { Bone, DataTypes } = require('../../src');

const formatter = {
formatName(value) {
Expand Down
4 changes: 0 additions & 4 deletions test/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,18 @@ function dts {
case $1 in
unit)
args=("${@:2}")
npm run prepack
unit
;;
integration)
args=("${@:2}")
npm run prepack
integration
;;
dts)
args=("${@:2}")
npm run prepack
dts
;;
*.js)
args=("${@:1}")
npm run prepack
run $1
;;
*)
Expand Down
2 changes: 1 addition & 1 deletion test/types/basics.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { strict as assert } from 'assert';
import sinon, { SinonFakeTimers } from 'sinon';
import Realm, { Bone, Column, DataTypes, connect, Raw } from '../..';
import Realm, { Bone, Column, DataTypes, connect, Raw } from '../../src';

describe('=> Basics (TypeScript)', function() {
const { TEXT } = DataTypes;
Expand Down
2 changes: 1 addition & 1 deletion test/types/collection.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { strict as assert } from 'assert';
import { Bone, Collection, connect } from '../..';
import { Bone, Collection, connect } from '../../src';

describe('=> Collection (TypeScript)', function() {
class User extends Bone {
Expand Down
2 changes: 1 addition & 1 deletion test/types/custom_driver.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { strict as assert } from 'assert';
const SqlString = require('sqlstring');

import Realm, { SqliteDriver, SpellMeta, Literal, SpellBookFormatResult, Column, Raw } from '../..';
import Realm, { SqliteDriver, SpellMeta, Literal, SpellBookFormatResult, Column, Raw } from '../../src';
const { formatConditions, collectLiteral } = require('../../src/expr_formatter');
const { findExpr } = require('../../src/expr');

Expand Down
8 changes: 4 additions & 4 deletions test/types/data_types.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { strict as assert } from 'assert';
import Realm, { DataTypes, LENGTH_VARIANTS } from '../..';
import Realm, { DataTypes, LENGTH_VARIANTS } from '../../src';

describe('=> Data types (TypeScript)', function() {
const { STRING, TEXT, BLOB, INTEGER, BIGINT, DATE, BOOLEAN, BINARY, VARBINARY, VIRTUAL, JSON, JSONB, DECIMAL } = DataTypes;
Expand All @@ -11,7 +11,7 @@ describe('=> Data types (TypeScript)', function() {
});
// should be mixed with dialect overrides
assert.notEqual(realm.Bone.DataTypes, DataTypes);
})
});

it('STRING', async function() {
assert.equal(STRING(255).toSqlString(), 'VARCHAR(255)');
Expand Down Expand Up @@ -82,7 +82,7 @@ describe('=> Data types (TypeScript)', function() {
it('BOOLEAN', () => {
assert.equal(BOOLEAN.toSqlString(), 'BOOLEAN');
assert.equal((new BOOLEAN).toSqlString(), 'BOOLEAN');
})
});

it('BINARY', () => {
// default 255
Expand Down Expand Up @@ -127,5 +127,5 @@ describe('=> Data types (TypeScript)', function() {
assert.equal(DECIMAL.ZEROFILL.toSqlString(), 'DECIMAL ZEROFILL');
assert.equal(DECIMAL(10).ZEROFILL.toSqlString(), 'DECIMAL(10) ZEROFILL');
assert.equal(new DECIMAL(10).ZEROFILL.toSqlString(), 'DECIMAL(10) ZEROFILL');
})
});
});
2 changes: 1 addition & 1 deletion test/types/decorators.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { strict as assert } from 'assert';
import { AttributeMeta, Bone, DataTypes, Column, HasMany, BelongsTo, connect } from '../..';
import { AttributeMeta, Bone, DataTypes, Column, HasMany, BelongsTo, connect } from '../../src';

const { TEXT, STRING, INTEGER } = DataTypes;

Expand Down
2 changes: 1 addition & 1 deletion test/types/querying.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { strict as assert } from 'assert';
import { Bone, DataTypes, Column, HasMany, connect, Raw } from '../..';
import { Bone, DataTypes, Column, HasMany, connect, Raw } from '../../src';

describe('=> Querying (TypeScript)', function() {
const { BIGINT, INTEGER, STRING } = DataTypes;
Expand Down
Loading

0 comments on commit 834c80b

Please sign in to comment.