Orange-OpenSource / uuv

Solution to facilitate the writing and execution of E2E tests understandable by any human
https://orange-opensource.github.io/uuv/
MIT License
101 stars 16 forks source link

Unable to create custom step definitions - tsconfig issues #613

Closed MikeDabrowski closed 4 months ago

MikeDabrowski commented 5 months ago

Describe the bug I followed the docs but I am getting error "SyntaxError: Cannot use import statement outside a module", <Unable to read "C:\Users\AHTI\IdeaProjects\uuv-test\node_modules\ts-node\src\index.ts">

To Reproduce Steps to reproduce the behavior:

  1. Create blank npm project
  2. Add playwright, uuv, ts-node as docs says
  3. add custom step definitions
  4. run tests - they work
  5. add advanced ts-config and ts-config.e2e
  6. tests no longer work

Expected behavior I expected the tsconfig.e2e to be respected. It seems tests only run without tsconfig or when the config that is specified in the docs is the only config there.

I tried keeping my adv config and putting .e2e version next to it or in uuv folder. And as soon as I remove my config tests start working.

possible hints The error suggests that module resolution might be broken. And indeed - if I put "module": "commonjs", in my advanced config (and remove all other tsconfigs) the tests are running. This hints that the uuv/playwright does not read the tsconfig.e2e.json file and defaults to baseline.

Screenshots image
image

Desktop (please complete the following information):

Additional context Archive with repro
uuv-test.zip

luifr10 commented 5 months ago

Our bad, this part of the documentation is not up-to-date. Your have to replace the 2 import lines by the following one :

const { Given, When, Then } = require('@cucumber/cucumber');
const { expect } = require('@playwright/test');

I'll update the documentation

MikeDabrowski commented 5 months ago

Ouch, I am not sure if this is the right way to go. The tsconfig is clearly not used. Could you double check ts-node is being given it as a param?

luifr10 commented 5 months ago

Yes, you're right ! Here is the best solution with composite tsconfig file : tsconfig.json

{
    "references": [
        { "path": "./tsconfig.e2e.json" }, 
        { "path": "./tsconfig.app.json" }
    ]
}

tsconfig.app.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noFallthroughCasesInSwitch": true,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "strict": true,
    "strictNullChecks": true,
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "module": "es2020",
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "ES2022",
    "lib": [
      "es2019",
      "es2018",
      "es2015",
      "dom", "ES2020.Intl"
    ],
    "plugins": [
      {
        "name": "typescript-tslint-plugin",
        "alwaysShowRuleFailuresAsWarnings": false,
        "ignoreDefinitionFiles": true
      }
    ],
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "useDefineForClassFields": false,
    "composite": true
  },
  "angularCompilerOptions": {
    "preserveWhitespaces": false,
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true
  },
  "allowSyntheticDefaultImports": true,
  "include": [
    "src"
  ]
}

tsconfig.e2e.json

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "composite": true,
    "outDir": "./out-tsc/app",
    "types": [
      "@uuv/playwright"
    ]
  },
  "include": [
    "uuv/cucumber/step_definitions/**/*.ts"
  ],
  "references": [
    { "path": "./tsconfig.app.json" }
  ]
}
MikeDabrowski commented 5 months ago

I found this piece. I suspect this might be just for running the tests on UUV itself but if similar pattern (not parameterised tsconfig location) is used in other places it may be the issue. I did not find any other place where ts-node config could be used...

https://github.com/Orange-OpenSource/uuv/blob/9e2d84679d8147a7c4a4d90f528bdee4958ffca3/packages/runner-cypress/test.js#L17-L24

MikeDabrowski commented 5 months ago

Nah this solution is not viable for us. I spend whole week trying to convert the project to use it but still keeps failing.

Latest issue is that Error: error TS6304: Composite projects may not disable declaration emit. despite declaration: true

We will abandon uuv for now.