小编Sli*_*lim的帖子

安装 jest 时未定义 describe

jest v24.7.1在我的项目中安装了:

npm install jest -D
Run Code Online (Sandbox Code Playgroud)

然后我开始编写一些测试文件,但是我收到了这些 eslint 错误:

'describe' is not defined. eslint (no-undef)
'it' is not defined. eslint (no-undef)
'expect' is not defined. eslint (no-undef)
Run Code Online (Sandbox Code Playgroud)

eslintrc.js:

module.exports = {


env: {
    browser: true,
    es6: true
  },
  extends: ["airbnb", "prettier", "prettier/react"],
  globals: {
    Atomics: "readonly",
    SharedArrayBuffer: "readonly"
  },
  parserOptions: {
    ecmaFeatures: {
      jsx: true
    },
    ecmaVersion: 2018,
    sourceType: "module"
  },
  plugins: ["react"],
  rules: {}
};
Run Code Online (Sandbox Code Playgroud)

我应该添加另一个规则或插件来解决这个问题吗?

eslint jestjs eslint-config-airbnb eslintrc

47
推荐指数
2
解决办法
2万
查看次数

Webpack 4:找不到Entry模块中的ERROR:错误:无法解析'./src'

我第一次尝试运行webpack-4

webpack ./src/js/app.js ./dist/app.bundle.js
Run Code Online (Sandbox Code Playgroud)

它显示警告/错误:

WARNING in configuration
The 'mode' option has not been set, webpack will fallback to 'production' for this value. Set 'mode' option to 'development' or 'production' to enable defaults for each environment.
You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/concepts/mode/

ERROR in multi ./src/js/app.js ./dist/app.bundle.js
Module not found: Error: Can't resolve './dist/app.bundle.js' in 'D:\wamp64\www\webpack-4'
 @ multi ./src/js/app.js ./dist/app.bundle.js
Run Code Online (Sandbox Code Playgroud)

然后我试着改变模式

webpack --mode development
Run Code Online (Sandbox Code Playgroud)

表明 :

ERROR in Entry module …
Run Code Online (Sandbox Code Playgroud)

npm webpack webpack-4

22
推荐指数
3
解决办法
2万
查看次数

未捕获的不变违规:重新渲染过多。React限制渲染次数以防止无限循环

我试图添加一个快餐栏,以便在用户登录或不登录时显示一条消息。SnackBar.jsx:

import React from "react";
import PropTypes from "prop-types";
import classNames from "classnames";
import CheckCircleIcon from "@material-ui/icons/CheckCircle";
import ErrorIcon from "@material-ui/icons/Error";
import CloseIcon from "@material-ui/icons/Close";
import green from "@material-ui/core/colors/green";
import IconButton from "@material-ui/core/IconButton";
import Snackbar from "@material-ui/core/Snackbar";
import SnackbarContent from "@material-ui/core/SnackbarContent";
import { withStyles } from "@material-ui/core/styles";

const variantIcon = {
  success: CheckCircleIcon,
  error: ErrorIcon
};

const styles1 = theme => ({
  success: {
    backgroundColor: green[600]
  },
  error: {
    backgroundColor: theme.palette.error.dark
  },
  icon: {
    fontSize: 20
  },
  iconVariant: {
    opacity: …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs redux material-ui

17
推荐指数
5
解决办法
2万
查看次数

错误:在dockerfile中使用apk的不可满足的约束

我正在尝试将postgis安装到postgres容器中.Dockerfile:

FROM postgres:9.6.4-alpine

RUN apk update \
    && apk add -u postgresql-9.6-postgis-2.4 postgresql-9.6-postgis-2.4-scripts \
    && rm -rf /var/lib/apt/lists/*

COPY ./scripts/postgis.sh  /docker-entrypoint-initdb.d/postgis.sh
Run Code Online (Sandbox Code Playgroud)

postgis.sh:

#!/bin/sh

for DB in $(psql -t -c  "SELECT datname from pg_database where datname = 'backend'"); do
    echo "Loading PostGIS extensions into $DB"
    "${psql[@]}" --dbname="$DB" <<-'EOSQL'
        CREATE EXTENSION IF NOT EXISTS postgis;
EOSQL
done
Run Code Online (Sandbox Code Playgroud)

我收到了这个错误:

错误:不可满足的约束:postgresql-9.6-postgis-2.4(缺失):所需:world [postgresql-9.6-postgis-2.4] postgresql-9.6-postgis-2.4-scripts(缺失):所需:world [postgresql-9.6 -postgis-2.4-scripts]命令'/ bin/sh -c apk update && apk add -u postgresql-9.6-postgis-2.4 postgresql-9.6-postgis-2.4-scripts && rm -rf/var/lib/apt/lists/*'返回非零代码:2

我发现了类似的问题,例如:

  1. 错误:不可满足的限制:在高山安装包装时
  2. 错误:不可满足的约束 - 关于php:7-fpm-alpine

但它并没有解决我的问题.如何用apk添加postgis扩展到我的postgres容器?

apk docker alpine-linux

14
推荐指数
2
解决办法
2万
查看次数

如何将realm文件导出到keycloak docker容器中?

我正在尝试将域文件导出到keycloak docker容器中,我无法这样做,因为执行此命令时服务器正在运行:

bin/standalone.sh -Dkeycloak.migration.action=export
-Dkeycloak.migration.provider=dir -Dkeycloak.migration.dir=<DIR TO EXPORT TO>
Run Code Online (Sandbox Code Playgroud)

我试图修改docker-entrypoint.sh并删除执行服务器以启动的命令:

#!/bin/bash

if [ $KEYCLOAK_USER ] && [ $KEYCLOAK_PASSWORD ]; then
    keycloak/bin/add-user-keycloak.sh --user $KEYCLOAK_USER --password $KEYCLOAK_PASSWORD
fi

if [ "$DB_VENDOR" == "POSTGRES" ]; then
  databaseToInstall="postgres"
elif [ "$DB_VENDOR" == "MYSQL" ]; then
  databaseToInstall="mysql"
elif [ "$DB_VENDOR" == "H2" ]; then
  databaseToInstall=""
else
    if (printenv | grep '^POSTGRES_' &>/dev/null); then
      databaseToInstall="postgres"
    elif (printenv | grep '^MYSQL_' &>/dev/null); then
      databaseToInstall="mysql"
    fi
fi

if [ "$databaseToInstall" != "" ]; then
    echo "[KEYCLOAK DOCKER IMAGE] …
Run Code Online (Sandbox Code Playgroud)

docker keycloak keycloak-services

9
推荐指数
1
解决办法
3390
查看次数

在使用 testing-library 进行测试时使用 getByRole 时无法获取输入的名称

我正在测试一个包含 Material Ui TextField 组件的组件(我们称之为 MyComponent):

<TextField
              name="code"
              aria-label="code"
              onKeyPress={keyPressHandler(codeRegExp)}
              value={values.code}
              placeholder={codePlaceholder}
              onChange={handleChange}
              InputProps={{
                classes: {
                  input: classes.code,
                },
              }}
              onBlur={handleBlur}
              helperText={
                touchedValues.code && errorValues.code ? errorValues.code : ''
              }
              FormHelperTextProps={{classes: {root: classes.errorMessage}}}
            />
Run Code Online (Sandbox Code Playgroud)

我为此编写了测试:

test('Checking the initial rendering of the component', () => {
    const initialState = {
      refs: {
        choice: '',
        creationDate: '',
      },
    };
    render(<MyComponent />, {initialState});
    expect(screen.getByRole('textbox', {name: /code/i})).toBeInTheDocument();
  });
Run Code Online (Sandbox Code Playgroud)

测试失败,我收到此错误:

 TestingLibraryElementError: Unable to find an accessible element with the role "textbox" and name `/code/i`

    Here …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-testing-library

9
推荐指数
1
解决办法
7351
查看次数

找不到模块:错误:无法解析“/home/user/Desktop/my_app/src”中的“./app”

我开始创建我的应用程序,所以我使用 webpack 实现了项目配置。项目结构为:

node_modules
public
|----bundle.js
|----index.html
src
|----app.jsx
|----index.jsx
|----components
     |-----appBar.jsx
Run Code Online (Sandbox Code Playgroud)

webpack.config.jsx:

const path = require('path');

module.exports = {
    mode: 'development',
    entry: path.resolve(__dirname, 'src/index.jsx'),
    output: {
        path: path.resolve(__dirname, 'public'),
        filename: 'bundle.js'
    },
    module: {
        rules: [
            {
                test: /\.jsx$/,
                exclude: /node_modules/,
                loader: 'babel-loader',
            }
        ]
    },
    devServer: {
        contentBase: path.join(__dirname, 'public'),
        compress: true,
        port: 9000
    }
}
Run Code Online (Sandbox Code Playgroud)

应用程序.jsx:

import ButtonAppBar  from './components/appBar';
import React from 'react';


class App extends React.Component {
    render(){
        return (
            <div>
                <ButtonAppBar />
            </div>
        ) …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs webpack

7
推荐指数
2
解决办法
2万
查看次数

无法更新 WSL 发行版上的包

我使用的是 Docker 桌面 v2.3.0,并在 Windows 10 Professional v1909 上启用了 WSL2。

我安装了 Ubuntu 20.04 发行版,我访问了它,当我运行时apt-get update

Err:1 http://archive.ubuntu.com/ubuntu focal InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Err:2 http://security.ubuntu.com/ubuntu focal-security InRelease
  Temporary failure resolving 'security.ubuntu.com'
Err:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Err:4 http://archive.ubuntu.com/ubuntu focal-backports InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Reading package lists... Done
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal/InRelease  Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal-updates/InRelease  Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal-backports/InRelease  Temporary failure resolving 'archive.ubuntu.com' …
Run Code Online (Sandbox Code Playgroud)

linux ubuntu docker windows-subsystem-for-linux

7
推荐指数
0
解决办法
2278
查看次数

使用 _id 查找不适用于聚合

我是 mongodb 的初学者,我正在尝试在 node.js 应用程序中使用 mongoose 编写查询:

const objectIdValue = secondId.valueOf();


  const existedRelation = await this.model.aggregate([
    { $match: { _id: firstId } },
    { $project: {
      relations: {
        $filter: {
          input: '$links',
          as: 'link',
          cond: {
            $and: [
              { $eq: ['$$link.target.entityId', `${objectIdValue}`] },
              { $eq: ['$$link.linkTypeId', linkTypeId] },
            ],
          },

        },
      },
    },
    },
  ]);
  console.log('existedRelation: ', existedRelation);
Run Code Online (Sandbox Code Playgroud)

当我执行它时,我得到了这个结果:

existedRelation:  []
Run Code Online (Sandbox Code Playgroud)

我尝试使用 mongoShell 执行它:

db.tasks.aggregate([
    { $match:{ _id: ObjectId("5bbf5800be37394f38a9727e") }},
    {
  $project: {
          relations:{
                $filter:{
                  input: '$links',
                  as: "link",
                  cond: …
Run Code Online (Sandbox Code Playgroud)

mongoose mongodb aggregation-framework

6
推荐指数
1
解决办法
2700
查看次数

jwt.verify() 当过期时间为 24h 时返回 jwt 已过期

我使用jwt创建一个令牌:

const jwt = require('jsonwebtoken');
const token = jwt.sign({
filePath: "path/to/file"
}, 'secretKey', {
expiresIn: "24h"
});
try {
  console.log(token)
  var decoded = jwt.verify(token, 'secretKey');
} catch(err) {
 console.log(err)
}
Run Code Online (Sandbox Code Playgroud)

jwt.标头:

{
  "alg": "HS256",
  "typ": "JWT"
}
Run Code Online (Sandbox Code Playgroud)

有效负载:

{
  "filePath": "path",
  "iat": 1557833831,
  "exp": 1557920231
}
Run Code Online (Sandbox Code Playgroud)

当我在真实的应用程序中测试上面提到的代码片段时,我收到一条错误消息:

jwt expired
Run Code Online (Sandbox Code Playgroud)

使用jwt 调试器,令牌有效,并应在 24 小时后过期。verify()检查过期返回的错误。jwt如何检查过期时间?或者它不检查它?

javascript jwt

6
推荐指数
1
解决办法
9405
查看次数