Jest测试错误 - 找不到模块&期望'来自' jest_expect.js'

时间:2018-03-13 12:30:26

标签: javascript testing webpack jestjs webpack-dev-server

我按照Jest configuration按照指南为Webpack构建了React应用程序&我已经解决了以前的一些错误。但是,以下错误令人困惑。错误:

Cannot find module 'expect' from 'jest_expect.js'      
      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:194:17)

这是我的package.json

   "devDependencies / dependencies" :
    "babel-core": "^6.26.0",
    "babel-eslint": "^8.2.1",
    "babel-jest": "^22.2.2",
    "babel-loader": "^7.1.2",
    "babel-polyfill": "^6.26.0",
    "babel-preset-env": "^1.6.1",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "babel-preset-stage-0": "^6.24.1",
    "jest": "^22.3.0",
    "webpack": "^3.11.0",
    "webpack-dev-server": "^2.11.1"
    ...
    "identity-obj-proxy": "^3.0.0",
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "react-redux": "^5.0.6",
    "redux": "^3.7.2",
    "redux-form": "^7.3.0",
    "redux-thunk": "^2.2.0",
    "webpack-merge": "^4.1.1"
     },
  "jest": {
    "verbose": true,
    "moduleDirectories": ["mode_modules"],
    "moduleFileExtensions": ["js", "jsx"],
    "moduleNameMapper": {
      "app(.*)$": "<rootDir>/apps$1",
      "appAthenaTrader(.*)$": "<rootDir>/apps/athenaTrader$1",
      "common(.*)$": "<rootDir>/src/modules/Common$1",
      "modules(.*)$": "<rootDir>/src/modules$1",
      "src(.*)$": "<rootDir>/src$1"
    },
    "modulePaths": ["src", "apps"]
  }

我的webpack.config.js:

const PATHS = {
  app: path.join(__dirname, 'apps'),
  src: path.join(__dirname, 'src'),
  modules: path.join(__dirname, 'src/modules'),
  common: path.join(__dirname, 'src/modules/Common'),
  styles: path.join(__dirname, 'src/styles')
};

const common = {
  output: {
    path: PATHS.build,
    publicPath: '/',
    filename: 'bundle.js'
  },
  resolve: {
    alias: {
      app: PATHS.app,
      Common: PATHS.common,
      modules: PATHS.modules,
      src: PATHS.src,
      styles: PATHS.styles
    },
    extensions: ['.js', '.jsx', '.json']
  },
  module: {
    rules: [
      {
        test: /\.jsx?$/,
        include: [PATHS.app, PATHS.src],
        use: [
          {
            loader: 'babel-loader',
            options: {
              cacheDirectory: true
            }
          }
        ]
      },
...

我写的测试是:

import { Map as iMap } from 'immutable';
import * as actions from '../actionTypes';
import * as actionTypes from '../actions';

describe('Testing of User actions...', () => {
  it('should create an action for sendingUserAuthRequest', () => {
    const action = {
      type: actionTypes.SEND_AUTH_REQUEST,
      payload: iMap({
        isFetching: true,
        isAuthenticated: false
      })
    };
    expect(actions.sendUserAuthRequest()).toEqual(action);
  });
});

我读过的一些解决方案&amp;试过包括this link to regex moduleNameMapper

重申一下,每当我运行测试时,我都会得到

Cannot find module 'expect' from 'jest_expect.js'

1 个答案:

答案 0 :(得分:2)

最有可能的是&#34; m&#34;在&#34;模式&#34;错字应该是&#34; node&#34;:

import tensorflow as tf

self.label_lines_numbers = [lines.rstrip() for line in \
    tf.gfile.GFile('numbers_logs/trained_labels.txt')]

self.label_lines_letters = [lines.rstrip() for line in \
    tf.gfile.GFile('letters_logs/trained_labels.txt')]

with tf.gfile.FastGFile('numbers_logs/trained_graph.pb', 'rb') as f:
    graph_def = tf.GraphDef()
    graph_def.ParseFromString(f.read())
    graph = tf.import_graph_def(graph_def, name='')

sess_numbers = tf.Session(graph)
tf.reset_default_graph()

with tf.gfile.FastGFile('letters_logs/trained_graph.pb', 'rb') as f:
    graph_def = tf.GraphDef()
    graph_def.ParseFromString(f.read())
    graph = tf.import_graph_def(graph_def, name='')

sess_letters = tf.Session(graph)

softmax_tensor_numbers = sess_numbers.graph.get_tensor_by_name('final_result:0')

softmax_tensor_letters = sess_letters.graph.get_tensor_by_name('final_result:0')

# Proceed with classification