wallabyjs / public

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

Cannot read property '_jasmineAdapter' of undefined  #2187

Closed adover closed 5 years ago

adover commented 5 years ago

Issue description or question

Getting the above error. Have deleted an reinstalled node modules. Funnily enough it works with the same config on my personal laptop, but not on my work machine.

Wallaby.js configuration file

module.exports = function(wallaby) {
  return {
    files: [
      'tsconfig.json',
      'tsconfig.spec.json',
      'jest.config.js',
      'apps/**/*.+(ts|html|json|snap|css|less|sass|scss|jpg|jpeg|gif|png|svg)',
      '!apps/**/*.spec.ts',
      '!apps/**/*.stories.ts',
      '!apps/**/main.ts',
      'libs/**/*.+(ts|html|json|snap|css|less|sass|scss|jpg|jpeg|gif|png|svg)',
      '!libs/**/*.spec.ts',
      '!libs/**/*.stories.ts',
      '!libs/**/environment.*.ts',
      '!libs/**/environment.ts',
      '!apps/legacy-restyle/**/*.*',
    ],

    tests: [
      './apps/**/*.spec.ts',
      './libs/**/*.spec.ts',
      '!apps/pluto-e2e/**/*.spec.ts',
      '!apps/product-stamp-e2e/**/*.spec.ts',
    ],

    env: {
      type: 'node',
      runner: 'node',
      params: {
        runner: '--max-old-space-size=12288',
      },
    },

    debug: true,

    testFramework: 'jest',

    compilers: {
      '**/*.ts?(x)': wallaby.compilers.typeScript({
        module: 'commonjs',
        getCustomTransformers: () => {
          return {
            before: [
              require('jest-preset-angular/InlineHtmlStripStylesTransformer').factory(
                { compilerModule: require('typescript') }
              ),
            ],
          };
        },
      }),
      '**/*.html': file => ({
        code: require('ts-jest').process(file.content, file.path, {
          globals: {
            'ts-jest': {
              stringifyContentPathRegex: '\\.html$',
            },
          },
        }),
        map: { version: 3, sources: [], names: [], mappings: [] },
        ranges: [],
      }),
    },

    preprocessors: {
      '**/*.js': file =>
        require('@babel/core').transform(file.content, {
          sourceMap: true,
          compact: false,
          filename: file.path,
          presets: [require('babel-preset-jest')],
        }),
    },

    setup: function(wallaby) {
      let jestConfig = require('./jest.config');
      delete jestConfig.preset;
      jestConfig = Object.assign(
        require('jest-preset-angular/jest-preset'),
        jestConfig
      );
      jestConfig.transformIgnorePatterns.push('instrumented.*.(jsx?|html)$');
      jestConfig.rootDir = './';
      jestConfig.setupFilesAfterEnv = ['./apps/pluto/src/test-setup.ts'];

      jestConfig.transform = { '^.+\\.(ts)$': 'ts-jest' };

      wallaby.testFramework.configure(jestConfig);
    },
  };
};

package.json

{
  "dependencies": {
    "@angular/animations": "^8.1.1",
    "@angular/cdk": "^8.1.1",
    "@angular/common": "^8.1.1",
    "@angular/compiler": "^8.1.1",
    "@angular/core": "^8.1.1",
    "@angular/elements": "^8.0.0",
    "@angular/forms": "^8.1.1",
    "@angular/platform-browser": "^8.1.1",
    "@angular/platform-browser-dynamic": "^8.1.1",
    "@angular/router": "^8.1.1",
    "@commitlint/config-conventional": "^8.1.0",
    "@microsoft/applicationinsights-web": "^2.2.0",
    "@ngrx/effects": "8.1.0",
    "@ngrx/router-store": "8.1.0",
    "@ngrx/store": "8.1.0",
    "@nrwl/nx": "^7.8.7",
    "@webcomponents/custom-elements": "^1.2.4",
    "@webcomponents/webcomponentsjs": "^2.2.10",
    "classlist.js": "1.1.20150312",
    "core-js": "^3.1.3",
    "cpx": "^1.5.0",
    "document-register-element": "^1.13.2",
    "elements-zone-strategy": "^8.0.0",
    "global": "^4.4.0",
    "husky": "^3.0.0",
    "ngx-markdown": "^8.1.0",
    "npm": "^6.10.1",
    "postcss-preset-env": "^6.7.0",
    "rxjs": "~6.5.2",
    "sass-export": "^1.0.4",
    "scss-bundle": "^2.5.1",
    "stylelint": "^10.0.1",
    "stylelint-config-recommended-scss": "^3.3.0",
    "stylelint-scss": "^3.9.1",
    "svg-sprite": "^1.5.0",
    "svgo": "^1.3.0",
    "take-until-destroy": "^2.1.0",
    "web-animations-js": "^2.3.2",
    "zone.js": "^0.9.1"
  },
  "devDependencies": {
    "@angular-builders/custom-webpack": "^8.1.0",
    "@angular-builders/dev-server": "^7.3.1",
    "@angular-builders/jest": "^8.0.4",
    "@angular-devkit/build-angular": "^0.801.1",
    "@angular-devkit/build-ng-packagr": "~0.801.1",
    "@angular/cli": "8.1.1",
    "@angular/compiler-cli": "^8.1.1",
    "@angular/language-service": "^8.1.1",
    "@babel/core": "^7.5.4",
    "@babel/plugin-proposal-decorators": "^7.4.4",
    "@babel/preset-env": "^7.4.5",
    "@invisionapp/dsm-storybook": "0.0.94",
    "@ngrx/schematics": "8.1.0",
    "@ngrx/store-devtools": "8.1.0",
    "@nrwl/builders": "^8.0.0",
    "@nrwl/cypress": "8.2.0",
    "@nrwl/jest": "8.2.0",
    "@nrwl/schematics": "^8.4.2",
    "@percy/storybook": "^3.1.0",
    "@storybook/addon-a11y": "^5.1.9",
    "@storybook/addon-actions": "^5.1.9",
    "@storybook/addon-backgrounds": "^5.1.9",
    "@storybook/addon-centered": "^5.1.9",
    "@storybook/addon-cssresources": "^5.1.9",
    "@storybook/addon-events": "^5.1.9",
    "@storybook/addon-jest": "^5.1.9",
    "@storybook/addon-knobs": "^5.1.9",
    "@storybook/addon-links": "^5.1.9",
    "@storybook/addon-notes": "^5.1.9",
    "@storybook/addon-options": "^5.1.11",
    "@storybook/addon-storyshots": "^5.1.9",
    "@storybook/addon-storyshots-puppeteer": "^5.1.9",
    "@storybook/addon-storysource": "^5.1.11",
    "@storybook/addon-viewport": "^5.1.9",
    "@storybook/addons": "^5.1.11",
    "@storybook/angular": "^5.1.9",
    "@types/jest": "^24.0.13",
    "@types/jest-environment-puppeteer": "^4.0.0",
    "@types/jest-image-snapshot": "^2.8.0",
    "@types/jquery": "3.3.30",
    "@types/node": "^12.6.5",
    "@types/storybook__addon-actions": "^3.4.3",
    "babel-jest": "^24.8.0",
    "babel-loader": "^8.0.6",
    "babel-plugin-require-context-hook": "^1.0.0",
    "base64-inline-loader": "^1.1.1",
    "clean-webpack-plugin": "^3.0.0",
    "codelyzer": "~5.1.0",
    "cross-env": "^5.2.0",
    "css-loader": "^1.0.1",
    "cssnano": "^4.1.10",
    "cssnano-preset-advanced": "^4.0.7",
    "cz-conventional-changelog": "^2.1.0",
    "debug": "^4.1.1",
    "dotenv": "^8.0.0",
    "html-webpack-plugin": "^3.2.0",
    "jasmine-marbles": "0.6.0",
    "jest": "^24.9.0",
    "jest-image-snapshot": "^2.9.0",
    "jest-preset-angular": "7.1.1",
    "jest-puppeteer": "^4.3.0",
    "mini-css-extract-plugin": "^0.8.0",
    "ng-packagr": "^5.2.0",
    "ngrx-store-freeze": "0.2.4",
    "ngx-schematics-for-storybook": "^0.2.2",
    "node-sass": "^4.12.0",
    "node-sass-utils": "^1.1.2",
    "optimize-css-assets-webpack-plugin": "^5.0.3",
    "postcss-loader": "^3.0.0",
    "prettier": "1.18.2",
    "protractor": "~5.4.2",
    "puppeteer": "^1.19.0",
    "sass-loader": "^7.1.0",
    "sassdoc": "^2.7.0",
    "script-ext-html-webpack-plugin": "^2.1.4",
    "scss-comment-parser": "^0.8.4",
    "start-server-and-test": "^1.9.1",
    "style-loader": "^0.23.1",
    "stylelint-config-recommended": "^2.2.0",
    "stylelint-order": "^3.0.1",
    "ts-jest": "^24.0.2",
    "ts-node": "~8.3.0",
    "tsconfig-paths-webpack-plugin": "^3.2.0",
    "tsickle": "0.36.0",
    "tslib": "^1.10.0",
    "tslint": "~5.18.0",
    "typescript": "^3.4.5",
    "url-loader": "^2.0.1",
    "webpack-bundle-analyzer": "^3.3.2",
    "webpack-cli": "^3.3.6"
  }
}

Code editor or IDE name and version

Visual Studio Code v1.37.0

OS name and version

Windows 10

smcenlly commented 5 years ago

It looks like you have conflicting jest versions in some of your packages.

Have deleted and reinstalled node modules.

Did you delete package-lock.json first? If not, could you please delete and try to install again?

Did you also do the same on your laptop (i.e. delete package-lock.json and reinstall node modules)?

If you're still experiencing the problem, can you please send us package-lock.json from both machines?


Another thing to try is our new automatic configuration for Jest v24+. For Jest v24+, if your tests work through the command line, you should be able to run Wallaby without any configuration. You can read more about how to do this in our docs.

adover commented 5 years ago

Hey @smcenlly , I just deleted and reinstalled node modules and package-lock but with no success. I also tried the auto config but got the error Looks like none of the paths specified in your files/tests list exist in ...

I don't have my laptop to hand but here is the package lock from my work machine package-lock.json.txt

ArtemGovorov commented 5 years ago

I have put together this sample repo with your configs: https://github.com/ArtemGovorov/wallaby-2187, it seems to work (both config and auto config).

Also, on your work machine Jest may be trying to resolve dependencies from some other folders, try checking the following folders and remove any found node_modules subfolder in them:

- `c:\Users\USERNAME\.vscode\extensions\`
- `c:\Users\USERNAME\.vscode\`
- `c:\Users\USERNAME\`
- `c:\Users\`
- `c:\`
adover commented 5 years ago

Hey @ArtemGovorov , that seems to work on my local machine so it must mean it's project based. I'll clear out my jest.config files and see if that yields any results

smcenlly commented 5 years ago

You may also like to try cloning your project to a fresh directory on the same machine and seeing if that fixes your problem.

adover commented 5 years ago

Hey guys, Tried all of the above but still no luck. Still getting the following

TypeError: Cannot read property '_jasmineAdapter' of undefined 
    at Runtime._execModule (.\node_modules\jest-runtime\build\index.js:867:68) 
    at Runtime._loadModule (.\node_modules\jest-runtime\build\index.js:577:12) 
    at Runtime.requireModule (.\node_modules\jest-runtime\build\index.js:433:10) 
    at config.setupFilesAfterEnv.forEach.path (.\node_modules\jest-jasmine2\build\index.js:187:55) 
    at Array.forEach (<anonymous>) 
    at .\node_modules\jest-jasmine2\build\index.js:187:31 
    at Generator.next (<anonymous>) 
    at asyncGeneratorStep (.\node_modules\jest-jasmine2\build\index.js:27:24) 
    at _next (.\node_modules\jest-jasmine2\build\index.js:47:9) 
    at .\node_modules\jest-jasmine2\build\index.js:52:7 
    at new Promise (<anonymous>) 
    at .\node_modules\jest-jasmine2\build\index.js:44:12 
    at _jasmine (.\node_modules\jest-jasmine2\build\index.js:207:19) 
    at jasmine2 (.\node_modules\jest-jasmine2\build\index.js:60:19) 
    at .\node_modules\jest-runner\build\runTest.js:385:24 
    at Generator.next (<anonymous>) 
    at asyncGeneratorStep (.\node_modules\jest-runner\build\runTest.js:161:24) 
    at _next (.\node_modules\jest-runner\build\runTest.js:181:9) 
    at process._tickCallback (internal/process/next_tick.js:68:7) 

This is with a fresh clone and install

adover commented 5 years ago

I think I found the issue! I removed the "allowJS" flag from my tsconfigs and it came to life! Thanks for the help @ArtemGovorov and @smcenlly

Hopefully this will be of use to other people too :)

smcenlly commented 5 years ago

Great to hear that you solved your problem.

rryter commented 5 years ago

I was running into the same problem (without having allowJS set at all) when using vs-code and auto-configuration without a wallaby.js file.

For me the solution was to create the wallaby.js file with the following contents:

module.exports = () => ({
    autoDetect: true
});
ArtemGovorov commented 5 years ago

@rryter This is interesting. Were you trying to run Wallaby auto-config without a wallaby.js from the same folder where you now have the module.exports = () => ({ autoDetect: true }); config? I'm asking because they should work identically (unless the folder was different).

rryter commented 5 years ago

It seems it just was a caching problem, I can not reproduce it anymore. Also Wallby.js Core was updated to Core v1.0.744 just before I had the chance to retry this. It now also works without the config file. 👍