我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)
我应该添加另一个规则或插件来解决这个问题吗?
我第一次尝试运行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) 我试图添加一个快餐栏,以便在用户登录或不登录时显示一条消息。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) 我正在尝试将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
我发现了类似的问题,例如:
但它并没有解决我的问题.如何用apk添加postgis扩展到我的postgres容器?
我正在尝试将域文件导出到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) 我正在测试一个包含 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) 我开始创建我的应用程序,所以我使用 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) 我使用的是 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) 我是 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) 我使用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如何检查过期时间?或者它不检查它?