Skip to content

Commit

Permalink
refactor: fix imports in unit tests files
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Mar 20, 2023
1 parent 15c1bee commit 544d6c4
Show file tree
Hide file tree
Showing 342 changed files with 738 additions and 567 deletions.
6 changes: 5 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@
},
"overrides": [
{
"files": ["**/*.spec.ts", "**/*.benchmark.ts", "**/test/**", "**/__mock__/**"],
"files": [
"**/*.benchmark.ts",
"**/test/**",
"**/__mock__/**"
],
"rules": {
"workspaces/no-absolute-imports": "off"
}
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/domain/AnyToPromise.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {catchAsyncError, isStream} from "@tsed/core";
import {createReadStream} from "fs";
import {of} from "rxjs";
import {catchAsyncError} from "../utils/catchError";
import {isStream} from "../utils/objects/isStream";
import {AnyToPromise, AnyToPromiseStatus} from "./AnyToPromise";

describe("AnyToPromise", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/domain/Hooks.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Hooks} from "@tsed/core";
import {Hooks} from "./Hooks";

describe("Hooks", () => {
describe("emit", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/domain/Metadata.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Metadata} from "../../src";
import {Metadata} from "./Metadata";

function logger(target: any, method?: any, descriptor?: any) {
return descriptor;
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/domain/Store.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {CLASS_STORE, Metadata, METHOD_STORE, PARAM_STORE, PROPERTY_STORE, Store} from "../../src";
import {Metadata} from "./Metadata";
import {CLASS_STORE, METHOD_STORE, PARAM_STORE, PROPERTY_STORE, Store} from "./Store";

class FakeMetadata {
attr1: any;
Expand Down
14 changes: 13 additions & 1 deletion packages/core/src/utils/catchError.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {catchError} from "./catchError";
import {catchAsyncError, catchError} from "./catchError";

describe("catchError", () => {
it("should catch error", () => {
Expand All @@ -9,3 +9,15 @@ describe("catchError", () => {
).toEqual("message");
});
});

describe("catchAsyncError", () => {
it("should catch error", async () => {
expect(
(
await catchAsyncError(async () => {
throw new Error("message");
})
)?.message
).toEqual("message");
});
});
5 changes: 4 additions & 1 deletion packages/core/src/utils/decorators/decorateMethodsOf.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import {descriptorOf, Store, StoreMerge, StoreSet} from "@tsed/core";
import {StoreMerge} from "../../decorators/storeMerge";
import {StoreSet} from "../../decorators/storeSet";
import {Store} from "../../domain/Store";
import {descriptorOf} from "../objects/descriptorOf";
import {decorateMethodsOf} from "./decorateMethodsOf";

describe("decorateMethodsOf", () => {
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/utils/decorators/decoratorArgs.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {decoratorArgs, descriptorOf, prototypeOf} from "@tsed/core";
import {descriptorOf} from "../objects/descriptorOf";
import {prototypeOf} from "../objects/prototypeOf";
import {decoratorArgs} from "./decoratorArgs";

describe("decoratorArgs", () => {
it("should return decorator arguments", () => {
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/utils/decorators/useDecorators.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {Store, StoreFn, useDecorators} from "@tsed/core";
import {StoreFn} from "../../decorators/storeFn";
import {useDecorators} from "./useDecorators";
import {AnyDecorator} from "../../interfaces/AnyDecorator";
import {Store} from "../../domain/Store";

describe("useDecorators", () => {
function decorator1(value: any) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import {Store, StoreFn, useDecorators, useMethodDecorator, useMethodDecorators} from "@tsed/core";
import {StoreFn} from "../../decorators/storeFn";
import {Store} from "../../domain/Store";
import {useDecorators} from "./useDecorators";
import {useMethodDecorator, useMethodDecorators} from "./useMethodDecorators";

describe("useMethodDecorators", () => {
it("should apply all decorators", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/imports/importPackage.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {catchAsyncError} from "../catchError";
import {importPackage} from "./importPackage";
import {catchAsyncError} from "@tsed/core";

describe("importPackage", () => {
it("should load package util", async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/objects/cleanObject.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {cleanObject} from "@tsed/core";
import {cleanObject} from "./cleanObject";

describe("cleanObject", () => {
it("should clean undefined value from object", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {getConstructorArgNames} from "@tsed/core";
import {getConstructorArgNames} from "./getConstructorArgNames";

describe("getConstructorArgNames", () => {
it("should return the constructor args names", () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/utils/objects/getEnumerableKeys.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Enumerable, getEnumerableKeys} from "@tsed/core";
import {Enumerable} from "../../decorators/enumerable";
import {getEnumerableKeys} from "./getEnumerableKeys";

describe("getEnumerableKeys", () => {
it("should return enumerable keys", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/objects/isClass.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {isClass} from "@tsed/core";
import {isClass} from "./isClass";

describe("isClass", () => {
it("should test if a value is a class", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/objects/isEmpty.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {isEmpty} from "@tsed/core";
import {isEmpty} from "./isEmpty";

describe("isEmpty", () => {
it("should return true", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/objects/isNil.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {isNil} from "@tsed/core";
import {isNil} from "./isNil";

describe("isNil", () => {
it("should return true", () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/utils/objects/isPlainObject.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {isPlainObject} from "@tsed/core";
import {isPlainObject} from "./isPlainObject";

describe("isPlainObject", () => {
it("should test if the value is a plain object", () => {
expect(isPlainObject({})).toEqual(true);
expect(isPlainObject(class {})).toEqual(false);
expect(isPlainObject(new (class {})())).toEqual(false);
expect(isPlainObject(Object)).toEqual(false);
});
});
2 changes: 1 addition & 1 deletion packages/core/src/utils/objects/isPrimitive.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {isPrimitive, isPrimitiveClass} from "@tsed/core";
import {isPrimitive, isPrimitiveClass} from "./isPrimitive";

describe("isPrimitive", () => {
it("should test if an variable content is a primitive", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/objects/isSerializable.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {isSerializable} from "@tsed/core";
import {isSerializable} from "./isSerializable";

describe("isSerializable()", () => {
it("should return the expected value", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/objects/isSymbol.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {isSymbol, isSymbolOrSymbolClass} from "@tsed/core";
import {isSymbol, isSymbolOrSymbolClass} from "./isSymbol";

describe("isSymbol()", () => {
it("should validate value", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/proxyDelegation.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {proxyDelegation} from "@tsed/core";
import {proxyDelegation} from "./proxyDelegation";

describe("proxyDelegation", () => {
it("should create proxy delegation with internal map", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/di/src/decorators/__mock__/lazy.import.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Injectable} from "@tsed/di";
import {Injectable} from "../injectable";

@Injectable()
export class MyLazyModule {
Expand Down
3 changes: 2 additions & 1 deletion packages/di/src/decorators/__mock__/lazy.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {Injectable} from "@tsed/di";
import {Injectable} from "../injectable";

@Injectable()
export class MyLazyModule {
called = false;

$onInit() {
this.called = true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Injectable} from "@tsed/di";
import {Injectable} from "../injectable";

@Injectable()
export class MyLazyModule {
Expand Down
6 changes: 5 additions & 1 deletion packages/di/src/decorators/configuration.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import {Store} from "@tsed/core";
import {Container, GlobalProviders, Injectable, InjectorService, Provider} from "@tsed/di";
import {Container} from "../domain/Container";
import {Provider} from "../domain/Provider";
import {GlobalProviders} from "../registries/GlobalProviders";
import {InjectorService} from "../services/InjectorService";
import {Configuration} from "./configuration";
import {Injectable} from "./injectable";

describe("@Configuration", () => {
it("should declare a new provider with custom configuration", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/di/src/decorators/constant.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Store} from "@tsed/core";
import {Constant} from "../../src";
import {INJECTABLE_PROP} from "../constants/constants";
import {Constant} from "./constant";

class Test {}

Expand Down
6 changes: 4 additions & 2 deletions packages/di/src/decorators/controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {Controller} from "@tsed/common";
import {GlobalProviders, ProviderScope, ProviderType} from "@tsed/di";
import {ProviderScope} from "../domain/ProviderScope";
import {ProviderType} from "../domain/ProviderType";
import {GlobalProviders} from "../registries/GlobalProviders";
import {Controller} from "./controller";

class Test {}

Expand Down
8 changes: 5 additions & 3 deletions packages/di/src/decorators/inject.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {catchError, descriptorOf} from "@tsed/core";
import {Required} from "@tsed/schema";
import {Inject, Injectable, InjectorService, registerProvider} from "../../src";
import {descriptorOf} from "@tsed/core";
import {registerProvider} from "../registries/ProviderRegistry";
import {InjectorService} from "../services/InjectorService";
import {Inject} from "./inject";
import {Injectable} from "./injectable";

describe("@Inject()", () => {
describe("used on unsupported decorator type", () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/di/src/decorators/injectable.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Injectable} from "@tsed/di";
import * as ProviderRegistry from "../../src/registries/ProviderRegistry";
import {Injectable} from "../decorators/injectable";
import * as ProviderRegistry from "../registries/ProviderRegistry";

describe("@Injectable()", () => {
beforeEach(() => jest.spyOn(ProviderRegistry, "registerProvider"));
Expand Down
5 changes: 4 additions & 1 deletion packages/di/src/decorators/intercept.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {Store} from "@tsed/core";
import {InterceptorMethods, InterceptorContext, InjectablePropertyType, Intercept} from "../../src";
import {INJECTABLE_PROP} from "../constants/constants";
import {InjectablePropertyType} from "../domain/InjectablePropertyType";
import {InterceptorContext} from "../interfaces/InterceptorContext";
import {InterceptorMethods} from "../interfaces/InterceptorMethods";
import {Intercept} from "./intercept";

describe("@Intercept", () => {
it("should add interceptor on method", () => {
Expand Down
6 changes: 4 additions & 2 deletions packages/di/src/decorators/lazyInject.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {Injectable, InjectorService, LazyInject, OptionalLazyInject} from "@tsed/di";
import type {MyLazyModule} from "./__mock__/lazy.module";
import {catchAsyncError, classOf, nameOf} from "@tsed/core";
import {InjectorService} from "../services/InjectorService";
import type {MyLazyModule} from "./__mock__/lazy.module";
import {Injectable} from "./injectable";
import {LazyInject, OptionalLazyInject} from "./lazyInject";

describe("LazyInject", () => {
it("should lazy load module (import)", async () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/di/src/decorators/overrideProvider.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Sinon from "sinon";
import {GlobalProviders, Provider} from "../../src";
import {OverrideProvider} from "../../src/decorators/overrideProvider";
import {OverrideProvider} from "./overrideProvider";
import {Provider} from "../domain/Provider";
import {GlobalProviders} from "../registries/GlobalProviders";

describe("OverrideProvider", () => {
class Test {}
Expand Down
2 changes: 1 addition & 1 deletion packages/di/src/decorators/scope.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Store} from "@tsed/core";
import {Scope} from "../../src";
import {Scope} from "./scope";

class Test {}

Expand Down
8 changes: 7 additions & 1 deletion packages/di/src/decorators/useOpts.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import {descriptorOf} from "@tsed/core";
import {DITest, Inject, Injectable, Opts, ProviderScope, Scope, UseOpts} from "@tsed/di";
import {ProviderScope} from "../domain/ProviderScope";
import {DITest} from "../services/DITest";
import {Inject} from "./inject";
import {Injectable} from "./injectable";
import {Opts} from "./opts";
import {Scope} from "./scope";
import {UseOpts} from "./useOpts";

describe("UseOpts", () => {
let testContext: any;
Expand Down
2 changes: 1 addition & 1 deletion packages/di/src/decorators/value.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Store} from "@tsed/core";
import {Value} from "../../src";
import {Value} from "./value";
import {INJECTABLE_PROP} from "../constants/constants";

describe("@Value()", () => {
Expand Down
4 changes: 3 additions & 1 deletion packages/di/src/domain/Container.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {Container, Provider, ProviderType} from "../../src";
import {Container} from "./Container";
import {Provider} from "./Provider";
import {ProviderType} from "./ProviderType";

describe("Container", () => {
describe("getProvider()", () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/di/src/domain/ContextLogger.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {InjectorService, ContextLogger} from "@tsed/di";
import {InjectorService} from "../services/InjectorService";
import {ContextLogger} from "./ContextLogger";

function getIgnoreLogFixture(ignore: string[], url: string) {
const ignoreReg = ignore.map((pattern: string | RegExp) => (typeof pattern === "string" ? new RegExp(pattern, "gi") : pattern));
Expand Down
2 changes: 1 addition & 1 deletion packages/di/src/domain/ControllerProvider.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ProviderScope} from "@tsed/di";
import {ControllerProvider} from "./ControllerProvider";
import {ProviderScope} from "./ProviderScope";

class Test {}

Expand Down
Loading

0 comments on commit 544d6c4

Please sign in to comment.