jest-decorated icon indicating copy to clipboard operation
jest-decorated copied to clipboard

Annotations are not defined after updating to 0.1.1

Open amrsalem1 opened this issue 3 years ago • 7 comments

Screenshot 2021-11-01 at 11 21 40

in my jest config

    setupFilesAfterEnv: [
        './jest.setup.js'
        , "@jest-decorated/core/globals"
    ],

in my setup.ts

import "@jest-decorated/core/globals";

module.exports = async function () {
};

other dependencies

  "dependencies": {
    "@babel/core": "^7.11.1",
    "@babel/preset-env": "^7.11.0",
    "@babel/preset-typescript": "^7.10.4",
    "@jest-decorated/core": "^0.1.1",
    "@types/jest": "^27.0.2",
    "@types/node": "^14.0.23",
    "axios": "^0.21.1",
    "babel-jest": "^27.3.1",
    "expect-playwright": "^0.2.5",
    "jest": "^27.3.1",
    "jest-allure": "^0.1.3",
    "jest-circus": "^27.3.1",
    "jest-circus-allure-environment": "^0.13.3",
    "playwright": "^1.16.2"
  },

amrsalem1 avatar Nov 01 '21 10:11 amrsalem1

Hello, @amrsalem1 !

Thanks for reporting the issue, you're absolutely right. In this case, we need to help the TS and explicitly reference our typings. In your tsconfig.json try adding your jest setup file:

{
  "include": ["./setup.ts"]
}

or the jest-decorated lib itself:

{
  "include": ["node_modules/@jest-decorated/core"]
}

(another example here)

If I won't be able to find a workaround/solution for this by the end of this week, I'll update the README with this explanation

vitalishapovalov avatar Nov 01 '21 12:11 vitalishapovalov

@vitalishapovalov thanks for the workaround but it didn't help unfortunately, annotation still undefined

amrsalem1 avatar Nov 02 '21 11:11 amrsalem1

@amrsalem1

okay, seems like the only way we can make it work properly with TS/editor is:

  • in the jest-config -> setupFilesAfterEnv list we shouldn't include the jest-decorated lib itself; we need to create a separate .ts file (setup.ts), and include jest-decorated globals right inside that file (import "@jest-decorated/core/globals";)
{
  "setupFilesAfterEnv": ["<rootDir>/setup.ts"],
}
  • in tsconfig -> include we need to include the setup.ts file:
{
  "include": ["./setup.ts"],
}

If you've already tried this way, and it's still not working - may I take a look at folder structure, jest-config and tsconfig files?

vitalishapovalov avatar Nov 02 '21 15:11 vitalishapovalov

@amrsalem1

any success here?

please, also make sure that the tests directory itself is also included in tsconfig -> include list.

the final tsconfig -> include setup should look something like:

{
  "include": ["./setup.ts", "./__tests__"],
}

vitalishapovalov avatar Nov 07 '21 12:11 vitalishapovalov

upd: added Typescript section to docs here and here

vitalishapovalov avatar Nov 08 '21 06:11 vitalishapovalov

still facing same issue

here is my configs for jest

module.exports = {
    runner: "groups",
    testMatch: [
        "**/__tests__/**/*.+(ts|tsx|js)",
        "**/?(*.)+(spec|test).+(ts|tsx|js)"
    ],
    testRunner: "jest-circus/runner",
    globalSetup: '<rootDir>/setup.ts',
    globalTeardown: '<rootDir>/teardown.ts',
    setupFilesAfterEnv: [
        './jest.setup.js', "<rootDir>/setup.ts", "@jest-decorated/react/globals"
    ],
    include: ["./setup.ts"],
    testEnvironment: '<rootDir>/testEnvironment.js',
    moduleFileExtensions: ["js", "json", "jsx", "ts", "tsx", "node"],
    moduleDirectories: ["node_modules", "src", "./src/utils/checks"],
    verbose: false,
    reporters: [
        "default",
        // "<rootDir>/shiftReporter.ts"
    ]
};

setup.ts

import "@jest-decorated/core/globals";

module.exports = async function () {
};

error Screenshot 2021-11-16 at 10 14 26

my file structurer

Screenshot 2021-11-16 at 10 15 18

amrsalem1 avatar Nov 16 '21 09:11 amrsalem1

You've added include: ["./setup.ts"], to the jest.config.js, but it should be added to the tsconfig.json

Please, try adding include: ["./setup.ts"], to the tsconfig.json

vitalishapovalov avatar Nov 16 '21 16:11 vitalishapovalov