scottohara / loot

An implementation of some of the core MS Money features in Ruby on Rails
MIT License
4 stars 3 forks source link

Cypress ignores user-supplied tsconfig.json file when running tests #180

Closed scottohara closed 3 years ago

scottohara commented 4 years ago

In 0b1b54c67a5b5f53841c26706e298b74999cb421 we removed @cypress/webpack-preprocessor in favour of native Typescript support introduced in Cypress v4.4.0.

Previously, the webpack config used by the preprocessor included:

resolve: {
    ...
    modules: [
        path.resolve(__dirname, "support"),
        ...
    ]
}

...to allow test files in /cypress/integration/* to resolve import specifiers relative to the /cypress/support/* directory, e.g.

// cypress/support/utils.ts
export function foo() { ... };

// cypress/integration/test.ts
import { foo } from "utils";  // <- webpack resolves this to cypress/support/utils.ts

The hope was that the existing config in cypress/tsconfig.json (already there for VS Code to resolve these paths) would achieve the same result:

{
  "compilerOptions": {
    "paths": {
        "*": [
            "cypress/support/*"
        ]
    },

Unfortunately it turns out that Cypress currently ignores the user-supplied tsconfig.json file, so any compiler options specified aren't actually used when building & running the tests.

Hopefully this will change with a future release of Cypress.

For now, the workaround was to change all imports to be relative to the current file, e.g.

// cypress/integration/test.ts
import { foo } from "../support/utils";

https://github.com/cypress-io/cypress/issues/7188