angulare2e-testingtestcafeangular-e2e

Testcafe run failed (Angular 14.2.1)


I'm trying to run e2e testcases with testcafe in Angular 14.2.1. For the setup I have used the mentioned documentation from the testcafe page: https://medium.com/test-automation-pro/testcafe-tests-in-an-angular-project-e1d1ccc6e1cb

But the e2e run is failing:

> angular@0.0.0 e2e
> ng e2e e2e-project

Testcafe run failed!!! error: this._init is not a function
this._init is not a function
(node:16504) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.
(Use `node --trace-warnings ...` to show where the warning was created)

Process finished with exit code 1

My angular.json

"e2e-project": {
  "architect": {
    "e2e": {
      "builder": "angular-testcafe:testcafe",
      "options": {
        "browsers": [
          "chrome --no-sandbox",
          "firefox"
        ],
        "src": "e2e/src/*.e2e-spec.ts",
        "host": "localhost",
        "reporters": [
          {
            "name": "spec"
          }
        ]
      }
    }
  },
  "projectType": "application",
  "root": ""
},

My package.json

"devDependencies": {
  "@angular-devkit/build-angular": "^14.2.1",
  "@angular/cli": "^14.2.1",
  "@angular/compiler-cli": "^14.2.0",
  "@angular/language-service": "^14.2.0",
  "@types/jasmine": "^4.0.3",
  "@types/jasminewd2": "^2.0.10",
  "@types/node": "^17.0.24",
  "angular-testcafe": "^3.0.0",
  "codelyzer": "^6.0.2",
  "jasmine-core": "~4.1.0",
  "jasmine-spec-reporter": "~7.0.0",
  "karma": "^6.3.18",
  "karma-chrome-launcher": "^3.1.1",
  "karma-coverage-istanbul-reporter": "~3.0.3",
  "karma-jasmine": "^5.0.0",
  "karma-jasmine-html-reporter": "^1.7.0",
  "protractor": "^7.0.0",
  "testcafe": "^15.1.317922",
  "testcafe-angular-selectors": "^0.4.1",
  "testcafe-reporter-html": "^1.4.6",
  "ts-node": "~10.7.0",
  "tslint": "~6.1.3",
  "typescript": "~4.6.3"
}

My first testcase

import { fixture, test } from 'testcafe'; // <- manually added, without the import it showed that the functions are not available

fixture('Passing').page('http://localhost:4200');

test('foo equals foo', async t => await t.expect('foo').eql('foo'));

When running it without Angular:

PS D:\workspaces\XXX\src\main\angular> testcafe chrome .\e2e\src\getting-started.js
Using locally installed version of TestCafe.
D:\workspaces\XXXX\src\main\angular\node_modules\brotli\build\encode.js:3
1<process.argv.length?process.argv[1].replace(/\\/g,"/"):"unknown-program");b.arguments=process.argv.slice(2);"undefined"!==typeof module&&(module.exports=b);process.on("uncaughtException",function(a){if(!(a instanceof y))throw a;});b.inspect=function(){return"[Emscripten Module object]"}}else if(x)b.print||(b.print=print),"undefined"!=typeof printErr&&(b.printErr=printErr),b.read="undefined"!=typeof read?read:function(){throw"no read() available (jsc?)";},b.readBinary=function(a){if("function"===
                                                                                                                                                                                                                              ^

TypeError: util.error is not a function
    at Cli._fatalError (D:\workspaces\XXX\src\main\angular\node_modules\testcafe\lib\cli\cli.js:33:10)
    at Cli._buildTasks (D:\workspaces\XXX\src\main\angular\node_modules\testcafe\lib\cli\cli.js:123:18)
    at Cli.execute (D:\workspaces\XXX\src\main\angular\node_modules\testcafe\lib\cli\cli.js:19:10)
    at Object.<anonymous> (D:\workspaces\XXX\src\main\angular\node_modules\testcafe\lib\cli\index.js:1:26)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12)
    at Module.require (node:internal/modules/cjs/loader:1061:19)
    at require (node:internal/modules/cjs/helpers:103:18)

Node.js v18.12.1    

I've reinstalled all packages from the project and also installed testcafe globally again.


Solution

  • I'm not sure how this happened that the package version for testcafe was set to ^15.1.317922, but this was the issue. Using version 2.2.0 instead is the fix for my issue.

    package.json