aurelia / testing

Simplifies the testing of UI components by providing an elegant, fluent interface for arranging test setups along with a number of runtime debug/test helpers.
MIT License
40 stars 27 forks source link

TypeError: m.configure is not a function #80

Closed dkent600 closed 6 years ago

dkent600 commented 6 years ago

I'm submitting a bug report

Please tell us about your environment: Windows 10

Current behavior: When I run the test given here: http://aurelia.io/docs/testing/components#testing-a-custom-element I get the following error:

console.error null:null TypeError: m.configure is not a function at [...]\node_modules\aurelia-framework\dist\commonjs\aurelia-framework.js:288:34 at \<anonymous> at process._tickCallback (internal/process/next_tick.js:160:7) console.log test\unit\example.spec.ts:18 TypeError: m.configure is not a function

Note this is being thrown inside the done function (line 18).

Some possibly-relevant package versions:

"aurelia-loader-nodejs": "^1.0.1",
"aurelia-pal-nodejs": "^1.0.0-beta.3.0.0",
"aurelia-protractor-plugin": "1.0.3",
"aurelia-testing": "^1.0.0-beta.4.0.0",
"aurelia-webpack-plugin": "2.0.0-rc.2",
"babel-jest": "^22.1.0",
"babel-plugin-syntax-async-functions": "^6.13.0",
"istanbul-instrumenter-loader": "2.0.0",
"jasmine-core": "2.6.4",
"jest-cli": "^22.1.4",
"jest-css-modules": "^1.1.0",
"karma": "1.7.0",
"karma-chrome-launcher": "2.2.0",
"karma-coverage-istanbul-reporter": "1.3.0",
"karma-jasmine": "1.1.0",
"karma-mocha-reporter": "2.2.3",
"karma-webpack": "2.0.4",
"protractor": "5.1.2",
"ts-jest": "^22.0.3",
"ts-node": "^4.1.0",

jest-pretest.ts:

import 'aurelia-polyfills';
import { Options } from 'aurelia-loader-nodejs';
import { globalize } from 'aurelia-pal-nodejs';
import * as path from 'path';
Options.relativeToDir = path.join(__dirname, 'unit');
globalize();

Jest configuration:

  "jest": {
    "moduleFileExtensions": [
      "js",
      "json",
      "ts"
    ],
    "transform": {
      "^.+\\.(js|jsx)$": "babel-jest",
      "^.+\\.tsx?$": "ts-jest",
      "^.+\\.scss": "jest-css-modules"
    },
    "transformIgnorePatterns": [
      "/dist/",
      "/node_modules/"
    ],
    "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
    "setupFiles": [
      "<rootDir>/test/jest-pretest.ts"
    ],
    "moduleNameMapper": {
      "aurelia-(.*)": "<rootDir>/node_modules/aurelia-$1"
    }

The test command: "jest --no-cache"

Alexander-Taran commented 6 years ago

Can you provide your test file?

dkent600 commented 6 years ago

@Alexander-Taran What test file? Do you mean this, that I referred-to in the original comment?

http://aurelia.io/docs/testing/components#testing-a-custom-element

Alexander-Taran commented 6 years ago

In my jest config there is a setting "testEnvironment": "node", And it came from what Aurelia CLI does.. It may well be that not having it confuses aurelia under testing and there is wrong loader selected and everything goes sideways.. (-:

Here is what CLI produced for me:

    "modulePaths": [
      "<rootDir>/src",
      "<rootDir>/node_modules"
    ],
    "moduleFileExtensions": [
      "js",
      "json",
      "ts"
    ],
    "transform": {
      "^.+\\.(ts|tsx)$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
    },
    "testRegex": "\\.spec\\.(ts|js)x?$",
    "setupFiles": [
      "<rootDir>/test/jest-pretest.ts"
    ],
    "testEnvironment": "node",
    "moduleNameMapper": {
      "aurelia-(.*)": "<rootDir>/node_modules/$1"
    },
    "collectCoverage": true,
    "collectCoverageFrom": [
      "src/**/*.{js,ts}",
      "!**/*.spec.{js,ts}",
      "!**/node_modules/**",
      "!**/test/**"
    ],
    "coverageDirectory": "<rootDir>/test/coverage-jest",
    "coverageReporters": [
      "json",
      "lcov",
      "text",
      "html"
    ],
    "mapCoverage": true
  },
  "engines": {
    "node": ">= 6.0.0"
  },
  "scripts": {
    "start": "nps",
    "test": "nps test"
  },

Yeah. I just tried to remove it from my config and it blew up.. not the same error, but it is important..

dkent600 commented 6 years ago

Please refer to the issue I created on aurelia-framework: https://github.com/aurelia/framework/issues/869

dkent600 commented 6 years ago

@Alexander-Taran adding "testEnvironment": "node" makes no difference for me (I think it was always in there).

Alexander-Taran commented 6 years ago

the culprit is

 "moduleNameMapper": {
      "aurelia-(.*)": "<rootDir>/node_modules/$1"
    },

see https://github.com/aurelia/framework/issues/869 for discoveries with the repro zip attached.

I propose to close this one in favor of https://github.com/aurelia/cli/issues/834