diff --git a/packages/server/lib/util/ts-node.js b/packages/server/lib/util/ts-node.js index d44d07c4c0df..439bf6cb4f0c 100644 --- a/packages/server/lib/util/ts-node.js +++ b/packages/server/lib/util/ts-node.js @@ -27,6 +27,7 @@ const registerTsNode = (projectRoot, pluginsFile) => { debug('typescript path: %s', tsPath) debug('registering project TS with options %o', tsOptions) + require('tsconfig-paths/register') tsnode.register(tsOptions) } catch (err) { debug(`typescript doesn't exist. ts-node setup failed.`) diff --git a/packages/server/package.json b/packages/server/package.json index 11bebeedbc67..254aa0d77e0f 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -178,6 +178,7 @@ "supertest-session": "4.0.0", "through2": "2.0.5", "ts-loader": "7.0.4", + "tsconfig-paths": "3.9.0", "webpack": "4.43.0", "ws": "5.2.2", "xvfb": "cypress-io/node-xvfb#22e3783c31d81ebe64d8c0df491ea00cdc74726a", diff --git a/packages/server/test/e2e/1_typescript_spec_support_spec.ts b/packages/server/test/e2e/1_typescript_spec_support_spec.ts index 82dfa6f8fdfa..8c85f5ff1ac7 100644 --- a/packages/server/test/e2e/1_typescript_spec_support_spec.ts +++ b/packages/server/test/e2e/1_typescript_spec_support_spec.ts @@ -29,6 +29,9 @@ describe('e2e typescript in spec and support file', function () { }) }) + // this covers spec/support files as well as the plugins file + // @see https://github.com/cypress-io/cypress/issues/7006 + // @see https://github.com/cypress-io/cypress/issues/8555 it('respects tsconfig paths', function () { return e2e.exec(this, { project: Fixtures.projectPath('ts-proj-with-paths'), diff --git a/packages/server/test/support/fixtures/projects/ts-proj-with-paths/cypress.json b/packages/server/test/support/fixtures/projects/ts-proj-with-paths/cypress.json index be9e6bf4576b..0967ef424bce 100644 --- a/packages/server/test/support/fixtures/projects/ts-proj-with-paths/cypress.json +++ b/packages/server/test/support/fixtures/projects/ts-proj-with-paths/cypress.json @@ -1,4 +1 @@ -{ - "supportFile": false, - "pluginsFile": false -} +{} diff --git a/packages/server/test/support/fixtures/projects/ts-proj-with-paths/cypress/plugins/index.ts b/packages/server/test/support/fixtures/projects/ts-proj-with-paths/cypress/plugins/index.ts new file mode 100644 index 000000000000..037720a88e4e --- /dev/null +++ b/packages/server/test/support/fixtures/projects/ts-proj-with-paths/cypress/plugins/index.ts @@ -0,0 +1,7 @@ +import { appName } from '@app/main' + +if (appName !== 'Best App Ever') { + throw new Error('Path alias not working properly in plugins file!') +} + +export default () => {} diff --git a/packages/server/test/support/fixtures/projects/ts-proj-with-paths/cypress/support/index.ts b/packages/server/test/support/fixtures/projects/ts-proj-with-paths/cypress/support/index.ts new file mode 100644 index 000000000000..b45bd0d4b86a --- /dev/null +++ b/packages/server/test/support/fixtures/projects/ts-proj-with-paths/cypress/support/index.ts @@ -0,0 +1,5 @@ +import { appName } from '@app/main' + +if (appName !== 'Best App Ever') { + throw new Error('Path alias not working properly in support file!') +} diff --git a/yarn.lock b/yarn.lock index 4f6056c92a5a..a1bf08712985 100644 --- a/yarn.lock +++ b/yarn.lock @@ -24475,7 +24475,7 @@ tsconfig-paths-webpack-plugin@^3.3.0: enhanced-resolve "^4.0.0" tsconfig-paths "^3.4.0" -tsconfig-paths@^3.4.0: +tsconfig-paths@3.9.0, tsconfig-paths@^3.4.0: version "3.9.0" resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.9.0.tgz#098547a6c4448807e8fcb8eae081064ee9a3c90b" integrity sha512-dRcuzokWhajtZWkQsDVKbWyY+jgcLC5sqJhg2PSgf4ZkH2aHPvaOY8YWGhmjb68b5qqTfasSsDO9k7RUiEmZAw==