Прогнал линтером для автоматических доделок, но оставлять его не стал - слишком много ошибок
This commit is contained in:
1 parent
ce3a192cbd
commit
c6db8bc2fe
14 files changed
+118
-8324
No files matched your search
@@ -1,13 +1,13 @@
|
||||
const Sequencer = require('@jest/test-sequencer').default;
|
||||
const Sequencer = require('@jest/test-sequencer').default
|
||||
|
||||
class CustomSequencer extends Sequencer {
|
||||
sort(tests) {
|
||||
// Test structure information
|
||||
// https://github.com/facebook/jest/blob/6b8b1404a1d9254e7d5d90a8934087a9c9899dab/packages/jest-runner/src/types.ts#L17-L21
|
||||
const copyTests = Array.from(tests);
|
||||
const copyTests = Array.from(tests)
|
||||
// @ts-ignore
|
||||
return copyTests.sort((testA, testB) => (testA.path > testB.path ? 1 : -1));
|
||||
return copyTests.sort((testA, testB) => (testA.path > testB.path ? 1 : -1))
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CustomSequencer;
|
||||
module.exports = CustomSequencer
|
||||
@@ -1,10 +1,10 @@
|
||||
const failFast = require("jasmine-fail-fast");
|
||||
const failFast = require('jasmine-fail-fast')
|
||||
|
||||
// Добавляем нормальный fail fast
|
||||
// https://github.com/facebook/jest/issues/2867
|
||||
|
||||
//if (process.argv.includes("--bail")) {
|
||||
// @ts-ignore
|
||||
const jasmineEnv = jasmine.getEnv();
|
||||
jasmineEnv.addReporter(failFast.init());
|
||||
//}
|
||||
// if (process.argv.includes("--bail")) {
|
||||
// @ts-expect-error
|
||||
const jasmineEnv = jasmine.getEnv()
|
||||
jasmineEnv.addReporter(failFast.init())
|
||||
// }
|
||||
+15
-15
@@ -6,30 +6,30 @@ export class ItemData extends Data {
|
||||
return 'a'
|
||||
}
|
||||
|
||||
a: number = 0
|
||||
a = 0
|
||||
b: number
|
||||
c: { d: number; e?: number } = { d: 1 }
|
||||
__f: number = 0
|
||||
__f = 0
|
||||
sum() {
|
||||
return this.a + this.c.d + this.c.e
|
||||
}
|
||||
}
|
||||
|
||||
describe('Data', function () {
|
||||
describe('#toObject', function () {
|
||||
it('should return object', function () {
|
||||
describe('Data', () => {
|
||||
describe('#toObject', () => {
|
||||
it('should return object', () => {
|
||||
const data = new ItemData()
|
||||
data.a = 1
|
||||
data.c = { d: 2, e: undefined }
|
||||
const obj = data.toObject()
|
||||
const object = data.toObject()
|
||||
|
||||
assert.strictEqual('a' in obj, true)
|
||||
assert.strictEqual('b' in obj, false)
|
||||
assert.strictEqual('c' in obj, true)
|
||||
assert.strictEqual('d' in obj['c'], true)
|
||||
assert.strictEqual('e' in obj['c'], true)
|
||||
assert.strictEqual('__f' in obj, false)
|
||||
assert.strictEqual('sum' in obj, false)
|
||||
assert.strictEqual('a' in object, true)
|
||||
assert.strictEqual('b' in object, false)
|
||||
assert.strictEqual('c' in object, true)
|
||||
assert.strictEqual('d' in object['c'], true)
|
||||
assert.strictEqual('e' in object['c'], true)
|
||||
assert.strictEqual('__f' in object, false)
|
||||
assert.strictEqual('sum' in object, false)
|
||||
})
|
||||
})
|
||||
describe('#fromObject', () => {
|
||||
@@ -37,10 +37,10 @@ describe('Data', function () {
|
||||
const dataOrig = new ItemData()
|
||||
dataOrig.a = 1
|
||||
dataOrig.c = { d: 2, e: undefined }
|
||||
const obj = dataOrig.toObject()
|
||||
const object = dataOrig.toObject()
|
||||
|
||||
const dataRecovered = new ItemData()
|
||||
dataRecovered.fromObject(obj)
|
||||
dataRecovered.fromObject(object)
|
||||
|
||||
assert.notStrictEqual(dataOrig, dataRecovered)
|
||||
})
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { ItemData } from './data.test'
|
||||
import assert from 'assert'
|
||||
import { Entity } from '../app/entity'
|
||||
import { Storage } from '../app/storage'
|
||||
import { Repo } from '../app/repo'
|
||||
import { MapStorage } from './storage.test'
|
||||
import { Data } from '../app/data'
|
||||
import assert from 'assert'
|
||||
import { MapStorage } from './storage.test'
|
||||
import { ItemData } from './data.test'
|
||||
|
||||
class Item extends Entity<ItemData> {
|
||||
_getVO(): ItemData {
|
||||
@@ -16,6 +16,7 @@ class Item extends Entity<ItemData> {
|
||||
getA(): number {
|
||||
return this._data.a
|
||||
}
|
||||
|
||||
getC(): { d: number; e?: number } {
|
||||
return this._data.c
|
||||
}
|
||||
@@ -29,13 +30,14 @@ class ItemRepository extends Repo<Item> {
|
||||
Name() {
|
||||
return 'items'
|
||||
}
|
||||
|
||||
Entity() {
|
||||
return new Item()
|
||||
}
|
||||
}
|
||||
|
||||
describe('ItemRepository', function () {
|
||||
describe('map storage save', function () {
|
||||
describe('ItemRepository', () => {
|
||||
describe('map storage save', () => {
|
||||
const storage = new MapStorage('')
|
||||
const repo = new ItemRepository(storage)
|
||||
|
||||
|
||||
+26
-24
@@ -9,16 +9,16 @@ export class MapCursor implements StorageCursor {
|
||||
this._map = map
|
||||
}
|
||||
|
||||
limit(num: number): StorageCursor {
|
||||
this._limit = num
|
||||
limit(number_: number): StorageCursor {
|
||||
this._limit = number_
|
||||
return this
|
||||
}
|
||||
|
||||
sort(params: {}): StorageCursor {
|
||||
sort(parameters: Record<string, unknown>): StorageCursor {
|
||||
return this
|
||||
}
|
||||
|
||||
toArray(): Promise<any[]> {
|
||||
async toArray(): Promise<any[]> {
|
||||
return Promise.resolve(Array.from(this._map.values()))
|
||||
}
|
||||
|
||||
@@ -37,50 +37,52 @@ export class MapStorage extends Storage {
|
||||
this._mapPool = {}
|
||||
}
|
||||
|
||||
async find(name: string, query: Object): Promise<StorageCursor> {
|
||||
async find(name: string, query: Record<string, unknown>): Promise<StorageCursor> {
|
||||
if (!(name in this._mapPool)) {
|
||||
return new MapCursor(new Map())
|
||||
}
|
||||
|
||||
const map: Map<any, any> = new Map()
|
||||
for (let [_, elem] of this._mapPool[name]) {
|
||||
nextParam: for (let [key, val] of Object.entries(query)) {
|
||||
if (key in elem) {
|
||||
for (let symbol of ['=', '>', '<', '!']) {
|
||||
if ((val + '').startsWith(symbol)) {
|
||||
if (eval(elem[key] + val + '')) {
|
||||
map.set(_, elem)
|
||||
break nextParam
|
||||
}
|
||||
for (const [_, element] of this._mapPool[name]) {
|
||||
nextParam: for (const [key, value] of Object.entries(query)) {
|
||||
if (key in element) {
|
||||
for (const symbol of ['=', '>', '<', '!']) {
|
||||
if (String(value).startsWith(symbol) && eval(String(element[key] + value))) {
|
||||
map.set(_, element)
|
||||
break nextParam
|
||||
}
|
||||
}
|
||||
if (elem[key] == val) {
|
||||
map.set(_, elem)
|
||||
|
||||
if (element[key] == value) {
|
||||
map.set(_, element)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new MapCursor(map)
|
||||
}
|
||||
|
||||
count(name: string, query: object): Promise<number> {
|
||||
async count(name: string, query: Record<string, unknown>): Promise<number> {
|
||||
return Promise.resolve(0)
|
||||
}
|
||||
|
||||
remove(collectionName: string, uniqKeyName: string, uniqKey: string): Promise<boolean> {
|
||||
async remove(collectionName: string, uniqKeyName: string, uniqKey: string): Promise<boolean> {
|
||||
return Promise.resolve(true)
|
||||
}
|
||||
|
||||
async save(name: string, idKey: string, data: Object): Promise<string> {
|
||||
async save(name: string, idKey: string, data: Record<string, unknown>): Promise<string> {
|
||||
if (!(name in this._mapPool)) {
|
||||
this._mapPool[name] = new Map()
|
||||
this._mapPoolId[name] = {}
|
||||
}
|
||||
|
||||
const id = data[idKey] + ''
|
||||
const id = String(data[idKey])
|
||||
this._mapPool[name].set(id, data)
|
||||
if (!(id in this._mapPoolId[name])) {
|
||||
this._mapPoolId[name][id] = Date.now()
|
||||
}
|
||||
|
||||
return Promise.resolve(this._mapPoolId[name][id])
|
||||
}
|
||||
|
||||
@@ -90,17 +92,17 @@ export class MapStorage extends Storage {
|
||||
}
|
||||
|
||||
class MapStorageSession extends StorageSession {
|
||||
async commit(fn, options?: {}): Promise<any> {
|
||||
async commit(fn, options?: Record<string, unknown>): Promise<any> {
|
||||
return Promise.resolve(undefined)
|
||||
}
|
||||
|
||||
async start(options?: {}): Promise<any> {
|
||||
async start(options?: Record<string, unknown>): Promise<any> {
|
||||
return Promise.resolve(undefined)
|
||||
}
|
||||
}
|
||||
|
||||
describe('Storage', function () {
|
||||
describe('#save', function () {
|
||||
describe('Storage', () => {
|
||||
describe('#save', () => {
|
||||
it('should return inner id', async () => {
|
||||
const storage = new MapStorage('')
|
||||
|
||||
|
||||
Reference in new issue
Block a user