wallabyjs / public

Repository for Wallaby.js questions and issues
http://wallabyjs.com
758 stars 45 forks source link

Errors running WallabyJS for the first time #1978

Closed dbigintonpro closed 5 years ago

dbigintonpro commented 5 years ago

I am currently reviewing the rollout of WallabyJS for a number of applications however, I am having trouble getting it to work.

It should be noted that I am running in an Angular 7 NX workspace with multiple apps and libs.

Code editor or IDE name and version

Visual Studio Code v1.30.2

OS name and version

Windows 10

Wallaby.js configuration file

The errors received when running the wallaby.js configuration file are below.

[Info]​​​​​ Mon, 21 Jan 2019 21:43:21 GMT wallaby:middleware Preparing to serve /jasmine@2.1.3/starter.js
​​​​​[Info]​​​​​ Mon, 21 Jan 2019 21:43:21 GMT wallaby:middleware Serving /jasmine@2.1.3/starter.js from disk
​​​​​[Info]​​​​​ Mon, 21 Jan 2019 21:43:21 GMT wallaby:workers Sandbox (active) [b8tjg] error: Uncaught Error: Cannot find module 'core-js/es6/reflect'
​​[Error] Runtime error: Uncaught Error: Cannot find module 'core-js/es6/reflect'​​
​​[Error] at http://localhost:55787/____wallaby-bundle.js?1548107000963&wallabyFileId=bundle:4​​
​​​​​[Info]​​​​​ Mon, 21 Jan 2019 21:43:21 GMT wallaby:workers Sandbox (active) [b8tjg] error: Uncaught Error: Cannot find module '@angular/core/testing'
​​[Error] Runtime error: Uncaught Error: Cannot find module '@angular/core/testing'​​
​​[Error] at http://localhost:55787/apps/documents/src/app/app.component.spec.js.wbp.js?1548107000932&wallabyFileId=40:4​​
​​​​​[Info]​​​​​ Mon, 21 Jan 2019 21:43:21 GMT wallaby:workers [b8tjg] Loaded 0 test(s)
​​​​​[Info]​​​​​ Mon, 21 Jan 2019 21:43:21 GMT wallaby:workers [b8tjg] Run 0 test(s), skipped 0 test(s)
​​​​​[Info]​​​​​ Mon, 21 Jan 2019 21:43:21 GMT wallaby:workers [b8tjg] Sandbox is responsive, closing it
​​​​​[Info]​​​​​ Mon, 21 Jan 2019 21:43:21 GMT wallaby:project Test run finished
​​​​​[Info]​​​​​ Mon, 21 Jan 2019 21:43:21 GMT wallaby:project Processed console.log entries
​​​​​[Info]​​​​​ Mon, 21 Jan 2019 21:43:21 GMT wallaby:project Processed loading sequences
​​​​​[Info]​​​​​ Mon, 21 Jan 2019 21:43:21 GMT wallaby:project Processed executed tests
​​​​​[Info]​​​​​ Mon, 21 Jan 2019 21:43:21 GMT wallaby:project Processed code coverage
​​​​​[Info]​​​​​ Mon, 21 Jan 2019 21:43:21 GMT wallaby:project Test run result processed and sent to IDE

These are the only 2 errors received.

Below are the dependencies from package.json

"dependencies": {
    "@angular/animations": "^7.1.0",
    "@angular/cdk": "~7.2.0",
    "@angular/common": "^7.1.4",
    "@angular/compiler": "^7.1.0",
    "@angular/core": "^7.1.0",
    "@angular/forms": "^7.1.0",
    "@angular/material": "^7.0.3",
    "@angular/platform-browser": "^7.1.0",
    "@angular/platform-browser-dynamic": "^7.1.0",
    "@angular/pwa": "^0.11.4",
    "@angular/router": "^7.1.0",
    "@ngrx/effects": "7.0.0",
    "@ngrx/router-store": "7.0.0",
    "@ngrx/store": "7.0.0",
    "@nrwl/nx": "7.1.1",
    "core-js": "^2.5.4",
    "hammerjs": "^2.0.8",
    "rxjs": "^6.0.0",
    "tachyons": "4.11.1",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.12.2",
    "@angular-devkit/build-ng-packagr": "~0.11.4",
    "@angular/cli": "7.1.4",
    "@angular/compiler-cli": "^7.1.0",
    "@angular/language-service": "^7.1.0",
    "@compodoc/compodoc": "^1.1.6",
    "@ngrx/store-devtools": "7.0.0",
    "@nrwl/schematics": "7.1.1",
    "@types/jasmine": "~3.3.4",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~10.12.18",
    "angular2-template-loader": "^0.6.2",
    "codelyzer": "~4.5.0",
    "electron": "^4.0.1",
    "husky": "^1.1.4",
    "jasmine-core": "~3.3.0",
    "jasmine-marbles": "0.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~3.1.4",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "kss": "^3.0.0-beta.23",
    "michelangelo": "^0.8.0",
    "ng-packagr": "^4.2.0",
    "ngrx-store-freeze": "0.2.4",
    "prettier": "1.15.3",
    "pretty-quick": "^1.8.0",
    "protractor": "~5.4.0",
    "stylelint": "^9.8.0",
    "stylelint-config-standard": "^18.2.0",
    "ts-node": "~7.0.0",
    "tsickle": ">=0.29.0",
    "tslib": "^1.9.0",
    "tslint": "~5.12.0",
    "typescript": ">=3.1.6 <3.2",
    "wallaby-webpack": "^3.9.13"
  }

Your help would be greatly appreciated.

smcenlly commented 5 years ago

Can you please provide us with your wallaby configuration file?

dbigintonpro commented 5 years ago

Absolutely, see below

WallabyTest.ts

import 'core-js/es6/reflect';
import 'core-js/es7/reflect';
import 'zone.js/dist/zone';
import 'zone.js/dist/long-stack-trace-zone';
import 'zone.js/dist/proxy.js';
import 'zone.js/dist/sync-test';
import 'zone.js/dist/jasmine-patch';
import 'zone.js/dist/async-test';
import 'zone.js/dist/fake-async-test';

import { getTestBed } from '@angular/core/testing';
import {
  BrowserDynamicTestingModule,
  platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';

getTestBed().initTestEnvironment(
  BrowserDynamicTestingModule,
  platformBrowserDynamicTesting()
);

Wallaby.js

var wallabyWebpack = require('wallaby-webpack');
var path = require('path');

var compilerOptions = Object.assign(
  require('./tsconfig.json').compilerOptions,
  // require('./apps/**/tsconfig.spec.json').compilerOptions,
  require('./libs/core/tsconfig.spec.json').compilerOptions
);

module.exports = function(wallaby) {
  var webpackPostprocessor = wallabyWebpack({
    entryPatterns: ['wallabyTest.js', 'apps/**/*spec.js', 'libs/**/*spec.js'],
    emitModulePaths: true,

    module: {
      rules: [
        { test: /\.css$/, loader: ['raw-loader', 'css-loader'] },
        { test: /\.html$/, loader: 'raw-loader' },
        {
          test: /\.ts$/,
          loader: '@ngtools/webpack',
          include: /node_modules/,
          query: { tsConfigPath: 'tsconfig.json' }
        },
        {
          test: /\.js$/,
          loader: 'angular2-template-loader',
          exclude: /node_modules/
        },
        { test: /\.js$/, loader: 'shebang-loader', include: /node_modules/ },
        { test: /\.json$/, loader: 'json-loader' },
        { test: /\.styl$/, loaders: ['raw-loader', 'stylus-loader'] },
        { test: /\.less$/, loaders: ['raw-loader', 'less-loader'] },
        { test: /\.scss$|\.sass$/, loaders: ['raw-loader', 'sass-loader'] },
        { test: /\.(jpg|png)$/, loader: 'url-loader?limit=128000' }
      ]
    },

    resolve: {
      extensions: ['.js', '.ts'],
      modules: [
        path.join(wallaby.projectCacheDir, 'apps'),
        path.join(wallaby.projectCacheDir, 'libs'),
        'node_modules'
      ],
      alias: {
        '@lazard/core': path.join(
          wallaby.projectCacheDir,
          'libs/core/src/index.ts'
        )
      }
    },
    node: {
      fs: 'empty',
      net: 'empty',
      tls: 'empty',
      dns: 'empty'
    }
  });

  return {
    files: [
      { pattern: 'wallabyTest.ts', load: false },
      {
        pattern: 'apps/**/*.+(ts|css|less|scss|sass|styl|html|json|svg)',
        load: false
      },
      { pattern: 'apps/**/*.d.ts', ignore: true },
      { pattern: 'apps/**/*spec.ts', ignore: true },
      {
        pattern: 'libs/**/*.+(ts|css|less|scss|sass|styl|html|json|svg)',
        load: false
      },
      { pattern: 'libs/**/*.d.ts', ignore: true },
      { pattern: 'libs/**/*spec.ts', ignore: true },
      { pattern: 'apps/**/*-e2e/**', ignore: true },
      { pattern: 'libs/**/*-e2e/**', ignore: true }
    ],

    tests: [
      { pattern: 'apps/**/*spec.ts', load: false },
      { pattern: 'libs/**/*spec.ts', load: false },
      { pattern: 'apps/**/*-e2e/**', ignore: true },
      { pattern: 'libs/**/*-e2e/**', ignore: true }
    ],

    testFramework: 'jasmine',

    compilers: {
      '**/*.ts': wallaby.compilers.typeScript(compilerOptions)
    },

    env: {
      kind: 'electron'
    },

    postprocessor: webpackPostprocessor,

    workers: {initial: 1, regular: 1},
    debug: true,

    setup: function() {
      window.__moduleBundler.loadTests();
    }
  };
};

It seems that all the imports define in WallabyTest.ts cannot be found, for example, if i comment out the first, and attempt to run, the error is reproduced with the first uncommented import.

dbigintonpro commented 5 years ago

OK, partly a mistake by me, I was referencing WallabyTest.js but had my file named as WallabyTest.ts. This is now corrected to WallabyTest.js and the imports are no longer failing, except I now have an error relating to protractor, as shown below:

[Info]​​​​​ Tue, 22 Jan 2019 00:25:19 GMT wallaby:middleware Preparing to serve /jasmine@2.1.3/starter.js
​​​​​[Info]​​​​​ Tue, 22 Jan 2019 00:25:19 GMT wallaby:middleware Serving /jasmine@2.1.3/starter.js from disk
​​​​​[Info]​​​​​ Tue, 22 Jan 2019 00:25:19 GMT wallaby:workers Sandbox (active) [t63h9] error: Uncaught Error: Cannot find module 'protractor'
​​[Error] Runtime error: Uncaught Error: Cannot find module 'protractor'​​
​​[Error] at http://localhost:62920/____wallaby-bundle.js?1548116718726&wallabyFileId=bundle:320​​
​​​​​[Info]​​​​​ Tue, 22 Jan 2019 00:25:19 GMT wallaby:workers [t63h9] Loaded 0 test(s)
​​​​​[Info]​​​​​ Tue, 22 Jan 2019 00:25:19 GMT wallaby:workers [t63h9] Run 0 test(s), skipped 0 test(s)
​​​​​[Info]​​​​​ Tue, 22 Jan 2019 00:25:19 GMT wallaby:workers [t63h9] Sandbox is responsive, closing it
​​​​​[Info]​​​​​ Tue, 22 Jan 2019 00:25:19 GMT wallaby:project Test run finished
​​​​​[Info]​​​​​ Tue, 22 Jan 2019 00:25:19 GMT wallaby:project Processed console.log entries
​​​​​[Info]​​​​​ Tue, 22 Jan 2019 00:25:19 GMT wallaby:project Processed loading sequences
​​​​​[Info]​​​​​ Tue, 22 Jan 2019 00:25:19 GMT wallaby:project Processed executed tests
​​​​​[Info]​​​​​ Tue, 22 Jan 2019 00:25:19 GMT wallaby:project Processed code coverage
​​​​​[Info]​​​​​ Tue, 22 Jan 2019 00:25:19 GMT wallaby:project Test run result processed and sent to IDE

Any thoughts?

smcenlly commented 5 years ago

It looks like some of your e2e tests are still being included in either your files section or your tests section. Take a look at which of your files are referencing protractor and make sure that they're not being included by your files or tests patterns.

dbigintonpro commented 5 years ago

Thanks. I've made some adjustments to the wallaby.js config file:

Protractor is no longer in error. I now receive the following:

[Error] ​​Postprocessor run failure: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.​​
[Error] ​​ - configuration.entry should be one of these:​​
[Error] ​​   function | object { <key>: non-empty string | [non-empty string] } | non-empty string | [non-empty string]​​
[Error] ​​   -> The entry point(s) of the compilation.​​
[Error] ​​   Details:​​
[Error] ​​    * configuration.entry should be an instance of function​​
[Error] ​​      -> A Function returning an entry object, an entry string, an entry array or a promise to these things.​​
[Error] ​​    * configuration.entry should not be empty.​​
[Error] ​​      -> Multiple entry bundles are created. The key is the chunk name. The value can be a string or an array.​​
[Error] ​​    * configuration.entry should be a string.​​
[Error] ​​      -> An entry point without name. The string is resolved to a module which is loaded upon startup.​​
[Error] ​​    * configuration.entry should be an array:​​
[Error] ​​      [non-empty string]​​

Update wallaby.js config file:

var wallabyWebpack = require('wallaby-webpack');
var path = require('path');

var compilerOptions = Object.assign(
  require('./tsconfig.json').compilerOptions,
  // require('./apps/**/tsconfig.spec.json').compilerOptions,
  require('./libs/core/tsconfig.spec.json').compilerOptions
);

var patterns = [
  'apps/*/src/**/*spec.ts', 'libs/*/src/**/*spec.ts', // run all tests
  // 'apps/app1/src/**/*spec.js',                     // run test just for app1
  // 'libs/lib2/src/**/*spec.js',                     // run test just for lib2
];

module.exports = function(wallaby) {
  var webpackPostprocessor = wallabyWebpack({
    entryPatterns: [ 'wallabyTest.js', ...patterns ],
    emitModulePaths: true,

    module: {
      rules: [
        { test: /\.css$/, loader: ['raw-loader', 'css-loader'] },
        { test: /\.html$/, loader: 'raw-loader' },
        {
          test: /\.ts$/,
          loader: '@ngtools/webpack',
          include: /node_modules/,
          query: { tsConfigPath: 'tsconfig.json' }
        },
        {
          test: /\.js$/,
          loader: 'angular2-template-loader',
          exclude: /node_modules/
        },
        { test: /\.js$/, loader: 'shebang-loader', include: /node_modules/ },
        { test: /\.json$/, loader: 'json-loader' },
        { test: /\.styl$/, loaders: ['raw-loader', 'stylus-loader'] },
        { test: /\.less$/, loaders: ['raw-loader', 'less-loader'] },
        { test: /\.scss$|\.sass$/, loaders: ['raw-loader', 'sass-loader'] },
        { test: /\.(jpg|png)$/, loader: 'url-loader?limit=128000' }
      ]
    },

    resolve: {
      extensions: ['.js', '.ts'],
      modules: [
        path.join(wallaby.projectCacheDir, 'apps'),
        path.join(wallaby.projectCacheDir, 'libs'),
        'node_modules'
      ],
      alias: {
        '@lazard/core': path.join(
          wallaby.projectCacheDir,
          'libs/core/src/index.ts'
        )
      }
    },
    node: {
      fs: 'empty',
      net: 'empty',
      tls: 'empty',
      dns: 'empty'
    }
  });

  return {
    files: [
      { pattern: 'wallabyTest.ts', load: false },
      { pattern: 'apps/**/*.+(ts|css|less|scss|sass|styl|html|json|svg)', load: false },
      { pattern: 'apps/**/*.d.ts', ignore: true },
      // { pattern: 'apps/**/*spec.ts', ignore: true },
      { pattern: 'apps/*/src/**/*.spec.ts', ignore: true },
      { pattern: 'libs/**/*.+(ts|css|less|scss|sass|styl|html|json|svg)', load: false },
      { pattern: 'libs/**/*.d.ts', ignore: true },
      // { pattern: 'libs/**/*spec.ts', ignore: true },
      { pattern: 'libs/*/src/**/*.spec.ts', ignore: true },
    ],

    tests: [
      // { pattern: 'apps/**/*.spec.ts', load: false },
      { pattern: 'apps/*/src/**/*.spec.ts', load: false },
      // { pattern: 'apps/**/e2e/**', ignore: true },
      // { pattern: 'libs/**/*.spec.ts', load: false },
      { pattern: 'libs/*/src/**/*.spec.ts', load: false },
      // { pattern: 'libs/**/e2e/**', ignore: true },
    ],

    testFramework: 'jasmine',

    compilers: {
      '**/*.ts': wallaby.compilers.typeScript(compilerOptions)
    },

    env: {
      kind: 'electron'
    },

    postprocessor: webpackPostprocessor,

    workers: {initial: 1, regular: 1},
    debug: true,

    setup: function() {
      window.__moduleBundler.loadTests();
    }
  };
};
ArtemGovorov commented 5 years ago

It looks like your entryPatterns in the webpack config are using .ts file extension, but are supposed to be using .js extension as in your previous config version.

Also your tests patterns: apps/*/src/**/*.spec.ts and libs/*/src/**/*.spec.ts may not be correct (ie. not finding any files). Please double check them as well.

dbigintonpro commented 5 years ago

Thanks @ArtemGovorov & @smcenlly,

Your prompts have pointed me in the right direction and I have managed to get the testing with Wallaby to work.

Thanks again

ArtemGovorov commented 5 years ago

Awesome, thanks for the update!