babel-jest: this.setDynami c не является функцией (переход на Jest 25) - PullRequest
0 голосов
/ 20 апреля 2020

После обновления с Jest 23 до Jest 24 или 25 я получаю следующую ошибку при попытке запустить тесты:

TypeError: /Users/mikhailsamoylov/workspace/omnitec/florder-stats/src/server/jest.globalSetup.js: this.setDynamic is not a function
    at PluginPass.pre (/Users/mikhailsamoylov/workspace/omnitec/florder-stats/node_modules/babel-plugin-transform-runtime/lib/index.js:31:12)
    at transformFile (/Users/mikhailsamoylov/workspace/omnitec/florder-stats/node_modules/@babel/core/lib/transformation/index.js:96:27)
    at transformFile.next (<anonymous>)
    at run (/Users/mikhailsamoylov/workspace/omnitec/florder-stats/node_modules/@babel/core/lib/transformation/index.js:35:12)
    at run.next (<anonymous>)
    at transform (/Users/mikhailsamoylov/workspace/omnitec/florder-stats/node_modules/@babel/core/lib/transform.js:27:41)
    at transform.next (<anonymous>)
    at evaluateSync (/Users/mikhailsamoylov/workspace/omnitec/florder-stats/node_modules/gensync/index.js:244:28)
    at sync (/Users/mikhailsamoylov/workspace/omnitec/florder-stats/node_modules/gensync/index.js:84:14)
    at Object.process (/Users/mikhailsamoylov/workspace/omnitec/florder-stats/node_modules/jest-config/node_modules/babel-jest/build/index.js:249:57)

Я не думаю, что это связано с содержимым моего jest.globalSetup.js, поскольку он только подготавливает базу данных и фактически не нуждается в каких-либо преобразованиях babel:

require('dotenv').config()
const mongoose = require('mongoose')

module.exports = async () => {
  await mongoose.connect(process.env.DB_TEST)
  await mongoose.connection.db.dropDatabase()
  await mongoose.connection.db.admin().command( { setParameter: 1, maxTransactionLockRequestTimeoutMillis: 500 })
  await mongoose.disconnect()
}

Итак, я думаю, что проблема, как обычно, связана с Babel и его версиями плагинов. Единственная проблема в том, что я понятия не имею, что именно мне нужно обновить. Это то, что я сейчас установил в отношении babel:

$ yarn list --depth=0 | grep babel
├─ @babel/code-frame@7.5.5
├─ @babel/core@7.9.0
├─ @babel/generator@7.9.5
├─ @babel/helper-annotate-as-pure@7.0.0
├─ @babel/helper-function-name@7.9.5
├─ @babel/helper-get-function-arity@7.8.3
├─ @babel/helper-member-expression-to-functions@7.8.3
├─ @babel/helper-module-imports@7.0.0
├─ @babel/helper-module-transforms@7.9.0
├─ @babel/helper-optimise-call-expression@7.8.3
├─ @babel/helper-plugin-utils@7.8.3
├─ @babel/helper-replace-supers@7.8.6
├─ @babel/helper-simple-access@7.8.3
├─ @babel/helper-split-export-declaration@7.8.3
├─ @babel/helper-validator-identifier@7.9.5
├─ @babel/helpers@7.9.2
├─ @babel/highlight@7.9.0
├─ @babel/parser@7.9.4
├─ @babel/plugin-syntax-async-generators@7.8.4
├─ @babel/plugin-syntax-bigint@7.8.3
├─ @babel/plugin-syntax-class-properties@7.8.3
├─ @babel/plugin-syntax-json-strings@7.8.3
├─ @babel/plugin-syntax-logical-assignment-operators@7.8.3
├─ @babel/plugin-syntax-nullish-coalescing-operator@7.8.3
├─ @babel/plugin-syntax-numeric-separator@7.8.3
├─ @babel/plugin-syntax-object-rest-spread@7.8.3
├─ @babel/plugin-syntax-optional-catch-binding@7.8.3
├─ @babel/plugin-syntax-optional-chaining@7.8.3
├─ @babel/runtime@7.1.2
├─ @babel/template@7.8.6
├─ @babel/traverse@7.9.5
├─ @babel/types@7.9.5
├─ @emotion/babel-utils@0.6.10
├─ @types/babel__core@7.1.7
├─ @types/babel__generator@7.6.1
├─ @types/babel__template@7.0.2
├─ @types/babel__traverse@7.0.10
├─ babel-code-frame@6.26.0
├─ babel-core@6.26.3
├─ babel-generator@6.26.1
├─ babel-helper-builder-binary-assignment-operator-visitor@6.24.1
├─ babel-helper-builder-react-jsx@6.26.0
├─ babel-helper-call-delegate@6.24.1
├─ babel-helper-define-map@6.26.0
├─ babel-helper-explode-assignable-expression@6.24.1
├─ babel-helper-function-name@6.24.1
├─ babel-helper-get-function-arity@6.24.1
├─ babel-helper-hoist-variables@6.24.1
├─ babel-helper-optimise-call-expression@6.24.1
├─ babel-helper-regex@6.26.0
├─ babel-helper-remap-async-to-generator@6.24.1
├─ babel-helper-replace-supers@6.24.1
├─ babel-helpers@6.24.1
├─ babel-jest@23.4.2
├─ babel-messages@6.23.0
├─ babel-plugin-check-es2015-constants@6.22.0
├─ babel-plugin-emotion@9.2.11
├─ babel-plugin-istanbul@6.0.0
├─ babel-plugin-jest-hoist@23.2.0
├─ babel-plugin-macros@2.4.2
├─ babel-plugin-styled-components@1.10.0
├─ babel-plugin-syntax-async-functions@6.13.0
├─ babel-plugin-syntax-class-properties@6.13.0
├─ babel-plugin-syntax-exponentiation-operator@6.13.0
├─ babel-plugin-syntax-flow@6.18.0
├─ babel-plugin-syntax-jsx@6.18.0
├─ babel-plugin-syntax-object-rest-spread@6.13.0
├─ babel-plugin-syntax-trailing-function-commas@6.22.0
├─ babel-plugin-transform-async-to-generator@6.24.1
├─ babel-plugin-transform-builtin-classes@0.6.1
├─ babel-plugin-transform-class-properties@6.24.1
├─ babel-plugin-transform-es2015-arrow-functions@6.22.0
├─ babel-plugin-transform-es2015-block-scoped-functions@6.22.0
├─ babel-plugin-transform-es2015-block-scoping@6.26.0
├─ babel-plugin-transform-es2015-classes@6.24.1
├─ babel-plugin-transform-es2015-computed-properties@6.24.1
├─ babel-plugin-transform-es2015-destructuring@6.23.0
├─ babel-plugin-transform-es2015-duplicate-keys@6.24.1
├─ babel-plugin-transform-es2015-for-of@6.23.0
├─ babel-plugin-transform-es2015-function-name@6.24.1
├─ babel-plugin-transform-es2015-literals@6.22.0
├─ babel-plugin-transform-es2015-modules-amd@6.24.1
├─ babel-plugin-transform-es2015-modules-commonjs@6.26.2
├─ babel-plugin-transform-es2015-modules-systemjs@6.24.1
├─ babel-plugin-transform-es2015-modules-umd@6.24.1
├─ babel-plugin-transform-es2015-object-super@6.24.1
├─ babel-plugin-transform-es2015-parameters@6.24.1
├─ babel-plugin-transform-es2015-shorthand-properties@6.24.1
├─ babel-plugin-transform-es2015-spread@6.22.0
├─ babel-plugin-transform-es2015-sticky-regex@6.24.1
├─ babel-plugin-transform-es2015-template-literals@6.22.0
├─ babel-plugin-transform-es2015-typeof-symbol@6.23.0
├─ babel-plugin-transform-es2015-unicode-regex@6.24.1
├─ babel-plugin-transform-exponentiation-operator@6.24.1
├─ babel-plugin-transform-flow-strip-types@6.22.0
├─ babel-plugin-transform-object-rest-spread@6.26.0
├─ babel-plugin-transform-react-display-name@6.25.0
├─ babel-plugin-transform-react-jsx-self@6.22.0
├─ babel-plugin-transform-react-jsx-source@6.22.0
├─ babel-plugin-transform-react-jsx@6.24.1
├─ babel-plugin-transform-regenerator@6.26.0
├─ babel-plugin-transform-runtime@6.23.0
├─ babel-plugin-transform-strict-mode@6.24.1
├─ babel-preset-current-node-syntax@0.1.2
├─ babel-preset-env@1.7.0
├─ babel-preset-flow@6.23.0
├─ babel-preset-jest@23.2.0
├─ babel-preset-react@6.24.1
├─ babel-register@6.26.0
├─ babel-runtime@6.26.0
├─ babel-template@6.26.0
├─ babel-traverse@6.26.0
├─ babel-types@6.26.0

А вот мои package.json:

{
  "name": "...",
  "version": ...",
  "main": "index.js",
  "license": "commercial",
  "private": true,
  "scripts": { ... },
  "jest": {
    "testEnvironment": "node",
    "setupFiles": [
      "./src/server/jest.setup.js"
    ],
    "globalSetup": "./src/server/jest.globalSetup.js",
    "setupFilesAfterEnv": [
      "jest-expect-message",
      "./src/server/jest.envSetup.js"
    ]
  },
  "dependencies": {
    "@material-ui/core": "^3.0.1",
    "@material-ui/icons": "^3.0.1",
    "body-parser": "^1.18.3",
    "chalk": "^2.4.1",
    "cli-progress": "^2.1.1",
    "compression": "^1.7.3",
    "cookie-parser": "^1.4.3",
    "cors": "^2.8.4",
    "cross-env": "^5.2.0",
    "dotenv": "^6.0.0",
    "express": "^4.16.3",
    "express-jwt": "^5.3.1",
    "express-oas-generator": "^1.0.18",
    "fast-csv": "^2.4.1",
    "immutability-helper": "^2.7.1",
    "items-promise": "^1.0.0",
    "jsonwebtoken": "^8.4.0",
    "lodash": "^4.17.10",
    "material-ui-chip-input": "1.0.0-beta.8",
    "material-ui-popup-state": "^1.0.1",
    "metric": "^0.0.1",
    "migrate-mongo": "^5.0.1",
    "moment": "^2.22.2",
    "mongoose": "5.6.12",
    "mongoose-unique-validator": "^2.0.3",
    "nats": "^1.0.1",
    "node-cron": "^2.0.1",
    "node-nats-streaming": "^0.2.6",
    "nodemailer": "^4.6.8",
    "prop-types": "^15.7.2",
    "react": "16.8.4",
    "react-dom": "16.8.4",
    "react-router-dom": "^4.3.1",
    "react-select": "2.1.0",
    "sanitize-filename": "^1.6.1",
    "styled-components": "^4.1.3",
    "url-search-params-polyfill": "^5.0.0",
    "winston": "^3.2.1",
    "yn": "^2.0.0"
  },
  "devDependencies": {
    "@yojeek/mock-node-nats": "https://github.com/yojeek/mock-node-nats.git",
    "babel-core": "6.26.3",
    "babel-jest": "23.4.2",
    "babel-plugin-transform-builtin-classes": "^0.6.1",
    "babel-plugin-transform-class-properties": "6.24.1",
    "babel-plugin-transform-object-rest-spread": "6.26.0",
    "babel-plugin-transform-runtime": "6.23.0",
    "babel-preset-env": "1.7.0",
    "babel-preset-react": "6.24.1",
    "babel-register": "6.26.0",
    "jest": "^25.4.0",
    "jest-expect-message": "^1.0.2",
    "mockdate": "^2.0.2",
    "node-mocks-http": "^1.7.0",
    "nodemon": "^2.0.1",
    "parcel-bundler": "1.9.7",
    "react-hot-loader": "4.6.0",
    "react-jss": "^8.6.1",
    "standard": "^14.3.1"
  }
}

Я не смог найти никаких специфических c руководств по миграции, так что никакой помощи оценили.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...