Skip to content

Commit

Permalink
refactor tests for es6
Browse files Browse the repository at this point in the history
es config updated for es6
ci for es6 test
  • Loading branch information
dcavanagh committed Apr 17, 2021
1 parent e02a2fa commit 7790cb2
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 70 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dts
lib
temp
es
es6
amd

type_definitions/inversify/*.js
Expand Down
17 changes: 7 additions & 10 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,18 @@
"name": "Mocha Tests",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"args": [
"-r",
"ts-node/register",
"--require",
"reflect-metadata",
"-u",
"tdd",
"--timeout",
"999999",
"--colors",
"${workspaceRoot}/test/**/*.test.js"
"${workspaceRoot}/test/**/*.test.ts"
],
"sourceMaps": true,
"outFiles": [
"${workspaceRoot}/test",
"${workspaceRoot}/src"
],
"internalConsoleOptions": "openOnSessionStart"
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"protocol": "inspector"
},
{
"type": "node",
Expand All @@ -49,4 +46,4 @@
"console": "internalConsole",
}
]
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
"jsnext:main": "es/inversify.js",
"types": "lib/inversify.d.ts",
"scripts": {
"build": "npm run build:lib && npm run build:amd && npm run build:es",
"build": "npm run build:lib && npm run build:amd && npm run build:es && npm run build:es6",
"build:lib": "tsc -p src/tsconfig.json",
"build:amd": "tsc -p src/tsconfig-amd.json",
"build:es": "tsc -p src/tsconfig-es.json",
"build:es6": "tsc -p src/tsconfig-es6.json",
"clean": "rm -r amd es lib",
"pretest": "tslint --project .",
"test": "nyc --require ts-node/register mocha test/**/*.test.ts --reporter spec --retries 3 --require 'node_modules/reflect-metadata/Reflect.js' --exit",
Expand Down
3 changes: 2 additions & 1 deletion src/tsconfig-es6.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"extends": "../tsconfig.json",
"compilerOptions": {
"target": "es6",
"outDir": "../es6"
"outDir": "../es6",
"module": "es6"
},
}
41 changes: 23 additions & 18 deletions test/bugs/issue_543.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,44 @@ describe("Issue 543", () => {
Root: Symbol.for("Root")
};

interface IIrrelevant {}

This comment has been minimized.

Copy link
@PodaruDragos

PodaruDragos Apr 17, 2021

Contributor

if we add eslint this is gonna throw an error for being an interface with no properties, same for the rest of the empty interfaces

This comment has been minimized.

Copy link
@notaphplover

notaphplover Apr 17, 2021

Member

We could use types instead or override eslint rules. As an example:

"overrides": [
    {
      "files": ["**/*.spec.ts"],
      "extends": [
        "plugin:jest/recommended",
        "plugin:jest/style"
      ],
      "rules": {
        "@typescript-eslint/unbound-method": "off",
        "@typescript-eslint/no-magic-numbers": "off"
      }
    },
    {
      "files": ["**/*InjectionTypes.ts"],
      "rules": {
        "@typescript-eslint/typedef": "off"
      }
    }
  ]

I use this config to disable some rules in my test modules

interface ICircular{}
interface IChild {}
interface IChild2 {}

@injectable()
class Irrelevant {}
class Irrelevant implements IIrrelevant {}

@injectable()
class Child2 {
public circ: unknown;
class Child2 implements IChild2 {
public circ: ICircular;
public constructor(
@inject(TYPE.Circular) circ: unknown
@inject(TYPE.Circular) circ: ICircular
) {
this.circ = circ;
}
}

@injectable()
class Child {
public irrelevant: unknown;
public child2: unknown;
class Child implements IChild {
public irrelevant: IIrrelevant;
public child2: IChild2;
public constructor(
@inject(TYPE.Irrelevant) irrelevant: unknown,
@inject(TYPE.Child2) child2: unknown
@inject(TYPE.Irrelevant) irrelevant: IIrrelevant,
@inject(TYPE.Child2) child2: IChild2
) {
this.irrelevant = irrelevant;
this.child2 = child2;
}
}

@injectable()
class Circular {
public irrelevant: unknown;
public child: unknown;
class Circular implements Circular {
public irrelevant: IIrrelevant;
public child: IChild;
public constructor(
@inject(TYPE.Irrelevant) irrelevant: unknown,
@inject(TYPE.Child) child: unknown
@inject(TYPE.Irrelevant) irrelevant: IIrrelevant,
@inject(TYPE.Child) child: IChild
) {
this.irrelevant = irrelevant;
this.child = child;
Expand All @@ -55,11 +60,11 @@ describe("Issue 543", () => {

@injectable()
class Root {
public irrelevant: unknown;
public circ: unknown;
public irrelevant: IIrrelevant;
public circ: ICircular;
public constructor(
@inject(TYPE.Irrelevant) irrelevant1: unknown,
@inject(TYPE.Circular) circ: unknown
@inject(TYPE.Irrelevant) irrelevant1: IIrrelevant,
@inject(TYPE.Circular) circ: ICircular
) {
this.irrelevant = irrelevant1;
this.circ = circ;
Expand Down
11 changes: 7 additions & 4 deletions test/bugs/issue_549.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,24 @@ describe("Issue 549", () => {
BDynamicValue: Symbol.for("BDynamicValue")
};

interface IA {}
interface IB {}

@injectable()
class A {
public b: unknown;
public b: IB;
public constructor(
@inject(TYPE.BDynamicValue) b: unknown
@inject(TYPE.BDynamicValue) b: IB
) {
this.b = b;
}
}

@injectable()
class B {
public a: unknown;
public a: IA;
public constructor(
@inject(TYPE.ADynamicValue) a: unknown
@inject(TYPE.ADynamicValue) a: IA
) {
this.a = a;
}
Expand Down
32 changes: 16 additions & 16 deletions test/node/exceptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,39 @@ describe("Node", () => {

it("Should throw if circular dependencies found", () => {

interface A {}
interface B {}
interface C {}
interface D {}
interface IA {}
interface IB {}
interface IC {}
interface ID {}

@injectable()
class A implements A {
public b: unknown;
public c: unknown;
class A implements IA {
public b: IB;
public c: IC;
public constructor(
@inject("B") b: unknown,
@inject("C") c: unknown,
@inject("B") b: IB,
@inject("C") c: IC,
) {
this.b = b;
this.c = c;
}
}

@injectable()
class B implements B {}
class B implements IB {}

@injectable()
class C implements C {
public d: unknown;
public constructor(@inject("D") d: unknown) {
class C implements IC {
public d: ID;
public constructor(@inject("D") d: ID) {
this.d = d;
}
}

@injectable()
class D implements D {
public a: unknown;
public constructor(@inject("A") a: unknown) {
class D implements ID {
public a: IA;
public constructor(@inject("A") a: IA) {
this.a = a;
}
}
Expand Down
40 changes: 20 additions & 20 deletions test/planning/planner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,41 +120,41 @@ describe("Planner", () => {

it("Should throw when circular dependencies found", () => {

interface A { }
interface B { }
interface C { }
interface D { }
interface IA { }
interface IB { }
interface IC { }
interface ID { }

@injectable()
class D implements D {
public a: unknown;
class D implements ID {
public a: IA;
public constructor(
@inject("A") a: unknown
@inject("A") a: IA
) { // circular dependency
this.a = a;
}
}

@injectable()
class C implements C {
public d: unknown;
class C implements IC {
public d: ID;
public constructor(
@inject("D") d: unknown
@inject("D") d: ID
) {
this.d = d;
}
}

@injectable()
class B implements B { }
class B implements IB { }

@injectable()
class A implements A {
public b: unknown;
public c: unknown;
class A implements IA {
public b: IB;
public c: IC;
public constructor(
@inject("B") b: unknown,
@inject("C") c: unknown,
@inject("B") b: IB,
@inject("C") c: IC
) {
this.b = b;
this.c = c;
Expand All @@ -167,10 +167,10 @@ describe("Planner", () => {
const dId = "D";

const container = new Container();
container.bind<A>(aId).to(A);
container.bind<B>(bId).to(B);
container.bind<C>(cId).to(C);
container.bind<D>(dId).to(D);
container.bind<IA>(aId).to(A);
container.bind<IB>(bId).to(B);
container.bind<IC>(cId).to(C);
container.bind<ID>(dId).to(D);

const throwErrorFunction = () => {
container.get(aId);
Expand Down

0 comments on commit 7790cb2

Please sign in to comment.