【问题标题】:Unable to debug a TypeScript e2e testing framework using Visual Studio Code无法使用 Visual Studio Code 调试 TypeScript e2e 测试框架
【发布时间】:2019-04-02 12:40:15
【问题描述】:

我无法在 VSCode 上进行 E2E 测试框架的调试。仅显示此消息 - 等待调试器断开连接。

但是,我能够调试并运行一个简单的 TS 代码。我开始怀疑我是否朝着正确的方向前进。

下面是不工作和工作项目的 tsconfig.json、package.json 和 launch.json。

框架接近量角器提供的框架。使用

安装量角器
npm install -g protractor

您将在 node_modules\protractor\exampleTypescript 中看到框架

tsconfig.json

{
  "compilerOptions": {
    "outDir": "tmp",
    "rootDir": "./",
    "sourceMap": true,
    "module": "commonjs",
    "moduleResolution": "node",
    "target": "es2017",
    "types": ["jasmine", "jasminewd2", "node"]
  },

  "exclude": [
    "node_modules",
    "asyncAwait",
    "plugins.ts"
  ]
}

package.json

{
  "name": "org_abc",
  "version": "1.0.0",
  "description": "org_abc_e2e automation tests",
  "author": "org_abc",
  "main": "./conf.ts",
  "license": "org_abc",
  "scripts": {
    "webdriver-update": "npx webdriver-manager update",
    "prestart": "npm run build",
    "build": "tsc",
    "tsc": "tsc",
    "test": "npm run tsc && protractor tmp/conf.js" 

  },
  "dependencies": {
    "@types/jasmine": "^2.8.9",
    "@types/jasminewd2": "^2.0.4",
    "@types/node": "^10.12.0",
    "adm-zip": "0.4.7",
    "chance": "^1.0.16",
    "chromedriver": "^2.41",
    "colors": "1.1.2",
    "geckodriver": "1.8.1",
    "jasmine": "^2.99.0",
    "jasmine-reporters": "2.2.1",
    "jasmine-spec-reporter": "4.2.1",
    "mocha": "^5.2.0",
    "protractor": "^5.4.1",
    "protractor-jasmine2-screenshot-reporter": "0.4.0",
    "selenium-server": "^3.13.0",
    "selenium-webdriver": "^4.0.0-alpha.1",
    "ts-node": "^7.0.1",
    "webdriver-manager": "^12.0.6",
    "xml2js": "~0.4.19"
  },
  "devDependencies": {
    "@types/jasmine": "^2.8.8",
    "@types/jasminewd2": "^2.0.4",
    "ts-node": "^7.0.1",
    "typescript": "^2.9.2",
    "yarn": "^1.10.1"
  }
}

launch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [{
        "type": "node",
        "request": "launch",
        "name": "XPIA",
        "program": "${workspaceFolder}\\conf.ts",
        "preLaunchTask": "npm: build",
        "sourceMaps": true,
        "smartStep": true,
        "internalConsoleOptions": "openOnSessionStart",
        "protocol": "auto",
        "args": ["${workspaceRoot}\\conf.ts"],
        "outFiles": [
            "${workspaceFolder}/tmp/**/*.js"
        ]
    }]
}

调试输出:

C:\Program Files\nodejs\node.exe --inspect-brk=31907 tmp\conf.js C:\Users\user_name\Documents\automation\conf.ts 
Debugger listening on ws://127.0.0.1:31907/5ffdafc9-39d4-4f1a-afad-2593d4adacd7
Debugger attached.
Waiting for the debugger to disconnect...

============================ 下面是一个简单的项目,我可以调试它:

在 VS Code 中,我创建了一个包含几个变量的 TS 文件,并且我能够进行调试。

tsconfig.json

{
    "compileOnSave": true,
    "compilerOptions": {
        "outDir": "./out",
        "rootDir": "./src",
        "sourceMap": true,
        "moduleResolution": "node",
        "target": "es5"
    }
}

package.json

{
  "name": "typescript-debugging",
  "version": "1.0.0",
  "description": "typescript-debugging-desc",
  "main": "src/app.ts",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node out/app.js",
    "prestart": "npm run build",
    "build": "tsc"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "typescript": "^3.1.3"
  }
}

launch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [{
        "type": "node",
        "request": "launch",
        "name": "Launch Program",
        "program": "${workspaceFolder}\\src\\app.ts",
        "preLaunchTask": "npm: build",
        "sourceMaps": true,
        "smartStep": true,
        "internalConsoleOptions": "openOnSessionStart",
        "outFiles": [
            "${workspaceFolder}/out/**/*.js"
        ]
    }]
}

【问题讨论】:

    标签: typescript visual-studio-code protractor vscode-settings e2e-testing


    【解决方案1】:

    这是一个正在运行的示例 launch.json

    {
        // Use IntelliSense to learn about possible attributes.
        // Hover to view descriptions of existing attributes.
        // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
        "version": "0.2.0",
        "configurations": [
            {
                "type": "node",
                "request": "launch",
                "name": "Launch Program",
                "stopOnEntry": false,
                "program": "${workspaceRoot}/node_modules/protractor/bin/protractor",  // path the protractor node modules.
                "args": [
                    "${workspaceRoot}/build/config/protractor.config.js" // path to compiled protractor configuration file.
                ],
                "preLaunchTask": null,
                "sourceMaps": true,
                "outFiles": [ "${workspaceRoot}/dist/e2e/**/*.js" ]
            }
        ]
    }
    

    【讨论】:

      猜你喜欢
      • 2017-12-18
      • 1970-01-01
      • 2016-12-29
      • 1970-01-01
      • 2020-06-09
      • 2012-11-19
      • 2021-11-26
      • 1970-01-01
      • 2023-03-17
      相关资源
      最近更新 更多